confdb.c 26 KB

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