19 #include <sys/types.h>
31 int rc, xmlNode * output));
34 void (*callback) (
const char *event, xmlNode * msg));
37 void (*callback) (
const char *event, xmlNode * msg));
41 #define op_common(cib) do { \
44 } else if(cib->delegate_fn == NULL) { \
45 return -EPROTONOSUPPORT; \
50 cib_client_noop(
cib_t * cib,
int call_options)
57 cib_client_ping(
cib_t * cib, xmlNode ** output_data,
int call_options)
64 cib_client_query(
cib_t * cib,
const char *section, xmlNode ** output_data,
int call_options)
66 return cib->
cmds->
query_from(cib, NULL, section, output_data, call_options);
70 cib_client_query_from(
cib_t * cib,
const char *
host,
const char *section,
71 xmlNode ** output_data,
int call_options)
78 cib_client_is_master(
cib_t * cib)
86 cib_client_set_slave(
cib_t * cib,
int call_options)
93 cib_client_set_slave_all(
cib_t * cib,
int call_options)
95 return -EPROTONOSUPPORT;
99 cib_client_set_master(
cib_t * cib,
int call_options)
102 crm_trace(
"Adding cib_scope_local to options");
108 cib_client_bump_epoch(
cib_t * cib,
int call_options)
115 cib_client_upgrade(
cib_t * cib,
int call_options)
122 cib_client_sync(
cib_t * cib,
const char *section,
int call_options)
124 return cib->
cmds->
sync_from(cib, NULL, section, call_options);
128 cib_client_sync_from(
cib_t * cib,
const char *
host,
const char *section,
int call_options)
135 cib_client_create(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
142 cib_client_modify(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
149 cib_client_update(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
156 cib_client_replace(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
163 cib_client_delete(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
170 cib_client_delete_absolute(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
177 cib_client_erase(
cib_t * cib, xmlNode ** output_data,
int call_options)
184 cib_destroy_op_callback(gpointer
data)
201 destroy_op_callback_table(
void)
212 char *cib_home = NULL;
213 char *fullname = NULL;
215 const char *dir = getenv(
"CIB_shadow_dir");
218 uid_t uid = geteuid();
219 struct passwd *pwent = getpwuid(uid);
220 const char *user = NULL;
223 user = pwent->pw_name;
225 user = getenv(
"USER");
227 "Assuming %s because cannot get user details for user ID %d",
228 (user? user :
"unprivileged user"), uid);
235 const char *home = NULL;
237 if ((home = getenv(
"HOME")) == NULL) {
239 home = pwent->pw_dir;
244 if (home && home[0] ==
'/') {
249 rc = mkdir(cib_home, 0700);
250 if (rc < 0 && errno != EEXIST) {
251 crm_perror(LOG_ERR,
"Couldn't create user-specific shadow directory: %s",
272 cib_t *new_cib = NULL;
273 char *shadow_file = NULL;
287 unsetenv(
"CIB_shadow");
294 const char *value = getenv(
"CIB_shadow");
297 if (value && value[0] != 0) {
301 value = getenv(
"CIB_file");
306 value = getenv(
"CIB_port");
308 gboolean encrypted = TRUE;
309 const char *server = getenv(
"CIB_server");
310 const char *user = getenv(
"CIB_user");
311 const char *pass = getenv(
"CIB_passwd");
320 value = getenv(
"CIB_encrypted");
328 crm_info(
"Defaulting to user: %s", user);
331 if (server == NULL) {
332 server =
"localhost";
333 crm_info(
"Defaulting to localhost");
354 cib_t *new_cib = NULL;
356 new_cib = calloc(1,
sizeof(
cib_t));
379 new_cib->
cmds->
noop = cib_client_noop;
380 new_cib->
cmds->
ping = cib_client_ping;
382 new_cib->
cmds->
sync = cib_client_sync;
414 while (list != NULL) {
417 list = g_list_remove(list, client);
433 destroy_op_callback_table();
452 int rc, xmlNode * output))
454 if (callback == NULL) {
455 crm_info(
"Un-Setting operation callback");
466 void (*callback) (
const char *event, xmlNode * msg))
468 GList *list_item = NULL;
472 return -EPROTONOSUPPORT;
478 new_client->
event = event;
483 if (list_item != NULL) {
484 crm_warn(
"Callback already present");
499 get_notify_list_event_count(
cib_t * cib,
const char *event)
504 for (l = g_list_first(cib->
notify_list); l; l = g_list_next(l)) {
507 if (strcmp(client->
event, event) == 0) {
511 crm_trace(
"event(%s) count : %d", event, count);
517 void (*callback) (
const char *event, xmlNode * msg))
519 GList *list_item = NULL;
523 return -EPROTONOSUPPORT;
526 if (get_notify_list_event_count(cib, event) == 0) {
527 crm_debug(
"The callback of the event does not exist(%s)", event);
531 crm_debug(
"Removing callback for %s events", event);
534 new_client->
event = event;
539 if (list_item != NULL) {
551 if (get_notify_list_event_count(cib, event) == 0) {
568 rc = strcmp(a_client->
event, b_client->
event);
573 crm_trace(
"callbacks for %s are not equal: %p < %p",
577 crm_trace(
"callbacks for %s are not equal: %p > %p",
585 cib_async_timeout_handler(gpointer data)
600 void *user_data,
const char *callback_name,
601 void (*callback) (xmlNode *,
int,
int, xmlNode *,
void *))
604 only_success, user_data,
605 callback_name, callback, NULL);
610 gboolean only_success,
void *user_data,
611 const char *callback_name,
612 void (*callback)(xmlNode *,
int,
int,
614 void (*free_func)(
void *))
619 if (only_success == FALSE) {
620 callback(NULL, call_id, call_id, NULL, user_data);
624 if (user_data && free_func) {
625 free_func(user_data);
631 blob->
id = callback_name;
640 async_timer = calloc(1,
sizeof(
struct timer_rec_s));
641 blob->
timer = async_timer;
645 async_timer->
timeout = timeout * 1000;
647 g_timeout_add(async_timer->
timeout, cib_async_timeout_handler, async_timer);
650 crm_trace(
"Adding callback %s for call %d", callback_name, call_id);
660 destroy_op_callback_table();
677 cib_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
679 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)
const char * pcmk_strerror(int rc)
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 *))
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
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 *))
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(* noop)(cib_t *cib, int call_options)
int(* set_slave_all)(cib_t *cib, int call_options)
void cib_free_notify(cib_t *cib)
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)
void cib_delete(cib_t *cib)
Free all memory used by CIB connection.
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)
int pcmk__scan_port(const char *text, int *port)
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)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
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(* add_notify_callback)(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
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(* remove)(cib_t *cib, const char *section, xmlNode *data, int call_options)
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_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...)
Send a system error message to both the log and stderr.
const char * pcmk__get_tmpdir(void)
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)
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 *))
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)
void cib_dump_pending_callbacks(void)
#define crm_info(fmt, args...)
int(* set_op_callback)(cib_t *cib, void(*callback)(const xmlNode *msg, int callid, int rc, xmlNode *output))
gint ciblib_GCompareFunc(gconstpointer a, gconstpointer b)
int(* del_notify_callback)(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))