confdb.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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. api = corosync_api;
  244. return 0;
  245. }
  246. static int confdb_lib_init_fn (void *conn)
  247. {
  248. log_printf(LOGSYS_LEVEL_DEBUG, "lib_init_fn: conn=%p\n", conn);
  249. return (0);
  250. }
  251. static int confdb_lib_exit_fn (void *conn)
  252. {
  253. log_printf(LOGSYS_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn);
  254. /* cleanup the object trackers for this client. */
  255. api->object_track_stop(confdb_notify_lib_of_key_change,
  256. confdb_notify_lib_of_new_object,
  257. confdb_notify_lib_of_destroyed_object,
  258. NULL,
  259. conn);
  260. return (0);
  261. }
  262. static void message_handler_req_lib_confdb_object_create (void *conn,
  263. const void *message)
  264. {
  265. const struct req_lib_confdb_object_create *req_lib_confdb_object_create
  266. = message;
  267. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  268. hdb_handle_t object_handle;
  269. int ret = CS_OK;
  270. if (api->object_create(req_lib_confdb_object_create->parent_object_handle,
  271. &object_handle,
  272. req_lib_confdb_object_create->object_name.value,
  273. req_lib_confdb_object_create->object_name.length))
  274. ret = CS_ERR_ACCESS;
  275. res_lib_confdb_object_create.object_handle = object_handle;
  276. res_lib_confdb_object_create.header.size = sizeof(res_lib_confdb_object_create);
  277. res_lib_confdb_object_create.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  278. res_lib_confdb_object_create.header.error = ret;
  279. api->ipc_response_send(conn, &res_lib_confdb_object_create, sizeof(res_lib_confdb_object_create));
  280. }
  281. static void message_handler_req_lib_confdb_object_destroy (void *conn,
  282. const void *message)
  283. {
  284. const struct req_lib_confdb_object_destroy *req_lib_confdb_object_destroy
  285. = message;
  286. coroipc_response_header_t res;
  287. int ret = CS_OK;
  288. if (api->object_destroy(req_lib_confdb_object_destroy->object_handle))
  289. ret = CS_ERR_ACCESS;
  290. res.size = sizeof(res);
  291. res.id = MESSAGE_RES_CONFDB_OBJECT_DESTROY;
  292. res.error = ret;
  293. api->ipc_response_send(conn, &res, sizeof(res));
  294. }
  295. static void message_handler_req_lib_confdb_object_find_destroy (void *conn,
  296. const void *message)
  297. {
  298. const struct req_lib_confdb_object_find_destroy
  299. *req_lib_confdb_object_find_destroy = message;
  300. coroipc_response_header_t res;
  301. int ret = CS_OK;
  302. if (api->object_find_destroy(req_lib_confdb_object_find_destroy->find_handle))
  303. ret = CS_ERR_ACCESS;
  304. res.size = sizeof(res);
  305. res.id = MESSAGE_RES_CONFDB_OBJECT_FIND_DESTROY;
  306. res.error = ret;
  307. api->ipc_response_send(conn, &res, sizeof(res));
  308. }
  309. static void message_handler_req_lib_confdb_key_create (void *conn,
  310. const void *message)
  311. {
  312. const struct req_lib_confdb_key_create *req_lib_confdb_key_create
  313. = message;
  314. coroipc_response_header_t res;
  315. int ret = CS_OK;
  316. if (api->object_key_create(req_lib_confdb_key_create->object_handle,
  317. req_lib_confdb_key_create->key_name.value,
  318. req_lib_confdb_key_create->key_name.length,
  319. req_lib_confdb_key_create->value.value,
  320. req_lib_confdb_key_create->value.length))
  321. ret = CS_ERR_ACCESS;
  322. res.size = sizeof(res);
  323. res.id = MESSAGE_RES_CONFDB_KEY_CREATE;
  324. res.error = ret;
  325. api->ipc_response_send(conn, &res, sizeof(res));
  326. }
  327. static void message_handler_req_lib_confdb_key_get (void *conn,
  328. const void *message)
  329. {
  330. const struct req_lib_confdb_key_get *req_lib_confdb_key_get = message;
  331. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  332. size_t value_len;
  333. void *value;
  334. int ret = CS_OK;
  335. if (api->object_key_get(req_lib_confdb_key_get->parent_object_handle,
  336. req_lib_confdb_key_get->key_name.value,
  337. req_lib_confdb_key_get->key_name.length,
  338. &value,
  339. &value_len))
  340. ret = CS_ERR_ACCESS;
  341. else {
  342. memcpy(res_lib_confdb_key_get.value.value, value, value_len);
  343. res_lib_confdb_key_get.value.length = value_len;
  344. }
  345. res_lib_confdb_key_get.header.size = sizeof(res_lib_confdb_key_get);
  346. res_lib_confdb_key_get.header.id = MESSAGE_RES_CONFDB_KEY_GET;
  347. res_lib_confdb_key_get.header.error = ret;
  348. api->ipc_response_send(conn, &res_lib_confdb_key_get, sizeof(res_lib_confdb_key_get));
  349. }
  350. static void message_handler_req_lib_confdb_key_increment (void *conn,
  351. const void *message)
  352. {
  353. const struct req_lib_confdb_key_get *req_lib_confdb_key_get = message;
  354. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  355. int ret = CS_OK;
  356. if (api->object_key_increment(req_lib_confdb_key_get->parent_object_handle,
  357. req_lib_confdb_key_get->key_name.value,
  358. req_lib_confdb_key_get->key_name.length,
  359. &res_lib_confdb_key_incdec.value))
  360. ret = CS_ERR_ACCESS;
  361. res_lib_confdb_key_incdec.header.size = sizeof(res_lib_confdb_key_incdec);
  362. res_lib_confdb_key_incdec.header.id = MESSAGE_RES_CONFDB_KEY_INCREMENT;
  363. res_lib_confdb_key_incdec.header.error = ret;
  364. api->ipc_response_send(conn, &res_lib_confdb_key_incdec, sizeof(res_lib_confdb_key_incdec));
  365. }
  366. static void message_handler_req_lib_confdb_key_decrement (void *conn,
  367. const void *message)
  368. {
  369. const struct req_lib_confdb_key_get *req_lib_confdb_key_get = message;
  370. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  371. int ret = CS_OK;
  372. if (api->object_key_decrement(req_lib_confdb_key_get->parent_object_handle,
  373. req_lib_confdb_key_get->key_name.value,
  374. req_lib_confdb_key_get->key_name.length,
  375. &res_lib_confdb_key_incdec.value))
  376. ret = CS_ERR_ACCESS;
  377. res_lib_confdb_key_incdec.header.size = sizeof(res_lib_confdb_key_incdec);
  378. res_lib_confdb_key_incdec.header.id = MESSAGE_RES_CONFDB_KEY_DECREMENT;
  379. res_lib_confdb_key_incdec.header.error = ret;
  380. api->ipc_response_send(conn, &res_lib_confdb_key_incdec, sizeof(res_lib_confdb_key_incdec));
  381. }
  382. static void message_handler_req_lib_confdb_key_replace (void *conn,
  383. const void *message)
  384. {
  385. const struct req_lib_confdb_key_replace *req_lib_confdb_key_replace
  386. = message;
  387. coroipc_response_header_t res;
  388. int ret = CS_OK;
  389. if (api->object_key_replace(req_lib_confdb_key_replace->object_handle,
  390. req_lib_confdb_key_replace->key_name.value,
  391. req_lib_confdb_key_replace->key_name.length,
  392. req_lib_confdb_key_replace->new_value.value,
  393. req_lib_confdb_key_replace->new_value.length))
  394. ret = CS_ERR_ACCESS;
  395. res.size = sizeof(res);
  396. res.id = MESSAGE_RES_CONFDB_KEY_REPLACE;
  397. res.error = ret;
  398. api->ipc_response_send(conn, &res, sizeof(res));
  399. }
  400. static void message_handler_req_lib_confdb_key_delete (void *conn,
  401. const void *message)
  402. {
  403. const struct req_lib_confdb_key_delete *req_lib_confdb_key_delete
  404. = message;
  405. coroipc_response_header_t res;
  406. int ret = CS_OK;
  407. if (api->object_key_delete(req_lib_confdb_key_delete->object_handle,
  408. req_lib_confdb_key_delete->key_name.value,
  409. req_lib_confdb_key_delete->key_name.length))
  410. ret = CS_ERR_ACCESS;
  411. res.size = sizeof(res);
  412. res.id = MESSAGE_RES_CONFDB_KEY_DELETE;
  413. res.error = ret;
  414. api->ipc_response_send(conn, &res, sizeof(res));
  415. }
  416. static void message_handler_req_lib_confdb_object_parent_get (void *conn,
  417. const void *message)
  418. {
  419. const struct req_lib_confdb_object_parent_get
  420. *req_lib_confdb_object_parent_get = message;
  421. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  422. hdb_handle_t object_handle;
  423. int ret = CS_OK;
  424. if (api->object_parent_get(req_lib_confdb_object_parent_get->object_handle,
  425. &object_handle))
  426. ret = CS_ERR_ACCESS;
  427. res_lib_confdb_object_parent_get.parent_object_handle = object_handle;
  428. res_lib_confdb_object_parent_get.header.size = sizeof(res_lib_confdb_object_parent_get);
  429. res_lib_confdb_object_parent_get.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  430. res_lib_confdb_object_parent_get.header.error = ret;
  431. api->ipc_response_send(conn, &res_lib_confdb_object_parent_get, sizeof(res_lib_confdb_object_parent_get));
  432. }
  433. static void message_handler_req_lib_confdb_key_iter (void *conn,
  434. const void *message)
  435. {
  436. const struct req_lib_confdb_key_iter *req_lib_confdb_key_iter = message;
  437. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  438. void *key_name;
  439. size_t key_name_len;
  440. void *value;
  441. size_t value_len;
  442. int ret = CS_OK;
  443. if (api->object_key_iter_from(req_lib_confdb_key_iter->parent_object_handle,
  444. req_lib_confdb_key_iter->next_entry,
  445. &key_name,
  446. &key_name_len,
  447. &value,
  448. &value_len))
  449. ret = CS_ERR_ACCESS;
  450. else {
  451. memcpy(res_lib_confdb_key_iter.key_name.value, key_name, key_name_len);
  452. memcpy(res_lib_confdb_key_iter.value.value, value, value_len);
  453. res_lib_confdb_key_iter.key_name.length = key_name_len;
  454. res_lib_confdb_key_iter.value.length = value_len;
  455. }
  456. res_lib_confdb_key_iter.header.size = sizeof(res_lib_confdb_key_iter);
  457. res_lib_confdb_key_iter.header.id = MESSAGE_RES_CONFDB_KEY_ITER;
  458. res_lib_confdb_key_iter.header.error = ret;
  459. api->ipc_response_send(conn, &res_lib_confdb_key_iter, sizeof(res_lib_confdb_key_iter));
  460. }
  461. static void message_handler_req_lib_confdb_object_iter (void *conn,
  462. const void *message)
  463. {
  464. const struct req_lib_confdb_object_iter *req_lib_confdb_object_iter
  465. = message;
  466. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  467. size_t object_name_len;
  468. int ret = CS_OK;
  469. if (!req_lib_confdb_object_iter->find_handle) {
  470. api->object_find_create(req_lib_confdb_object_iter->parent_object_handle,
  471. NULL, 0,
  472. m2h(&res_lib_confdb_object_iter.find_handle));
  473. }
  474. else
  475. res_lib_confdb_object_iter.find_handle = req_lib_confdb_object_iter->find_handle;
  476. if (api->object_find_next(res_lib_confdb_object_iter.find_handle,
  477. m2h(&res_lib_confdb_object_iter.object_handle))) {
  478. ret = CS_ERR_ACCESS;
  479. api->object_find_destroy(res_lib_confdb_object_iter.find_handle);
  480. }
  481. else {
  482. api->object_name_get(res_lib_confdb_object_iter.object_handle,
  483. (char *)res_lib_confdb_object_iter.object_name.value,
  484. &object_name_len);
  485. res_lib_confdb_object_iter.object_name.length = object_name_len;
  486. }
  487. res_lib_confdb_object_iter.header.size = sizeof(res_lib_confdb_object_iter);
  488. res_lib_confdb_object_iter.header.id = MESSAGE_RES_CONFDB_OBJECT_ITER;
  489. res_lib_confdb_object_iter.header.error = ret;
  490. api->ipc_response_send(conn, &res_lib_confdb_object_iter, sizeof(res_lib_confdb_object_iter));
  491. }
  492. static void message_handler_req_lib_confdb_object_find (void *conn,
  493. const void *message)
  494. {
  495. const struct req_lib_confdb_object_find *req_lib_confdb_object_find
  496. = message;
  497. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  498. int ret = CS_OK;
  499. if (!req_lib_confdb_object_find->find_handle) {
  500. api->object_find_create(req_lib_confdb_object_find->parent_object_handle,
  501. req_lib_confdb_object_find->object_name.value,
  502. req_lib_confdb_object_find->object_name.length,
  503. m2h(&res_lib_confdb_object_find.find_handle));
  504. }
  505. else
  506. res_lib_confdb_object_find.find_handle = req_lib_confdb_object_find->find_handle;
  507. if (api->object_find_next(res_lib_confdb_object_find.find_handle,
  508. m2h(&res_lib_confdb_object_find.object_handle))) {
  509. ret = CS_ERR_ACCESS;
  510. api->object_find_destroy(res_lib_confdb_object_find.find_handle);
  511. }
  512. res_lib_confdb_object_find.header.size = sizeof(res_lib_confdb_object_find);
  513. res_lib_confdb_object_find.header.id = MESSAGE_RES_CONFDB_OBJECT_FIND;
  514. res_lib_confdb_object_find.header.error = ret;
  515. api->ipc_response_send(conn, &res_lib_confdb_object_find, sizeof(res_lib_confdb_object_find));
  516. }
  517. static void message_handler_req_lib_confdb_write (void *conn,
  518. const void *message)
  519. {
  520. struct res_lib_confdb_write res_lib_confdb_write;
  521. int ret = CS_OK;
  522. const char *error_string = NULL;
  523. if (api->object_write_config(&error_string))
  524. ret = CS_ERR_ACCESS;
  525. res_lib_confdb_write.header.size = sizeof(res_lib_confdb_write);
  526. res_lib_confdb_write.header.id = MESSAGE_RES_CONFDB_WRITE;
  527. res_lib_confdb_write.header.error = ret;
  528. if (error_string) {
  529. strcpy((char *)res_lib_confdb_write.error.value, error_string);
  530. res_lib_confdb_write.error.length = strlen(error_string) + 1;
  531. } else
  532. res_lib_confdb_write.error.length = 0;
  533. api->ipc_response_send(conn, &res_lib_confdb_write, sizeof(res_lib_confdb_write));
  534. }
  535. static void message_handler_req_lib_confdb_reload (void *conn,
  536. const void *message)
  537. {
  538. const struct req_lib_confdb_reload *req_lib_confdb_reload = message;
  539. struct res_lib_confdb_reload res_lib_confdb_reload;
  540. int ret = CS_OK;
  541. const char *error_string = NULL;
  542. if (api->object_reload_config(req_lib_confdb_reload->flush, &error_string))
  543. ret = CS_ERR_ACCESS;
  544. res_lib_confdb_reload.header.size = sizeof(res_lib_confdb_reload);
  545. res_lib_confdb_reload.header.id = MESSAGE_RES_CONFDB_RELOAD;
  546. res_lib_confdb_reload.header.error = ret;
  547. if(error_string) {
  548. strcpy((char *)res_lib_confdb_reload.error.value, error_string);
  549. res_lib_confdb_reload.error.length = strlen(error_string) + 1;
  550. } else
  551. res_lib_confdb_reload.error.length = 0;
  552. api->ipc_response_send(conn, &res_lib_confdb_reload, sizeof(res_lib_confdb_reload));
  553. }
  554. static void confdb_notify_lib_of_key_change(object_change_type_t change_type,
  555. hdb_handle_t parent_object_handle,
  556. hdb_handle_t object_handle,
  557. const void *object_name_pt, size_t object_name_len,
  558. const void *key_name_pt, size_t key_name_len,
  559. const void *key_value_pt, size_t key_value_len,
  560. void *priv_data_pt)
  561. {
  562. struct res_lib_confdb_key_change_callback res;
  563. res.header.size = sizeof(res);
  564. res.header.id = MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK;
  565. res.header.error = CS_OK;
  566. // handle & type
  567. res.change_type = change_type;
  568. res.parent_object_handle = parent_object_handle;
  569. res.object_handle = object_handle;
  570. //object
  571. memcpy(res.object_name.value, object_name_pt, object_name_len);
  572. res.object_name.length = object_name_len;
  573. //key name
  574. memcpy(res.key_name.value, key_name_pt, key_name_len);
  575. res.key_name.length = key_name_len;
  576. //key value
  577. memcpy(res.key_value.value, key_value_pt, key_value_len);
  578. res.key_value.length = key_value_len;
  579. api->ipc_dispatch_send(priv_data_pt, &res, sizeof(res));
  580. }
  581. static void confdb_notify_lib_of_new_object(hdb_handle_t parent_object_handle,
  582. hdb_handle_t object_handle,
  583. const uint8_t *name_pt, size_t name_len,
  584. void *priv_data_pt)
  585. {
  586. struct res_lib_confdb_object_create_callback res;
  587. res.header.size = sizeof(res);
  588. res.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK;
  589. res.header.error = CS_OK;
  590. res.parent_object_handle = parent_object_handle;
  591. res.object_handle = object_handle;
  592. memcpy(res.name.value, name_pt, name_len);
  593. res.name.length = name_len;
  594. api->ipc_dispatch_send(priv_data_pt, &res, sizeof(res));
  595. }
  596. static void confdb_notify_lib_of_destroyed_object(
  597. hdb_handle_t parent_object_handle,
  598. const uint8_t *name_pt, size_t name_len,
  599. void *priv_data_pt)
  600. {
  601. struct res_lib_confdb_object_destroy_callback res;
  602. res.header.size = sizeof(res);
  603. res.header.id = MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK;
  604. res.header.error = CS_OK;
  605. res.parent_object_handle = parent_object_handle;
  606. memcpy(res.name.value, name_pt, name_len);
  607. res.name.length = name_len;
  608. api->ipc_dispatch_send(priv_data_pt, &res, sizeof(res));
  609. }
  610. static void message_handler_req_lib_confdb_track_start (void *conn,
  611. const void *message)
  612. {
  613. const struct req_lib_confdb_object_track_start *req = message;
  614. coroipc_response_header_t res;
  615. api->object_track_start(req->object_handle,
  616. req->flags,
  617. confdb_notify_lib_of_key_change,
  618. confdb_notify_lib_of_new_object,
  619. confdb_notify_lib_of_destroyed_object,
  620. NULL,
  621. conn);
  622. res.size = sizeof(res);
  623. res.id = MESSAGE_RES_CONFDB_TRACK_START;
  624. res.error = CS_OK;
  625. api->ipc_response_send(conn, &res, sizeof(res));
  626. }
  627. static void message_handler_req_lib_confdb_track_stop (void *conn,
  628. const void *message)
  629. {
  630. coroipc_response_header_t res;
  631. api->object_track_stop(confdb_notify_lib_of_key_change,
  632. confdb_notify_lib_of_new_object,
  633. confdb_notify_lib_of_destroyed_object,
  634. NULL,
  635. conn);
  636. res.size = sizeof(res);
  637. res.id = MESSAGE_RES_CONFDB_TRACK_STOP;
  638. res.error = CS_OK;
  639. api->ipc_response_send(conn, &res, sizeof(res));
  640. }