confdb.c 26 KB

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