confdb.c 24 KB

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