28 #include <sys/types.h>
40 int rc, xmlNode * output));
43 void (*callback) (
const char *event, xmlNode * msg));
46 void (*callback) (
const char *event, xmlNode * msg));
50 #define op_common(cib) do { \
53 } else if(cib->delegate_fn == NULL) { \
54 return -EPROTONOSUPPORT; \
59 cib_client_noop(
cib_t * cib,
int call_options)
66 cib_client_ping(
cib_t * cib, xmlNode ** output_data,
int call_options)
73 cib_client_query(
cib_t * cib,
const char *section, xmlNode ** output_data,
int call_options)
75 return cib->
cmds->
query_from(cib, NULL, section, output_data, call_options);
79 cib_client_query_from(
cib_t * cib,
const char *
host,
const char *section,
80 xmlNode ** output_data,
int call_options)
87 cib_client_is_master(
cib_t * cib)
95 cib_client_set_slave(
cib_t * cib,
int call_options)
102 cib_client_set_slave_all(
cib_t * cib,
int call_options)
104 return -EPROTONOSUPPORT;
108 cib_client_set_master(
cib_t * cib,
int call_options)
111 crm_trace(
"Adding cib_scope_local to options");
117 cib_client_bump_epoch(
cib_t * cib,
int call_options)
124 cib_client_upgrade(
cib_t * cib,
int call_options)
131 cib_client_sync(
cib_t * cib,
const char *section,
int call_options)
133 return cib->
cmds->
sync_from(cib, NULL, section, call_options);
137 cib_client_sync_from(
cib_t * cib,
const char *
host,
const char *section,
int call_options)
144 cib_client_create(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
151 cib_client_modify(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
158 cib_client_update(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
165 cib_client_replace(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
172 cib_client_delete(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
179 cib_client_delete_absolute(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
186 cib_client_erase(
cib_t * cib, xmlNode ** output_data,
int call_options)
193 cib_destroy_op_callback(gpointer
data)
210 destroy_op_callback_table()
221 char *cib_home = NULL;
222 char *fullname = NULL;
223 char *name =
crm_concat(
"shadow", suffix,
'.');
224 const char *dir = getenv(
"CIB_shadow_dir");
227 uid_t uid = geteuid();
228 struct passwd *pwent = getpwuid(uid);
229 const char *user = NULL;
232 user = pwent->pw_name;
234 crm_perror(LOG_ERR,
"Cannot get password entry for uid: %d", uid);
235 user = getenv(
"USER");
242 const char *home = NULL;
244 if ((home = getenv(
"HOME")) == NULL) {
246 home = pwent->pw_dir;
250 if ((dir = getenv(
"TMPDIR")) == NULL) {
253 if (home && home[0] ==
'/') {
258 rc = mkdir(cib_home, 0700);
259 if (rc < 0 && errno != EEXIST) {
260 crm_perror(LOG_ERR,
"Couldn't create user-specific shadow directory: %s",
281 cib_t *new_cib = NULL;
282 char *shadow_file = NULL;
296 unsetenv(
"CIB_shadow");
303 const char *value = getenv(
"CIB_shadow");
305 if (value && value[0] != 0) {
309 value = getenv(
"CIB_file");
314 value = getenv(
"CIB_port");
316 gboolean encrypted = TRUE;
318 const char *server = getenv(
"CIB_server");
319 const char *user = getenv(
"CIB_user");
320 const char *pass = getenv(
"CIB_passwd");
322 value = getenv(
"CIB_encrypted");
330 crm_info(
"Defaulting to user: %s", user);
333 if (server == NULL) {
334 server =
"localhost";
335 crm_info(
"Defaulting to localhost");
356 cib_t *new_cib = NULL;
358 new_cib = calloc(1,
sizeof(
cib_t));
381 new_cib->
cmds->
noop = cib_client_noop;
382 new_cib->
cmds->
ping = cib_client_ping;
384 new_cib->
cmds->
sync = cib_client_sync;
420 while (list != NULL) {
423 list = g_list_remove(list, client);
428 destroy_op_callback_table();
447 int rc, xmlNode * output))
449 if (callback == NULL) {
450 crm_info(
"Un-Setting operation callback");
461 void (*callback) (
const char *event, xmlNode * msg))
463 GList *list_item = NULL;
467 return -EPROTONOSUPPORT;
473 new_client->
event = event;
478 if (list_item != NULL) {
479 crm_warn(
"Callback already present");
494 get_notify_list_event_count(
cib_t * cib,
const char *event)
499 for (l = g_list_first(cib->
notify_list); l; l = g_list_next(l)) {
502 if (strcmp(client->
event, event) == 0) {
506 crm_trace(
"event(%s) count : %d", event, count);
512 void (*callback) (
const char *event, xmlNode * msg))
514 GList *list_item = NULL;
518 return -EPROTONOSUPPORT;
521 if (get_notify_list_event_count(cib, event) == 0) {
522 crm_debug(
"The callback of the event does not exist(%s)", event);
526 crm_debug(
"Removing callback for %s events", event);
529 new_client->
event = event;
534 if (list_item != NULL) {
546 if (get_notify_list_event_count(cib, event) == 0) {
563 rc = strcmp(a_client->
event, b_client->
event);
568 crm_trace(
"callbacks for %s are not equal: %p < %p",
572 crm_trace(
"callbacks for %s are not equal: %p > %p",
580 cib_async_timeout_handler(gpointer data)
595 void *user_data,
const char *callback_name,
596 void (*callback) (xmlNode *,
int,
int, xmlNode *,
void *))
599 only_success, user_data,
600 callback_name, callback, NULL);
605 gboolean only_success,
void *user_data,
606 const char *callback_name,
607 void (*callback)(xmlNode *,
int,
int,
609 void (*free_func)(
void *))
614 if (only_success == FALSE) {
615 callback(NULL, call_id, call_id, NULL, user_data);
619 if (user_data && free_func) {
620 free_func(user_data);
626 blob->
id = callback_name;
635 async_timer = calloc(1,
sizeof(
struct timer_rec_s));
636 blob->
timer = async_timer;
640 async_timer->
timeout = timeout * 1000;
642 g_timeout_add(async_timer->
timeout, cib_async_timeout_handler, async_timer);
645 crm_trace(
"Adding callback %s for call %d", callback_name, call_id);
655 destroy_op_callback_table();
657 NULL, cib_destroy_op_callback);
673 cib_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
675 int call = GPOINTER_TO_INT(key);
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
#define CRM_CHECK(expr, failure_action)
cib_t * cib_shadow_new(const char *name)
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))
int(* set_slave)(cib_t *cib, int call_options)
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 *))
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 *))
const char * pcmk_strerror(int rc)
int cib_client_del_notify_callback(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
void remove_cib_op_callback(int call_id, gboolean all_callbacks)
int crm_parse_int(const char *text, const char *default_text)
int(* noop)(cib_t *cib, int call_options)
int(* set_slave_all)(cib_t *cib, int call_options)
int(* set_op_callback)(cib_t *cib, void(*callback)(const xmlNode *msg, int callid, int rc, xmlNode *output))
int(* replace)(cib_t *cib, const char *section, xmlNode *data, int call_options)
int(* update)(cib_t *cib, const char *section, xmlNode *data, int call_options)
void(* callback)(const char *event, xmlNode *msg)
char * get_shadow_file(const char *name)
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 *))
void cib_delete(cib_t *cib)
Free all memory used by CIB connection.
int(* add_notify_callback)(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
int(* bump_epoch)(cib_t *cib, int call_options)
int(* modify)(cib_t *cib, const char *section, xmlNode *data, int call_options)
cib_t * cib_new_variant(void)
void(* callback)(xmlNode *, int, int, xmlNode *, void *)
#define crm_warn(fmt, args...)
struct timer_rec_s * timer
int(* upgrade)(cib_t *cib, int call_options)
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
void cib_free_callbacks(cib_t *cib)
Free all callbacks for a CIB connection.
int(* ping)(cib_t *cib, xmlNode **output_data, int call_options)
void(* op_callback)(const xmlNode *msg, int call_id, int rc, xmlNode *output)
#define crm_trace(fmt, args...)
int(* register_notification)(cib_t *cib, const char *callback, int enabled)
int(* delete_absolute)(cib_t *cib, const char *section, xmlNode *data, int call_options)
int(* erase)(cib_t *cib, xmlNode **output_data, int call_options)
Wrappers for and extensions to libxml2.
int(* set_master)(cib_t *cib, int call_options)
int(* query_from)(cib_t *cib, const char *host, const char *section, xmlNode **output_data, int call_options)
int(* sync_from)(cib_t *cib, const char *host, const char *section, int call_options)
cib_t * cib_native_new(void)
int num_cib_op_callbacks(void)
int(* sync)(cib_t *cib, const char *section, int call_options)
int(* del_notify_callback)(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
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))
GHashTable * cib_op_callback_table
#define crm_perror(level, fmt, args...)
Log a system error message.
void(* free_func)(void *)
cib_t * cib_new_no_shadow(void)
int(* is_master)(cib_t *cib)
void cib_native_callback(cib_t *cib, xmlNode *msg, int call_id, int rc)
int(* create)(cib_t *cib, const char *section, xmlNode *data, int call_options)
int(* delete)(cib_t *cib, const char *section, xmlNode *data, int call_options)
gboolean crm_is_true(const char *s)
#define CIB_OP_DELETE_ALT
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 *))
char * crm_concat(const char *prefix, const char *suffix, char join)
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_dump_pending_callbacks(void)
#define crm_info(fmt, args...)
gint ciblib_GCompareFunc(gconstpointer a, gconstpointer b)