17 #include <sys/types.h> 29 int rc, xmlNode * output));
32 void (*callback) (
const char *event, xmlNode * msg));
35 void (*callback) (
const char *event, xmlNode * msg));
39 #define op_common(cib) do { \ 42 } else if(cib->delegate_fn == NULL) { \ 43 return -EPROTONOSUPPORT; \ 48 cib_client_noop(
cib_t * cib,
int call_options)
55 cib_client_ping(
cib_t * cib, xmlNode ** output_data,
int call_options)
62 cib_client_query(
cib_t * cib,
const char *section, xmlNode ** output_data,
int call_options)
64 return cib->
cmds->
query_from(cib, NULL, section, output_data, call_options);
68 cib_client_query_from(
cib_t * cib,
const char *
host,
const char *section,
69 xmlNode ** output_data,
int call_options)
76 cib_client_is_master(
cib_t * cib)
84 cib_client_set_slave(
cib_t * cib,
int call_options)
91 cib_client_set_slave_all(
cib_t * cib,
int call_options)
93 return -EPROTONOSUPPORT;
97 cib_client_set_master(
cib_t * cib,
int call_options)
100 crm_trace(
"Adding cib_scope_local to options");
106 cib_client_bump_epoch(
cib_t * cib,
int call_options)
113 cib_client_upgrade(
cib_t * cib,
int call_options)
120 cib_client_sync(
cib_t * cib,
const char *section,
int call_options)
122 return cib->
cmds->
sync_from(cib, NULL, section, call_options);
126 cib_client_sync_from(
cib_t * cib,
const char *host,
const char *section,
int call_options)
133 cib_client_create(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
140 cib_client_modify(
cib_t * cib,
const char *section, xmlNode * data,
int call_options)
147 cib_client_update(
cib_t * cib,
const char *section, xmlNode * data,
int call_options)
154 cib_client_replace(
cib_t * cib,
const char *section, xmlNode * data,
int call_options)
161 cib_client_delete(
cib_t * cib,
const char *section, xmlNode * data,
int call_options)
168 cib_client_delete_absolute(
cib_t * cib,
const char *section, xmlNode * data,
int call_options)
175 cib_client_erase(
cib_t * cib, xmlNode ** output_data,
int call_options)
182 cib_destroy_op_callback(gpointer data)
199 destroy_op_callback_table()
210 char *cib_home = NULL;
211 char *fullname = NULL;
212 char *name = crm_concat(
"shadow", suffix,
'.');
213 const char *dir = getenv(
"CIB_shadow_dir");
216 uid_t uid = geteuid();
217 struct passwd *pwent = getpwuid(uid);
218 const char *user = NULL;
221 user = pwent->pw_name;
223 user = getenv(
"USER");
225 "Assuming %s because cannot get user details for user ID %d",
226 (user? user :
"unprivileged user"), uid);
233 const char *home = NULL;
235 if ((home = getenv(
"HOME")) == NULL) {
237 home = pwent->pw_dir;
242 if (home && home[0] ==
'/') {
245 cib_home = crm_concat(home,
".cib",
'/');
247 rc = mkdir(cib_home, 0700);
248 if (rc < 0 && errno != EEXIST) {
249 crm_perror(LOG_ERR,
"Couldn't create user-specific shadow directory: %s",
260 fullname = crm_concat(dir, name,
'/');
270 cib_t *new_cib = NULL;
271 char *shadow_file = NULL;
285 unsetenv(
"CIB_shadow");
292 const char *value = getenv(
"CIB_shadow");
294 if (value && value[0] != 0) {
298 value = getenv(
"CIB_file");
303 value = getenv(
"CIB_port");
305 gboolean encrypted = TRUE;
307 const char *server = getenv(
"CIB_server");
308 const char *user = getenv(
"CIB_user");
309 const char *pass = getenv(
"CIB_passwd");
311 value = getenv(
"CIB_encrypted");
319 crm_info(
"Defaulting to user: %s", user);
322 if (server == NULL) {
323 server =
"localhost";
324 crm_info(
"Defaulting to localhost");
345 cib_t *new_cib = NULL;
347 new_cib = calloc(1,
sizeof(
cib_t));
370 new_cib->
cmds->
noop = cib_client_noop;
371 new_cib->
cmds->
ping = cib_client_ping;
373 new_cib->
cmds->
sync = cib_client_sync;
409 while (list != NULL) {
412 list = g_list_remove(list, client);
417 destroy_op_callback_table();
436 int rc, xmlNode * output))
438 if (callback == NULL) {
439 crm_info(
"Un-Setting operation callback");
450 void (*callback) (
const char *event, xmlNode * msg))
452 GList *list_item = NULL;
456 return -EPROTONOSUPPORT;
462 new_client->
event = event;
467 if (list_item != NULL) {
468 crm_warn(
"Callback already present");
483 get_notify_list_event_count(
cib_t * cib,
const char *event)
488 for (l = g_list_first(cib->
notify_list); l; l = g_list_next(l)) {
491 if (strcmp(client->
event, event) == 0) {
495 crm_trace(
"event(%s) count : %d", event, count);
501 void (*callback) (
const char *event, xmlNode * msg))
503 GList *list_item = NULL;
507 return -EPROTONOSUPPORT;
510 if (get_notify_list_event_count(cib, event) == 0) {
511 crm_debug(
"The callback of the event does not exist(%s)", event);
515 crm_debug(
"Removing callback for %s events", event);
518 new_client->
event = event;
523 if (list_item != NULL) {
535 if (get_notify_list_event_count(cib, event) == 0) {
552 rc = strcmp(a_client->
event, b_client->
event);
557 crm_trace(
"callbacks for %s are not equal: %p < %p",
561 crm_trace(
"callbacks for %s are not equal: %p > %p",
569 cib_async_timeout_handler(gpointer data)
584 void *user_data,
const char *callback_name,
585 void (*callback) (xmlNode *,
int,
int, xmlNode *,
void *))
588 only_success, user_data,
589 callback_name, callback, NULL);
594 gboolean only_success,
void *user_data,
595 const char *callback_name,
596 void (*callback)(xmlNode *,
int,
int,
598 void (*free_func)(
void *))
603 if (only_success == FALSE) {
604 callback(NULL, call_id, call_id, NULL, user_data);
608 if (user_data && free_func) {
609 free_func(user_data);
615 blob->
id = callback_name;
624 async_timer = calloc(1,
sizeof(
struct timer_rec_s));
625 blob->
timer = async_timer;
629 async_timer->
timeout = timeout * 1000;
631 g_timeout_add(async_timer->
timeout, cib_async_timeout_handler, async_timer);
634 crm_trace(
"Adding callback %s for call %d", callback_name, call_id);
644 destroy_op_callback_table();
646 NULL, cib_destroy_op_callback);
662 cib_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
664 int call = GPOINTER_TO_INT(key);
#define CRM_CHECK(expr, failure_action)
const char * crm_get_tmpdir(void)
const char * pcmk_strerror(int rc)
gboolean(* register_callback)(cib_t *cib, int call_id, int timeout, gboolean only_success, void *user_data, const char *callback_name, void(*callback)(xmlNode *, int, int, xmlNode *, void *))
cib_t * cib_remote_new(const char *server, const char *user, const char *passwd, int port, gboolean encrypted)
int cib_client_add_notify_callback(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
void cib_dump_pending_callbacks(void)
int(* delete_absolute)(cib_t *cib, const char *section, xmlNode *data, int call_options)
int cib_client_del_notify_callback(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
gboolean(* register_callback_full)(cib_t *cib, int call_id, int timeout, gboolean only_success, void *user_data, const char *callback_name, void(*callback)(xmlNode *, int, int, xmlNode *, void *), void(*free_func)(void *))
void(* callback)(const char *event, xmlNode *msg)
void cib_free_callbacks(cib_t *cib)
Free all callbacks for a CIB connection.
int crm_parse_int(const char *text, const char *default_text)
Parse an integer value from a string.
cib_t * cib_shadow_new(const char *shadow)
GHashTable * cib_op_callback_table
int(* set_op_callback)(cib_t *cib, void(*callback)(const xmlNode *msg, int callid, int rc, xmlNode *output))
int(* sync)(cib_t *cib, const char *section, int call_options)
gboolean cib_client_register_callback_full(cib_t *cib, int call_id, int timeout, gboolean only_success, void *user_data, const char *callback_name, void(*callback)(xmlNode *, int, int, xmlNode *, void *), void(*free_func)(void *))
#define crm_warn(fmt, args...)
struct timer_rec_s * timer
int(* query_from)(cib_t *cib, const char *host, const char *section, xmlNode **output_data, int call_options)
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
int num_cib_op_callbacks(void)
int(* set_slave)(cib_t *cib, int call_options)
gboolean cib_client_register_callback(cib_t *cib, int call_id, int timeout, gboolean only_success, void *user_data, const char *callback_name, void(*callback)(xmlNode *, int, int, xmlNode *, void *))
void(* callback)(xmlNode *, int, int, xmlNode *, void *)
#define crm_trace(fmt, args...)
int(* modify)(cib_t *cib, const char *section, xmlNode *data, int call_options)
void(* op_callback)(const xmlNode *msg, int call_id, int rc, xmlNode *output)
char * get_shadow_file(const char *suffix)
int(* create)(cib_t *cib, const char *section, xmlNode *data, int call_options)
Wrappers for and extensions to libxml2.
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
int(* is_master)(cib_t *cib)
cib_t * cib_new_no_shadow(void)
cib_t * cib_native_new(void)
int(* replace)(cib_t *cib, const char *section, xmlNode *data, int call_options)
int(* add_notify_callback)(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
int(* sync_from)(cib_t *cib, const char *host, const char *section, int call_options)
int(* register_notification)(cib_t *cib, const char *callback, int enabled)
int(* ping)(cib_t *cib, xmlNode **output_data, int call_options)
int(* update)(cib_t *cib, const char *section, xmlNode *data, int call_options)
cib_t * cib_file_new(const char *filename)
int cib_client_set_op_callback(cib_t *cib, void(*callback)(const xmlNode *msg, int call_id, int rc, xmlNode *output))
int(* noop)(cib_t *cib, int call_options)
int(* set_slave_all)(cib_t *cib, int call_options)
int(* del_notify_callback)(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
#define crm_perror(level, fmt, args...)
Log a system error message.
int(* set_master)(cib_t *cib, int call_options)
void cib_native_callback(cib_t *cib, xmlNode *msg, int call_id, int rc)
cib_t * cib_new_variant(void)
int(* bump_epoch)(cib_t *cib, int call_options)
gboolean crm_is_true(const char *s)
int(* remove)(cib_t *cib, const char *section, xmlNode *data, int call_options)
#define CIB_OP_DELETE_ALT
int cib_internal_op(cib_t *cib, const char *op, const char *host, const char *section, xmlNode *data, xmlNode **output_data, int call_options, const char *user_name)
#define safe_str_eq(a, b)
void cib_delete(cib_t *cib)
Free all memory used by CIB connection.
void(* free_func)(void *)
int(* upgrade)(cib_t *cib, int call_options)
#define crm_info(fmt, args...)
int(* erase)(cib_t *cib, xmlNode **output_data, int call_options)
void remove_cib_op_callback(int call_id, gboolean all_callbacks)
gint ciblib_GCompareFunc(gconstpointer a, gconstpointer b)