confdb.c 26 KB

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