confdb.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /*
  2. * Copyright (c) 2008 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 "../include/saAis.h"
  41. #include "../include/ipc_gen.h"
  42. #include "../include/ipc_confdb.h"
  43. #include "../include/mar_gen.h"
  44. #include "../lcr/lcr_comp.h"
  45. #include "../exec/logsys.h"
  46. #include "../include/coroapi.h"
  47. LOGSYS_DECLARE_SUBSYS ("CONFDB", LOG_DEBUG);
  48. static struct corosync_api_v1 *api;
  49. static int confdb_exec_init_fn (
  50. struct corosync_api_v1 *corosync_api);
  51. static int confdb_lib_init_fn (void *conn);
  52. static int confdb_lib_exit_fn (void *conn);
  53. static void message_handler_req_lib_confdb_object_create (void *conn, void *message);
  54. static void message_handler_req_lib_confdb_object_destroy (void *conn, void *message);
  55. static void message_handler_req_lib_confdb_key_create (void *conn, void *message);
  56. static void message_handler_req_lib_confdb_key_get (void *conn, void *message);
  57. static void message_handler_req_lib_confdb_key_replace (void *conn, void *message);
  58. static void message_handler_req_lib_confdb_key_delete (void *conn, void *message);
  59. static void message_handler_req_lib_confdb_key_iter (void *conn, void *message);
  60. static void message_handler_req_lib_confdb_object_iter (void *conn, void *message);
  61. static void message_handler_req_lib_confdb_object_find (void *conn, void *message);
  62. static void message_handler_req_lib_confdb_object_parent_get (void *conn, void *message);
  63. static void message_handler_req_lib_confdb_write (void *conn, void *message);
  64. static void message_handler_req_lib_confdb_track_start (void *conn, void *message);
  65. static void message_handler_req_lib_confdb_track_stop (void *conn, void *message);
  66. static void confdb_notify_lib_of_key_change(object_change_type_t change_type,
  67. unsigned int parent_object_handle,
  68. unsigned int object_handle,
  69. void *object_name_pt, int object_name_len,
  70. void *key_name_pt, int key_name_len,
  71. void *key_value_pt, int key_value_len,
  72. void *priv_data_pt);
  73. static void confdb_notify_lib_of_new_object(unsigned int parent_object_handle,
  74. unsigned int object_handle,
  75. uint8_t *name_pt, int name_len,
  76. void *priv_data_pt);
  77. static void confdb_notify_lib_of_destroyed_object(unsigned int parent_object_handle,
  78. uint8_t *name_pt, int name_len,
  79. void *priv_data_pt);
  80. /*
  81. * Library Handler Definition
  82. */
  83. static struct corosync_lib_handler confdb_lib_engine[] =
  84. {
  85. { /* 0 */
  86. .lib_handler_fn = message_handler_req_lib_confdb_object_create,
  87. .response_size = sizeof (mar_res_header_t),
  88. .response_id = MESSAGE_RES_CONFDB_OBJECT_CREATE,
  89. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  90. },
  91. { /* 1 */
  92. .lib_handler_fn = message_handler_req_lib_confdb_object_destroy,
  93. .response_size = sizeof (mar_res_header_t),
  94. .response_id = MESSAGE_RES_CONFDB_OBJECT_DESTROY,
  95. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  96. },
  97. { /* 2 */
  98. .lib_handler_fn = message_handler_req_lib_confdb_object_find,
  99. .response_size = sizeof (struct res_lib_confdb_object_find),
  100. .response_id = MESSAGE_RES_CONFDB_OBJECT_FIND,
  101. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  102. },
  103. { /* 3 */
  104. .lib_handler_fn = message_handler_req_lib_confdb_key_create,
  105. .response_size = sizeof (mar_res_header_t),
  106. .response_id = MESSAGE_RES_CONFDB_KEY_CREATE,
  107. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  108. },
  109. { /* 4 */
  110. .lib_handler_fn = message_handler_req_lib_confdb_key_get,
  111. .response_size = sizeof (struct res_lib_confdb_key_get),
  112. .response_id = MESSAGE_RES_CONFDB_KEY_GET,
  113. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  114. },
  115. { /* 5 */
  116. .lib_handler_fn = message_handler_req_lib_confdb_key_replace,
  117. .response_size = sizeof (mar_res_header_t),
  118. .response_id = MESSAGE_RES_CONFDB_KEY_REPLACE,
  119. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  120. },
  121. { /* 6 */
  122. .lib_handler_fn = message_handler_req_lib_confdb_key_delete,
  123. .response_size = sizeof (mar_res_header_t),
  124. .response_id = MESSAGE_RES_CONFDB_KEY_DELETE,
  125. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  126. },
  127. { /* 7 */
  128. .lib_handler_fn = message_handler_req_lib_confdb_object_iter,
  129. .response_size = sizeof (struct res_lib_confdb_object_iter),
  130. .response_id = MESSAGE_RES_CONFDB_OBJECT_ITER,
  131. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  132. },
  133. { /* 8 */
  134. .lib_handler_fn = message_handler_req_lib_confdb_object_parent_get,
  135. .response_size = sizeof (struct res_lib_confdb_object_parent_get),
  136. .response_id = MESSAGE_RES_CONFDB_OBJECT_PARENT_GET,
  137. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  138. },
  139. { /* 9 */
  140. .lib_handler_fn = message_handler_req_lib_confdb_key_iter,
  141. .response_size = sizeof (struct res_lib_confdb_key_iter),
  142. .response_id = MESSAGE_RES_CONFDB_KEY_ITER,
  143. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  144. },
  145. { /* 10 */
  146. .lib_handler_fn = message_handler_req_lib_confdb_track_start,
  147. .response_size = sizeof (mar_res_header_t),
  148. .response_id = MESSAGE_RES_CONFDB_TRACK_START,
  149. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  150. },
  151. { /* 11 */
  152. .lib_handler_fn = message_handler_req_lib_confdb_track_stop,
  153. .response_size = sizeof (mar_res_header_t),
  154. .response_id = MESSAGE_RES_CONFDB_TRACK_STOP,
  155. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  156. },
  157. { /* 12 */
  158. .lib_handler_fn = message_handler_req_lib_confdb_write,
  159. .response_size = sizeof (struct res_lib_confdb_write),
  160. .response_id = MESSAGE_RES_CONFDB_WRITE,
  161. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  162. },
  163. };
  164. struct corosync_service_engine confdb_service_engine = {
  165. .name = "corosync cluster config database access v1.01",
  166. .id = CONFDB_SERVICE,
  167. .private_data_size = 0,
  168. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED,
  169. .lib_init_fn = confdb_lib_init_fn,
  170. .lib_exit_fn = confdb_lib_exit_fn,
  171. .lib_engine = confdb_lib_engine,
  172. .lib_engine_count = sizeof (confdb_lib_engine) / sizeof (struct corosync_lib_handler),
  173. .exec_init_fn = confdb_exec_init_fn,
  174. };
  175. /*
  176. * Dynamic loader definition
  177. */
  178. static struct corosync_service_engine *confdb_get_service_engine_ver0 (void);
  179. static struct corosync_service_engine_iface_ver0 confdb_service_engine_iface = {
  180. .corosync_get_service_engine_ver0 = confdb_get_service_engine_ver0
  181. };
  182. static struct lcr_iface corosync_confdb_ver0[1] = {
  183. {
  184. .name = "corosync_confdb",
  185. .version = 0,
  186. .versions_replace = 0,
  187. .versions_replace_count = 0,
  188. .dependencies = 0,
  189. .dependency_count = 0,
  190. .constructor = NULL,
  191. .destructor = NULL,
  192. .interfaces = NULL
  193. }
  194. };
  195. static struct lcr_comp confdb_comp_ver0 = {
  196. .iface_count = 1,
  197. .ifaces = corosync_confdb_ver0
  198. };
  199. static struct corosync_service_engine *confdb_get_service_engine_ver0 (void)
  200. {
  201. return (&confdb_service_engine);
  202. }
  203. __attribute__ ((constructor)) static void confdb_comp_register (void) {
  204. lcr_interfaces_set (&corosync_confdb_ver0[0], &confdb_service_engine_iface);
  205. lcr_component_register (&confdb_comp_ver0);
  206. }
  207. static int confdb_exec_init_fn (
  208. struct corosync_api_v1 *corosync_api)
  209. {
  210. api = corosync_api;
  211. return 0;
  212. }
  213. static int confdb_lib_init_fn (void *conn)
  214. {
  215. log_printf(LOG_LEVEL_DEBUG, "lib_init_fn: conn=%p\n", conn);
  216. return (0);
  217. }
  218. static int confdb_lib_exit_fn (void *conn)
  219. {
  220. log_printf(LOG_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn);
  221. /* cleanup the object trackers for this client. */
  222. api->object_track_stop(confdb_notify_lib_of_key_change,
  223. confdb_notify_lib_of_new_object,
  224. confdb_notify_lib_of_destroyed_object,
  225. api->ipc_conn_partner_get (conn));
  226. return (0);
  227. }
  228. static void message_handler_req_lib_confdb_object_create (void *conn, void *message)
  229. {
  230. struct req_lib_confdb_object_create *req_lib_confdb_object_create = (struct req_lib_confdb_object_create *)message;
  231. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  232. unsigned int object_handle;
  233. int ret = SA_AIS_OK;
  234. if (api->object_create(req_lib_confdb_object_create->parent_object_handle,
  235. &object_handle,
  236. req_lib_confdb_object_create->object_name.value,
  237. req_lib_confdb_object_create->object_name.length))
  238. ret = SA_AIS_ERR_ACCESS;
  239. res_lib_confdb_object_create.object_handle = object_handle;
  240. res_lib_confdb_object_create.header.size = sizeof(res_lib_confdb_object_create);
  241. res_lib_confdb_object_create.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  242. res_lib_confdb_object_create.header.error = ret;
  243. api->ipc_conn_send_response(conn, &res_lib_confdb_object_create, sizeof(res_lib_confdb_object_create));
  244. }
  245. static void message_handler_req_lib_confdb_object_destroy (void *conn, void *message)
  246. {
  247. struct req_lib_confdb_object_destroy *req_lib_confdb_object_destroy = (struct req_lib_confdb_object_destroy *)message;
  248. mar_res_header_t res;
  249. int ret = SA_AIS_OK;
  250. if (api->object_destroy(req_lib_confdb_object_destroy->object_handle))
  251. ret = SA_AIS_ERR_ACCESS;
  252. res.size = sizeof(res);
  253. res.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  254. res.error = ret;
  255. api->ipc_conn_send_response(conn, &res, sizeof(res));
  256. }
  257. static void message_handler_req_lib_confdb_key_create (void *conn, void *message)
  258. {
  259. struct req_lib_confdb_key_create *req_lib_confdb_key_create = (struct req_lib_confdb_key_create *)message;
  260. mar_res_header_t res;
  261. int ret = SA_AIS_OK;
  262. if (api->object_key_create(req_lib_confdb_key_create->object_handle,
  263. req_lib_confdb_key_create->key_name.value,
  264. req_lib_confdb_key_create->key_name.length,
  265. req_lib_confdb_key_create->value.value,
  266. req_lib_confdb_key_create->value.length))
  267. ret = SA_AIS_ERR_ACCESS;
  268. res.size = sizeof(res);
  269. res.id = MESSAGE_RES_CONFDB_KEY_CREATE;
  270. res.error = ret;
  271. api->ipc_conn_send_response(conn, &res, sizeof(res));
  272. }
  273. static void message_handler_req_lib_confdb_key_get (void *conn, void *message)
  274. {
  275. struct req_lib_confdb_key_get *req_lib_confdb_key_get = (struct req_lib_confdb_key_get *)message;
  276. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  277. int value_len;
  278. void *value;
  279. int ret = SA_AIS_OK;
  280. if (api->object_key_get(req_lib_confdb_key_get->parent_object_handle,
  281. req_lib_confdb_key_get->key_name.value,
  282. req_lib_confdb_key_get->key_name.length,
  283. &value,
  284. &value_len))
  285. ret = SA_AIS_ERR_ACCESS;
  286. else {
  287. memcpy(res_lib_confdb_key_get.value.value, value, value_len);
  288. res_lib_confdb_key_get.value.length = value_len;
  289. }
  290. res_lib_confdb_key_get.header.size = sizeof(res_lib_confdb_key_get);
  291. res_lib_confdb_key_get.header.id = MESSAGE_RES_CONFDB_KEY_GET;
  292. res_lib_confdb_key_get.header.error = ret;
  293. api->ipc_conn_send_response(conn, &res_lib_confdb_key_get, sizeof(res_lib_confdb_key_get));
  294. }
  295. static void message_handler_req_lib_confdb_key_replace (void *conn, void *message)
  296. {
  297. struct req_lib_confdb_key_replace *req_lib_confdb_key_replace = (struct req_lib_confdb_key_replace *)message;
  298. mar_res_header_t res;
  299. int ret = SA_AIS_OK;
  300. if (api->object_key_replace(req_lib_confdb_key_replace->object_handle,
  301. req_lib_confdb_key_replace->key_name.value,
  302. req_lib_confdb_key_replace->key_name.length,
  303. req_lib_confdb_key_replace->old_value.value,
  304. req_lib_confdb_key_replace->old_value.length,
  305. req_lib_confdb_key_replace->new_value.value,
  306. req_lib_confdb_key_replace->new_value.length))
  307. ret = SA_AIS_ERR_ACCESS;
  308. res.size = sizeof(res);
  309. res.id = MESSAGE_RES_CONFDB_KEY_REPLACE;
  310. res.error = ret;
  311. api->ipc_conn_send_response(conn, &res, sizeof(res));
  312. }
  313. static void message_handler_req_lib_confdb_key_delete (void *conn, void *message)
  314. {
  315. struct req_lib_confdb_key_delete *req_lib_confdb_key_delete = (struct req_lib_confdb_key_delete *)message;
  316. mar_res_header_t res;
  317. int ret = SA_AIS_OK;
  318. if (api->object_key_delete(req_lib_confdb_key_delete->object_handle,
  319. req_lib_confdb_key_delete->key_name.value,
  320. req_lib_confdb_key_delete->key_name.length,
  321. req_lib_confdb_key_delete->value.value,
  322. req_lib_confdb_key_delete->value.length))
  323. ret = SA_AIS_ERR_ACCESS;
  324. res.size = sizeof(res);
  325. res.id = MESSAGE_RES_CONFDB_KEY_DELETE;
  326. res.error = ret;
  327. api->ipc_conn_send_response(conn, &res, sizeof(res));
  328. }
  329. static void message_handler_req_lib_confdb_object_parent_get (void *conn, void *message)
  330. {
  331. struct req_lib_confdb_object_parent_get *req_lib_confdb_object_parent_get = (struct req_lib_confdb_object_parent_get *)message;
  332. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  333. unsigned int object_handle;
  334. int ret = SA_AIS_OK;
  335. if (api->object_parent_get(req_lib_confdb_object_parent_get->object_handle,
  336. &object_handle))
  337. ret = SA_AIS_ERR_ACCESS;
  338. res_lib_confdb_object_parent_get.parent_object_handle = object_handle;
  339. res_lib_confdb_object_parent_get.header.size = sizeof(res_lib_confdb_object_parent_get);
  340. res_lib_confdb_object_parent_get.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  341. res_lib_confdb_object_parent_get.header.error = ret;
  342. api->ipc_conn_send_response(conn, &res_lib_confdb_object_parent_get, sizeof(res_lib_confdb_object_parent_get));
  343. }
  344. static void message_handler_req_lib_confdb_key_iter (void *conn, void *message)
  345. {
  346. struct req_lib_confdb_key_iter *req_lib_confdb_key_iter = (struct req_lib_confdb_key_iter *)message;
  347. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  348. void *key_name;
  349. int key_name_len;
  350. void *value;
  351. int value_len;
  352. int ret = SA_AIS_OK;
  353. if (api->object_key_iter_from(req_lib_confdb_key_iter->parent_object_handle,
  354. req_lib_confdb_key_iter->next_entry,
  355. &key_name,
  356. &key_name_len,
  357. &value,
  358. &value_len))
  359. ret = SA_AIS_ERR_ACCESS;
  360. else {
  361. memcpy(res_lib_confdb_key_iter.key_name.value, key_name, key_name_len);
  362. memcpy(res_lib_confdb_key_iter.value.value, value, value_len);
  363. res_lib_confdb_key_iter.key_name.length = key_name_len;
  364. res_lib_confdb_key_iter.value.length = value_len;
  365. }
  366. res_lib_confdb_key_iter.header.size = sizeof(res_lib_confdb_key_iter);
  367. res_lib_confdb_key_iter.header.id = MESSAGE_RES_CONFDB_KEY_ITER;
  368. res_lib_confdb_key_iter.header.error = ret;
  369. api->ipc_conn_send_response(conn, &res_lib_confdb_key_iter, sizeof(res_lib_confdb_key_iter));
  370. }
  371. static void message_handler_req_lib_confdb_object_iter (void *conn, void *message)
  372. {
  373. struct req_lib_confdb_object_iter *req_lib_confdb_object_iter = (struct req_lib_confdb_object_iter *)message;
  374. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  375. void *object_name;
  376. int object_name_len;
  377. int ret = SA_AIS_OK;
  378. if (api->object_iter_from(req_lib_confdb_object_iter->parent_object_handle,
  379. req_lib_confdb_object_iter->next_entry,
  380. &object_name,
  381. &object_name_len,
  382. &res_lib_confdb_object_iter.object_handle))
  383. ret = SA_AIS_ERR_ACCESS;
  384. else {
  385. res_lib_confdb_object_iter.object_name.length = object_name_len;
  386. memcpy(res_lib_confdb_object_iter.object_name.value, object_name, object_name_len);
  387. }
  388. res_lib_confdb_object_iter.header.size = sizeof(res_lib_confdb_object_iter);
  389. res_lib_confdb_object_iter.header.id = MESSAGE_RES_CONFDB_OBJECT_ITER;
  390. res_lib_confdb_object_iter.header.error = ret;
  391. api->ipc_conn_send_response(conn, &res_lib_confdb_object_iter, sizeof(res_lib_confdb_object_iter));
  392. }
  393. static void message_handler_req_lib_confdb_object_find (void *conn, void *message)
  394. {
  395. struct req_lib_confdb_object_find *req_lib_confdb_object_find = (struct req_lib_confdb_object_find *)message;
  396. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  397. int ret = SA_AIS_OK;
  398. if (api->object_find_from(req_lib_confdb_object_find->parent_object_handle,
  399. req_lib_confdb_object_find->next_entry,
  400. req_lib_confdb_object_find->object_name.value,
  401. req_lib_confdb_object_find->object_name.length,
  402. &res_lib_confdb_object_find.object_handle,
  403. &res_lib_confdb_object_find.next_entry))
  404. ret = SA_AIS_ERR_ACCESS;
  405. res_lib_confdb_object_find.header.size = sizeof(res_lib_confdb_object_find);
  406. res_lib_confdb_object_find.header.id = MESSAGE_RES_CONFDB_OBJECT_FIND;
  407. res_lib_confdb_object_find.header.error = ret;
  408. api->ipc_conn_send_response(conn, &res_lib_confdb_object_find, sizeof(res_lib_confdb_object_find));
  409. }
  410. static void message_handler_req_lib_confdb_write (void *conn, void *message)
  411. {
  412. struct res_lib_confdb_write res_lib_confdb_write;
  413. int ret = SA_AIS_OK;
  414. char *error_string = NULL;
  415. if (api->object_write_config(&error_string))
  416. ret = SA_AIS_ERR_ACCESS;
  417. res_lib_confdb_write.header.size = sizeof(res_lib_confdb_write);
  418. res_lib_confdb_write.header.id = MESSAGE_RES_CONFDB_WRITE;
  419. res_lib_confdb_write.header.error = ret;
  420. if (error_string) {
  421. strcpy((char *)res_lib_confdb_write.error.value, error_string);
  422. res_lib_confdb_write.error.length = strlen(error_string) + 1;
  423. } else
  424. res_lib_confdb_write.error.length = 0;
  425. api->ipc_conn_send_response(conn, &res_lib_confdb_write, sizeof(res_lib_confdb_write));
  426. }
  427. static void confdb_notify_lib_of_key_change(object_change_type_t change_type,
  428. unsigned int parent_object_handle,
  429. unsigned int object_handle,
  430. void *object_name_pt, int object_name_len,
  431. void *key_name_pt, int key_name_len,
  432. void *key_value_pt, int key_value_len,
  433. void *priv_data_pt)
  434. {
  435. struct res_lib_confdb_key_change_callback res;
  436. res.header.size = sizeof(res);
  437. res.header.id = MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK;
  438. res.header.error = SA_AIS_OK;
  439. // handle & type
  440. res.change_type = change_type;
  441. res.parent_object_handle = parent_object_handle;
  442. res.object_handle = object_handle;
  443. //object
  444. memcpy(res.object_name.value, object_name_pt, object_name_len);
  445. res.object_name.length = object_name_len;
  446. //key name
  447. memcpy(res.key_name.value, key_name_pt, key_name_len);
  448. res.key_name.length = key_name_len;
  449. //key value
  450. memcpy(res.key_value.value, key_value_pt, key_value_len);
  451. res.key_value.length = key_value_len;
  452. api->ipc_conn_send_response(priv_data_pt, &res, sizeof(res));
  453. }
  454. static void confdb_notify_lib_of_new_object(unsigned int parent_object_handle,
  455. unsigned int object_handle,
  456. uint8_t *name_pt, int name_len,
  457. void *priv_data_pt)
  458. {
  459. struct res_lib_confdb_object_create_callback res;
  460. res.header.size = sizeof(res);
  461. res.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK;
  462. res.header.error = SA_AIS_OK;
  463. res.parent_object_handle = parent_object_handle;
  464. res.object_handle = object_handle;
  465. memcpy(res.name.value, name_pt, name_len);
  466. res.name.length = name_len;
  467. api->ipc_conn_send_response(priv_data_pt, &res, sizeof(res));
  468. }
  469. static void confdb_notify_lib_of_destroyed_object(unsigned int parent_object_handle,
  470. uint8_t *name_pt, int name_len,
  471. void *priv_data_pt)
  472. {
  473. struct res_lib_confdb_object_destroy_callback res;
  474. res.header.size = sizeof(res);
  475. res.header.id = MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK;
  476. res.header.error = SA_AIS_OK;
  477. res.parent_object_handle = parent_object_handle;
  478. memcpy(res.name.value, name_pt, name_len);
  479. res.name.length = name_len;
  480. api->ipc_conn_send_response(priv_data_pt, &res, sizeof(res));
  481. }
  482. static void message_handler_req_lib_confdb_track_start (void *conn, void *message)
  483. {
  484. struct req_lib_confdb_object_track_start *req = (struct req_lib_confdb_object_track_start *)message;
  485. mar_res_header_t res;
  486. api->object_track_start(req->object_handle, req->flags,
  487. confdb_notify_lib_of_key_change,
  488. confdb_notify_lib_of_new_object,
  489. confdb_notify_lib_of_destroyed_object,
  490. api->ipc_conn_partner_get (conn));
  491. res.size = sizeof(res);
  492. res.id = MESSAGE_RES_CONFDB_TRACK_START;
  493. res.error = SA_AIS_OK;
  494. api->ipc_conn_send_response(conn, &res, sizeof(res));
  495. }
  496. static void message_handler_req_lib_confdb_track_stop (void *conn, void *message)
  497. {
  498. mar_res_header_t res;
  499. api->object_track_stop(confdb_notify_lib_of_key_change,
  500. confdb_notify_lib_of_new_object,
  501. confdb_notify_lib_of_destroyed_object,
  502. api->ipc_conn_partner_get (conn));
  503. res.size = sizeof(res);
  504. res.id = MESSAGE_RES_CONFDB_TRACK_STOP;
  505. res.error = SA_AIS_OK;
  506. api->ipc_conn_send_response(conn, &res, sizeof(res));
  507. }