confdb.c 24 KB

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