confdb.c 26 KB

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