confdb.c 26 KB

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