confdb.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. /*
  2. * Copyright (c) 2008-2010 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield (ccaulfie@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <config.h>
  35. #include <sys/types.h>
  36. #include <unistd.h>
  37. #include <fcntl.h>
  38. #include <stdlib.h>
  39. #include <errno.h>
  40. #include <unistd.h>
  41. #include <corosync/corotypes.h>
  42. #include <corosync/coroipc_types.h>
  43. #include <corosync/corodefs.h>
  44. #include <corosync/cfg.h>
  45. #include <corosync/list.h>
  46. #include <corosync/mar_gen.h>
  47. #include <corosync/ipc_confdb.h>
  48. #include <corosync/lcr/lcr_comp.h>
  49. #include <corosync/engine/logsys.h>
  50. #include <corosync/engine/coroapi.h>
  51. LOGSYS_DECLARE_SUBSYS ("CONFDB");
  52. static hdb_handle_t *
  53. m2h (mar_uint64_t *m)
  54. {
  55. /* FIXME enable the following when/if we use gnulib:
  56. (it's a compile-time assertion; i.e., zero run-time cost)
  57. verify (sizeof (*m) == sizeof (hdb_handle_t)); */
  58. return (void *) m;
  59. }
  60. static struct corosync_api_v1 *api;
  61. static int confdb_exec_init_fn (
  62. struct corosync_api_v1 *corosync_api);
  63. static int confdb_lib_init_fn (void *conn);
  64. static int confdb_lib_exit_fn (void *conn);
  65. static void message_handler_req_lib_confdb_object_create (void *conn,
  66. const void *message);
  67. static void message_handler_req_lib_confdb_object_destroy (void *conn,
  68. const void *message);
  69. static void message_handler_req_lib_confdb_object_find_destroy (void *conn,
  70. const void *message);
  71. static void message_handler_req_lib_confdb_key_create (void *conn,
  72. const void *message);
  73. static void message_handler_req_lib_confdb_key_create_typed (void *conn,
  74. const void *message);
  75. static void message_handler_req_lib_confdb_key_get (void *conn,
  76. const void *message);
  77. static void message_handler_req_lib_confdb_key_get_typed (void *conn,
  78. const void *message);
  79. static void message_handler_req_lib_confdb_key_replace (void *conn,
  80. const void *message);
  81. static void message_handler_req_lib_confdb_key_delete (void *conn,
  82. const void *message);
  83. static void message_handler_req_lib_confdb_key_iter (void *conn,
  84. const void *message);
  85. static void message_handler_req_lib_confdb_key_iter_typed (void *conn,
  86. const void *message);
  87. static void message_handler_req_lib_confdb_key_increment (void *conn,
  88. const void *message);
  89. static void message_handler_req_lib_confdb_key_decrement (void *conn,
  90. const void *message);
  91. static void message_handler_req_lib_confdb_object_iter (void *conn,
  92. const void *message);
  93. static void message_handler_req_lib_confdb_object_find (void *conn,
  94. const void *message);
  95. static void message_handler_req_lib_confdb_object_parent_get (void *conn,
  96. const void *message);
  97. static void message_handler_req_lib_confdb_write (void *conn,
  98. const void *message);
  99. static void message_handler_req_lib_confdb_reload (void *conn,
  100. const void *message);
  101. static void message_handler_req_lib_confdb_track_start (void *conn,
  102. const void *message);
  103. static void message_handler_req_lib_confdb_track_stop (void *conn,
  104. const void *message);
  105. static void confdb_notify_lib_of_key_change(
  106. object_change_type_t change_type,
  107. hdb_handle_t parent_object_handle,
  108. hdb_handle_t object_handle,
  109. const void *object_name_pt, size_t object_name_len,
  110. const void *key_name_pt, size_t key_name_len,
  111. const void *key_value_pt, size_t key_value_len,
  112. void *priv_data_pt);
  113. static void confdb_notify_lib_of_new_object(
  114. hdb_handle_t parent_object_handle,
  115. hdb_handle_t object_handle,
  116. const uint8_t *name_pt, size_t name_len,
  117. void *priv_data_pt);
  118. static void confdb_notify_lib_of_destroyed_object(
  119. hdb_handle_t parent_object_handle,
  120. const uint8_t *name_pt, size_t name_len,
  121. void *priv_data_pt);
  122. static void confdb_notify_lib_of_reload(
  123. objdb_reload_notify_type_t notify_type,
  124. int flush,
  125. void *priv_data_pt);
  126. /*
  127. * Library Handler Definition
  128. */
  129. static struct corosync_lib_handler confdb_lib_engine[] =
  130. {
  131. { /* 0 */
  132. .lib_handler_fn = message_handler_req_lib_confdb_object_create,
  133. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  134. },
  135. { /* 1 */
  136. .lib_handler_fn = message_handler_req_lib_confdb_object_destroy,
  137. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  138. },
  139. { /* 2 */
  140. .lib_handler_fn = message_handler_req_lib_confdb_object_find,
  141. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  142. },
  143. { /* 3 */
  144. .lib_handler_fn = message_handler_req_lib_confdb_key_create,
  145. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  146. },
  147. { /* 4 */
  148. .lib_handler_fn = message_handler_req_lib_confdb_key_get,
  149. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  150. },
  151. { /* 5 */
  152. .lib_handler_fn = message_handler_req_lib_confdb_key_replace,
  153. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  154. },
  155. { /* 6 */
  156. .lib_handler_fn = message_handler_req_lib_confdb_key_delete,
  157. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  158. },
  159. { /* 7 */
  160. .lib_handler_fn = message_handler_req_lib_confdb_object_iter,
  161. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  162. },
  163. { /* 8 */
  164. .lib_handler_fn = message_handler_req_lib_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. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  170. },
  171. { /* 10 */
  172. .lib_handler_fn = message_handler_req_lib_confdb_track_start,
  173. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  174. },
  175. { /* 11 */
  176. .lib_handler_fn = message_handler_req_lib_confdb_track_stop,
  177. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  178. },
  179. { /* 12 */
  180. .lib_handler_fn = message_handler_req_lib_confdb_write,
  181. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  182. },
  183. { /* 13 */
  184. .lib_handler_fn = message_handler_req_lib_confdb_reload,
  185. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  186. },
  187. { /* 14 */
  188. .lib_handler_fn = message_handler_req_lib_confdb_object_find_destroy,
  189. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  190. },
  191. { /* 15 */
  192. .lib_handler_fn = message_handler_req_lib_confdb_key_increment,
  193. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  194. },
  195. { /* 16 */
  196. .lib_handler_fn = message_handler_req_lib_confdb_key_decrement,
  197. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  198. },
  199. { /* 17 */
  200. .lib_handler_fn = message_handler_req_lib_confdb_key_create_typed,
  201. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  202. },
  203. { /* 18 */
  204. .lib_handler_fn = message_handler_req_lib_confdb_key_get_typed,
  205. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  206. },
  207. { /* 19 */
  208. .lib_handler_fn = message_handler_req_lib_confdb_key_iter_typed,
  209. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  210. },
  211. };
  212. struct corosync_service_engine confdb_service_engine = {
  213. .name = "corosync cluster config database access v1.01",
  214. .id = CONFDB_SERVICE,
  215. .priority = 1,
  216. .private_data_size = 0,
  217. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED,
  218. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  219. .lib_init_fn = confdb_lib_init_fn,
  220. .lib_exit_fn = confdb_lib_exit_fn,
  221. .lib_engine = confdb_lib_engine,
  222. .lib_engine_count = sizeof (confdb_lib_engine) / sizeof (struct corosync_lib_handler),
  223. .exec_init_fn = confdb_exec_init_fn,
  224. };
  225. /*
  226. * Dynamic loader definition
  227. */
  228. static struct corosync_service_engine *confdb_get_service_engine_ver0 (void);
  229. static struct corosync_service_engine_iface_ver0 confdb_service_engine_iface = {
  230. .corosync_get_service_engine_ver0 = confdb_get_service_engine_ver0
  231. };
  232. static struct lcr_iface corosync_confdb_ver0[1] = {
  233. {
  234. .name = "corosync_confdb",
  235. .version = 0,
  236. .versions_replace = 0,
  237. .versions_replace_count = 0,
  238. .dependencies = 0,
  239. .dependency_count = 0,
  240. .constructor = NULL,
  241. .destructor = NULL,
  242. .interfaces = NULL
  243. }
  244. };
  245. static struct lcr_comp confdb_comp_ver0 = {
  246. .iface_count = 1,
  247. .ifaces = corosync_confdb_ver0
  248. };
  249. static struct corosync_service_engine *confdb_get_service_engine_ver0 (void)
  250. {
  251. return (&confdb_service_engine);
  252. }
  253. #ifdef COROSYNC_SOLARIS
  254. void corosync_lcr_component_register (void);
  255. void corosync_lcr_component_register (void) {
  256. #else
  257. __attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
  258. #endif
  259. lcr_interfaces_set (&corosync_confdb_ver0[0], &confdb_service_engine_iface);
  260. lcr_component_register (&confdb_comp_ver0);
  261. }
  262. static int confdb_exec_init_fn (
  263. struct corosync_api_v1 *corosync_api)
  264. {
  265. #ifdef COROSYNC_SOLARIS
  266. logsys_subsys_init();
  267. #endif
  268. api = corosync_api;
  269. return 0;
  270. }
  271. static int confdb_lib_init_fn (void *conn)
  272. {
  273. log_printf(LOGSYS_LEVEL_DEBUG, "lib_init_fn: conn=%p\n", conn);
  274. return (0);
  275. }
  276. static int confdb_lib_exit_fn (void *conn)
  277. {
  278. log_printf(LOGSYS_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn);
  279. /* cleanup the object trackers for this client. */
  280. api->object_track_stop(confdb_notify_lib_of_key_change,
  281. confdb_notify_lib_of_new_object,
  282. confdb_notify_lib_of_destroyed_object,
  283. NULL,
  284. conn);
  285. return (0);
  286. }
  287. static void message_handler_req_lib_confdb_object_create (void *conn,
  288. const void *message)
  289. {
  290. const struct req_lib_confdb_object_create *req_lib_confdb_object_create
  291. = message;
  292. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  293. hdb_handle_t object_handle;
  294. int ret = CS_OK;
  295. if (api->object_create(req_lib_confdb_object_create->parent_object_handle,
  296. &object_handle,
  297. req_lib_confdb_object_create->object_name.value,
  298. req_lib_confdb_object_create->object_name.length))
  299. ret = CS_ERR_ACCESS;
  300. res_lib_confdb_object_create.object_handle = object_handle;
  301. res_lib_confdb_object_create.header.size = sizeof(res_lib_confdb_object_create);
  302. res_lib_confdb_object_create.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  303. res_lib_confdb_object_create.header.error = ret;
  304. api->ipc_response_send(conn, &res_lib_confdb_object_create, sizeof(res_lib_confdb_object_create));
  305. }
  306. static void message_handler_req_lib_confdb_object_destroy (void *conn,
  307. const void *message)
  308. {
  309. const struct req_lib_confdb_object_destroy *req_lib_confdb_object_destroy
  310. = message;
  311. coroipc_response_header_t res;
  312. int ret = CS_OK;
  313. if (api->object_destroy(req_lib_confdb_object_destroy->object_handle))
  314. ret = CS_ERR_ACCESS;
  315. res.size = sizeof(res);
  316. res.id = MESSAGE_RES_CONFDB_OBJECT_DESTROY;
  317. res.error = ret;
  318. api->ipc_response_send(conn, &res, sizeof(res));
  319. }
  320. static void message_handler_req_lib_confdb_object_find_destroy (void *conn,
  321. const void *message)
  322. {
  323. const struct req_lib_confdb_object_find_destroy
  324. *req_lib_confdb_object_find_destroy = message;
  325. coroipc_response_header_t res;
  326. int ret = CS_OK;
  327. if (api->object_find_destroy(req_lib_confdb_object_find_destroy->find_handle))
  328. ret = CS_ERR_ACCESS;
  329. res.size = sizeof(res);
  330. res.id = MESSAGE_RES_CONFDB_OBJECT_FIND_DESTROY;
  331. res.error = ret;
  332. api->ipc_response_send(conn, &res, sizeof(res));
  333. }
  334. static void message_handler_req_lib_confdb_key_create (void *conn,
  335. const void *message)
  336. {
  337. const struct req_lib_confdb_key_create *req_lib_confdb_key_create
  338. = message;
  339. coroipc_response_header_t res;
  340. int ret = CS_OK;
  341. if (api->object_key_create(req_lib_confdb_key_create->object_handle,
  342. req_lib_confdb_key_create->key_name.value,
  343. req_lib_confdb_key_create->key_name.length,
  344. req_lib_confdb_key_create->value.value,
  345. req_lib_confdb_key_create->value.length))
  346. ret = CS_ERR_ACCESS;
  347. res.size = sizeof(res);
  348. res.id = MESSAGE_RES_CONFDB_KEY_CREATE;
  349. res.error = ret;
  350. api->ipc_response_send(conn, &res, sizeof(res));
  351. }
  352. static void message_handler_req_lib_confdb_key_create_typed (void *conn,
  353. const void *message)
  354. {
  355. const struct req_lib_confdb_key_create_typed *req_lib_confdb_key_create
  356. = message;
  357. coroipc_response_header_t res;
  358. int ret = CS_OK;
  359. if (api->object_key_create_typed(req_lib_confdb_key_create->object_handle,
  360. (char*)req_lib_confdb_key_create->key_name.value,
  361. req_lib_confdb_key_create->value.value,
  362. req_lib_confdb_key_create->value.length,
  363. req_lib_confdb_key_create->type))
  364. ret = CS_ERR_ACCESS;
  365. res.size = sizeof(res);
  366. res.id = MESSAGE_RES_CONFDB_KEY_CREATE;
  367. res.error = ret;
  368. api->ipc_response_send(conn, &res, sizeof(res));
  369. }
  370. static void message_handler_req_lib_confdb_key_get (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_get res_lib_confdb_key_get;
  375. size_t value_len;
  376. void *value;
  377. int ret = CS_OK;
  378. if (api->object_key_get(req_lib_confdb_key_get->parent_object_handle,
  379. req_lib_confdb_key_get->key_name.value,
  380. req_lib_confdb_key_get->key_name.length,
  381. &value,
  382. &value_len))
  383. ret = CS_ERR_ACCESS;
  384. else {
  385. memcpy(res_lib_confdb_key_get.value.value, value, value_len);
  386. res_lib_confdb_key_get.value.length = value_len;
  387. }
  388. res_lib_confdb_key_get.header.size = sizeof(res_lib_confdb_key_get);
  389. res_lib_confdb_key_get.header.id = MESSAGE_RES_CONFDB_KEY_GET;
  390. res_lib_confdb_key_get.header.error = ret;
  391. api->ipc_response_send(conn, &res_lib_confdb_key_get, sizeof(res_lib_confdb_key_get));
  392. }
  393. static void message_handler_req_lib_confdb_key_get_typed (void *conn,
  394. const void *message)
  395. {
  396. const struct req_lib_confdb_key_get *req_lib_confdb_key_get = message;
  397. struct res_lib_confdb_key_get_typed res_lib_confdb_key_get;
  398. size_t value_len;
  399. void *value;
  400. int ret = CS_OK;
  401. objdb_value_types_t type;
  402. char * key_name = (char*)req_lib_confdb_key_get->key_name.value;
  403. key_name[req_lib_confdb_key_get->key_name.length] = '\0';
  404. if (api->object_key_get_typed(req_lib_confdb_key_get->parent_object_handle,
  405. key_name,
  406. &value,
  407. &value_len, &type))
  408. ret = CS_ERR_ACCESS;
  409. else {
  410. memcpy(res_lib_confdb_key_get.value.value, value, value_len);
  411. res_lib_confdb_key_get.value.length = value_len;
  412. res_lib_confdb_key_get.type = type;
  413. }
  414. res_lib_confdb_key_get.header.size = sizeof(res_lib_confdb_key_get);
  415. res_lib_confdb_key_get.header.id = MESSAGE_RES_CONFDB_KEY_GET_TYPED;
  416. res_lib_confdb_key_get.header.error = ret;
  417. api->ipc_response_send(conn, &res_lib_confdb_key_get, sizeof(res_lib_confdb_key_get));
  418. }
  419. static void message_handler_req_lib_confdb_key_increment (void *conn,
  420. const void *message)
  421. {
  422. const struct req_lib_confdb_key_get *req_lib_confdb_key_get = message;
  423. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  424. int ret = CS_OK;
  425. if (api->object_key_increment(req_lib_confdb_key_get->parent_object_handle,
  426. req_lib_confdb_key_get->key_name.value,
  427. req_lib_confdb_key_get->key_name.length,
  428. &res_lib_confdb_key_incdec.value))
  429. ret = CS_ERR_ACCESS;
  430. res_lib_confdb_key_incdec.header.size = sizeof(res_lib_confdb_key_incdec);
  431. res_lib_confdb_key_incdec.header.id = MESSAGE_RES_CONFDB_KEY_INCREMENT;
  432. res_lib_confdb_key_incdec.header.error = ret;
  433. api->ipc_response_send(conn, &res_lib_confdb_key_incdec, sizeof(res_lib_confdb_key_incdec));
  434. }
  435. static void message_handler_req_lib_confdb_key_decrement (void *conn,
  436. const void *message)
  437. {
  438. const struct req_lib_confdb_key_get *req_lib_confdb_key_get = message;
  439. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  440. int ret = CS_OK;
  441. if (api->object_key_decrement(req_lib_confdb_key_get->parent_object_handle,
  442. req_lib_confdb_key_get->key_name.value,
  443. req_lib_confdb_key_get->key_name.length,
  444. &res_lib_confdb_key_incdec.value))
  445. ret = CS_ERR_ACCESS;
  446. res_lib_confdb_key_incdec.header.size = sizeof(res_lib_confdb_key_incdec);
  447. res_lib_confdb_key_incdec.header.id = MESSAGE_RES_CONFDB_KEY_DECREMENT;
  448. res_lib_confdb_key_incdec.header.error = ret;
  449. api->ipc_response_send(conn, &res_lib_confdb_key_incdec, sizeof(res_lib_confdb_key_incdec));
  450. }
  451. static void message_handler_req_lib_confdb_key_replace (void *conn,
  452. const void *message)
  453. {
  454. const struct req_lib_confdb_key_replace *req_lib_confdb_key_replace
  455. = message;
  456. coroipc_response_header_t res;
  457. int ret = CS_OK;
  458. if (api->object_key_replace(req_lib_confdb_key_replace->object_handle,
  459. req_lib_confdb_key_replace->key_name.value,
  460. req_lib_confdb_key_replace->key_name.length,
  461. req_lib_confdb_key_replace->new_value.value,
  462. req_lib_confdb_key_replace->new_value.length))
  463. ret = CS_ERR_ACCESS;
  464. res.size = sizeof(res);
  465. res.id = MESSAGE_RES_CONFDB_KEY_REPLACE;
  466. res.error = ret;
  467. api->ipc_response_send(conn, &res, sizeof(res));
  468. }
  469. static void message_handler_req_lib_confdb_key_delete (void *conn,
  470. const void *message)
  471. {
  472. const struct req_lib_confdb_key_delete *req_lib_confdb_key_delete
  473. = message;
  474. coroipc_response_header_t res;
  475. int ret = CS_OK;
  476. if (api->object_key_delete(req_lib_confdb_key_delete->object_handle,
  477. req_lib_confdb_key_delete->key_name.value,
  478. req_lib_confdb_key_delete->key_name.length))
  479. ret = CS_ERR_ACCESS;
  480. res.size = sizeof(res);
  481. res.id = MESSAGE_RES_CONFDB_KEY_DELETE;
  482. res.error = ret;
  483. api->ipc_response_send(conn, &res, sizeof(res));
  484. }
  485. static void message_handler_req_lib_confdb_object_parent_get (void *conn,
  486. const void *message)
  487. {
  488. const struct req_lib_confdb_object_parent_get
  489. *req_lib_confdb_object_parent_get = message;
  490. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  491. hdb_handle_t object_handle;
  492. int ret = CS_OK;
  493. if (api->object_parent_get(req_lib_confdb_object_parent_get->object_handle,
  494. &object_handle))
  495. ret = CS_ERR_ACCESS;
  496. res_lib_confdb_object_parent_get.parent_object_handle = object_handle;
  497. res_lib_confdb_object_parent_get.header.size = sizeof(res_lib_confdb_object_parent_get);
  498. res_lib_confdb_object_parent_get.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  499. res_lib_confdb_object_parent_get.header.error = ret;
  500. api->ipc_response_send(conn, &res_lib_confdb_object_parent_get, sizeof(res_lib_confdb_object_parent_get));
  501. }
  502. static void message_handler_req_lib_confdb_key_iter (void *conn,
  503. const void *message)
  504. {
  505. const struct req_lib_confdb_key_iter *req_lib_confdb_key_iter = message;
  506. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  507. void *key_name;
  508. size_t key_name_len;
  509. void *value;
  510. size_t value_len;
  511. int ret = CS_OK;
  512. if (api->object_key_iter_from(req_lib_confdb_key_iter->parent_object_handle,
  513. req_lib_confdb_key_iter->next_entry,
  514. &key_name,
  515. &key_name_len,
  516. &value,
  517. &value_len))
  518. ret = CS_ERR_ACCESS;
  519. else {
  520. memcpy(res_lib_confdb_key_iter.key_name.value, key_name, key_name_len);
  521. memcpy(res_lib_confdb_key_iter.value.value, value, value_len);
  522. res_lib_confdb_key_iter.key_name.length = key_name_len;
  523. res_lib_confdb_key_iter.value.length = value_len;
  524. }
  525. res_lib_confdb_key_iter.header.size = sizeof(res_lib_confdb_key_iter);
  526. res_lib_confdb_key_iter.header.id = MESSAGE_RES_CONFDB_KEY_ITER;
  527. res_lib_confdb_key_iter.header.error = ret;
  528. api->ipc_response_send(conn, &res_lib_confdb_key_iter, sizeof(res_lib_confdb_key_iter));
  529. }
  530. static void message_handler_req_lib_confdb_key_iter_typed (void *conn,
  531. const void *message)
  532. {
  533. const struct req_lib_confdb_key_iter *req_lib_confdb_key_iter = message;
  534. struct res_lib_confdb_key_iter_typed res_lib_confdb_key_iter;
  535. void *key_name;
  536. size_t key_name_len;
  537. void *value;
  538. size_t value_len;
  539. int ret = CS_OK;
  540. objdb_value_types_t my_type;
  541. if (api->object_key_iter_from(req_lib_confdb_key_iter->parent_object_handle,
  542. req_lib_confdb_key_iter->next_entry,
  543. &key_name,
  544. &key_name_len,
  545. &value,
  546. &value_len))
  547. ret = CS_ERR_ACCESS;
  548. else {
  549. memcpy(res_lib_confdb_key_iter.key_name.value, key_name, key_name_len);
  550. memcpy(res_lib_confdb_key_iter.value.value, value, value_len);
  551. res_lib_confdb_key_iter.key_name.length = key_name_len;
  552. res_lib_confdb_key_iter.key_name.value[key_name_len] = '\0';
  553. res_lib_confdb_key_iter.value.length = value_len;
  554. api->object_key_get_typed(req_lib_confdb_key_iter->parent_object_handle,
  555. (const char*)res_lib_confdb_key_iter.key_name.value,
  556. &value,
  557. &value_len,
  558. &my_type);
  559. res_lib_confdb_key_iter.type = my_type;
  560. }
  561. res_lib_confdb_key_iter.header.size = sizeof(res_lib_confdb_key_iter);
  562. res_lib_confdb_key_iter.header.id = MESSAGE_RES_CONFDB_KEY_ITER_TYPED;
  563. res_lib_confdb_key_iter.header.error = ret;
  564. api->ipc_response_send(conn, &res_lib_confdb_key_iter, sizeof(res_lib_confdb_key_iter));
  565. }
  566. static void message_handler_req_lib_confdb_object_iter (void *conn,
  567. const void *message)
  568. {
  569. const struct req_lib_confdb_object_iter *req_lib_confdb_object_iter
  570. = message;
  571. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  572. size_t object_name_len;
  573. int ret = CS_OK;
  574. if (!req_lib_confdb_object_iter->find_handle) {
  575. api->object_find_create(req_lib_confdb_object_iter->parent_object_handle,
  576. NULL, 0,
  577. m2h(&res_lib_confdb_object_iter.find_handle));
  578. }
  579. else
  580. res_lib_confdb_object_iter.find_handle = req_lib_confdb_object_iter->find_handle;
  581. if (api->object_find_next(res_lib_confdb_object_iter.find_handle,
  582. m2h(&res_lib_confdb_object_iter.object_handle))) {
  583. ret = CS_ERR_ACCESS;
  584. api->object_find_destroy(res_lib_confdb_object_iter.find_handle);
  585. }
  586. else {
  587. api->object_name_get(res_lib_confdb_object_iter.object_handle,
  588. (char *)res_lib_confdb_object_iter.object_name.value,
  589. &object_name_len);
  590. res_lib_confdb_object_iter.object_name.length = object_name_len;
  591. }
  592. res_lib_confdb_object_iter.header.size = sizeof(res_lib_confdb_object_iter);
  593. res_lib_confdb_object_iter.header.id = MESSAGE_RES_CONFDB_OBJECT_ITER;
  594. res_lib_confdb_object_iter.header.error = ret;
  595. api->ipc_response_send(conn, &res_lib_confdb_object_iter, sizeof(res_lib_confdb_object_iter));
  596. }
  597. static void message_handler_req_lib_confdb_object_find (void *conn,
  598. const void *message)
  599. {
  600. const struct req_lib_confdb_object_find *req_lib_confdb_object_find
  601. = message;
  602. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  603. int ret = CS_OK;
  604. if (!req_lib_confdb_object_find->find_handle) {
  605. api->object_find_create(req_lib_confdb_object_find->parent_object_handle,
  606. req_lib_confdb_object_find->object_name.value,
  607. req_lib_confdb_object_find->object_name.length,
  608. m2h(&res_lib_confdb_object_find.find_handle));
  609. }
  610. else
  611. res_lib_confdb_object_find.find_handle = req_lib_confdb_object_find->find_handle;
  612. if (api->object_find_next(res_lib_confdb_object_find.find_handle,
  613. m2h(&res_lib_confdb_object_find.object_handle))) {
  614. ret = CS_ERR_ACCESS;
  615. api->object_find_destroy(res_lib_confdb_object_find.find_handle);
  616. }
  617. res_lib_confdb_object_find.header.size = sizeof(res_lib_confdb_object_find);
  618. res_lib_confdb_object_find.header.id = MESSAGE_RES_CONFDB_OBJECT_FIND;
  619. res_lib_confdb_object_find.header.error = ret;
  620. api->ipc_response_send(conn, &res_lib_confdb_object_find, sizeof(res_lib_confdb_object_find));
  621. }
  622. static void message_handler_req_lib_confdb_write (void *conn,
  623. const void *message)
  624. {
  625. struct res_lib_confdb_write res_lib_confdb_write;
  626. int ret = CS_OK;
  627. const char *error_string = NULL;
  628. if (api->object_write_config(&error_string))
  629. ret = CS_ERR_ACCESS;
  630. res_lib_confdb_write.header.size = sizeof(res_lib_confdb_write);
  631. res_lib_confdb_write.header.id = MESSAGE_RES_CONFDB_WRITE;
  632. res_lib_confdb_write.header.error = ret;
  633. if (error_string) {
  634. strcpy((char *)res_lib_confdb_write.error.value, error_string);
  635. res_lib_confdb_write.error.length = strlen(error_string) + 1;
  636. } else
  637. res_lib_confdb_write.error.length = 0;
  638. api->ipc_response_send(conn, &res_lib_confdb_write, sizeof(res_lib_confdb_write));
  639. }
  640. static void message_handler_req_lib_confdb_reload (void *conn,
  641. const void *message)
  642. {
  643. const struct req_lib_confdb_reload *req_lib_confdb_reload = message;
  644. struct res_lib_confdb_reload res_lib_confdb_reload;
  645. int ret = CS_OK;
  646. const char *error_string = NULL;
  647. if (api->object_reload_config(req_lib_confdb_reload->flush, &error_string))
  648. ret = CS_ERR_ACCESS;
  649. res_lib_confdb_reload.header.size = sizeof(res_lib_confdb_reload);
  650. res_lib_confdb_reload.header.id = MESSAGE_RES_CONFDB_RELOAD;
  651. res_lib_confdb_reload.header.error = ret;
  652. if(error_string) {
  653. strcpy((char *)res_lib_confdb_reload.error.value, error_string);
  654. res_lib_confdb_reload.error.length = strlen(error_string) + 1;
  655. } else
  656. res_lib_confdb_reload.error.length = 0;
  657. api->ipc_response_send(conn, &res_lib_confdb_reload, sizeof(res_lib_confdb_reload));
  658. }
  659. static void confdb_notify_lib_of_key_change(object_change_type_t change_type,
  660. hdb_handle_t parent_object_handle,
  661. hdb_handle_t object_handle,
  662. const void *object_name_pt, size_t object_name_len,
  663. const void *key_name_pt, size_t key_name_len,
  664. const void *key_value_pt, size_t key_value_len,
  665. void *priv_data_pt)
  666. {
  667. struct res_lib_confdb_key_change_callback res;
  668. res.header.size = sizeof(res);
  669. res.header.id = MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK;
  670. res.header.error = CS_OK;
  671. // handle & type
  672. res.change_type = change_type;
  673. res.parent_object_handle = parent_object_handle;
  674. res.object_handle = object_handle;
  675. //object
  676. memcpy(res.object_name.value, object_name_pt, object_name_len);
  677. res.object_name.length = object_name_len;
  678. //key name
  679. memcpy(res.key_name.value, key_name_pt, key_name_len);
  680. res.key_name.length = key_name_len;
  681. //key value
  682. memcpy(res.key_value.value, key_value_pt, key_value_len);
  683. res.key_value.length = key_value_len;
  684. api->ipc_dispatch_send(priv_data_pt, &res, sizeof(res));
  685. }
  686. static void confdb_notify_lib_of_new_object(hdb_handle_t parent_object_handle,
  687. hdb_handle_t object_handle,
  688. const uint8_t *name_pt, size_t name_len,
  689. void *priv_data_pt)
  690. {
  691. struct res_lib_confdb_object_create_callback res;
  692. res.header.size = sizeof(res);
  693. res.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK;
  694. res.header.error = CS_OK;
  695. res.parent_object_handle = parent_object_handle;
  696. res.object_handle = object_handle;
  697. memcpy(res.name.value, name_pt, name_len);
  698. res.name.length = name_len;
  699. api->ipc_dispatch_send(priv_data_pt, &res, sizeof(res));
  700. }
  701. static void confdb_notify_lib_of_destroyed_object(
  702. hdb_handle_t parent_object_handle,
  703. const uint8_t *name_pt, size_t name_len,
  704. void *priv_data_pt)
  705. {
  706. struct res_lib_confdb_object_destroy_callback res;
  707. res.header.size = sizeof(res);
  708. res.header.id = MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK;
  709. res.header.error = CS_OK;
  710. res.parent_object_handle = parent_object_handle;
  711. memcpy(res.name.value, name_pt, name_len);
  712. res.name.length = name_len;
  713. api->ipc_dispatch_send(priv_data_pt, &res, sizeof(res));
  714. }
  715. static void confdb_notify_lib_of_reload(objdb_reload_notify_type_t notify_type,
  716. int flush,
  717. void *priv_data_pt)
  718. {
  719. struct res_lib_confdb_reload_callback res;
  720. res.header.size = sizeof(res);
  721. res.header.id = MESSAGE_RES_CONFDB_RELOAD_CALLBACK;
  722. res.header.error = CS_OK;
  723. res.type = notify_type;
  724. api->ipc_dispatch_send(priv_data_pt, &res, sizeof(res));
  725. }
  726. static void message_handler_req_lib_confdb_track_start (void *conn,
  727. const void *message)
  728. {
  729. const struct req_lib_confdb_object_track_start *req = message;
  730. coroipc_response_header_t res;
  731. api->object_track_start(req->object_handle,
  732. req->flags,
  733. confdb_notify_lib_of_key_change,
  734. confdb_notify_lib_of_new_object,
  735. confdb_notify_lib_of_destroyed_object,
  736. confdb_notify_lib_of_reload,
  737. conn);
  738. res.size = sizeof(res);
  739. res.id = MESSAGE_RES_CONFDB_TRACK_START;
  740. res.error = CS_OK;
  741. api->ipc_response_send(conn, &res, sizeof(res));
  742. }
  743. static void message_handler_req_lib_confdb_track_stop (void *conn,
  744. const void *message)
  745. {
  746. coroipc_response_header_t res;
  747. api->object_track_stop(confdb_notify_lib_of_key_change,
  748. confdb_notify_lib_of_new_object,
  749. confdb_notify_lib_of_destroyed_object,
  750. confdb_notify_lib_of_reload,
  751. conn);
  752. res.size = sizeof(res);
  753. res.id = MESSAGE_RES_CONFDB_TRACK_STOP;
  754. res.error = CS_OK;
  755. api->ipc_response_send(conn, &res, sizeof(res));
  756. }