4
0

confdb.c 30 KB

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