41 gboolean ruleset_default = TRUE;
44 for (rule = __xml_first_child(ruleset); rule != NULL; rule = __xml_next_element(rule)) {
46 ruleset_default = FALSE;
53 return ruleset_default;
61 gboolean empty = TRUE;
62 gboolean passed = TRUE;
63 gboolean do_and = TRUE;
64 const char *value = NULL;
74 for (expr = __xml_first_child(rule); expr != NULL; expr = __xml_next_element(expr)) {
78 if (test && do_and == FALSE) {
82 }
else if (test == FALSE && do_and) {
89 crm_err(
"Invalid Rule %s: rules must contain at least one expression",
ID(rule));
92 crm_trace(
"Rule %s %s",
ID(rule), passed ?
"passed" :
"failed");
99 gboolean accept = FALSE;
100 const char *
uname = NULL;
104 accept =
test_rule(expr, node_hash, role, now);
111 if (node_hash != NULL) {
129 uname = g_hash_table_lookup(node_hash,
"#uname");
133 ID(expr), accept ?
"passed" :
"failed", uname ? uname :
"all ndoes");
140 const char *tag = NULL;
141 const char *attr = NULL;
144 tag = crm_element_name(expr);
168 gboolean accept = FALSE;
169 const char *op = NULL;
170 const char *value = NULL;
209 gboolean accept = FALSE;
211 const char *h_val = NULL;
213 const char *op = NULL;
214 const char *
type = NULL;
215 const char *attr = NULL;
216 const char *value = NULL;
223 if (attr == NULL || op == NULL) {
224 pe_err(
"Invlaid attribute or operation in expression"
230 h_val = (
const char *)g_hash_table_lookup(hash, attr);
233 if (value != NULL && h_val != NULL) {
244 crm_trace(
"Defaulting to %s based comparison for '%s' op", type, op);
248 cmp = strcasecmp(h_val, value);
254 if (h_val_f < value_f) {
256 }
else if (h_val_f > value_f) {
267 }
else if (value == NULL && h_val == NULL) {
269 }
else if (value == NULL) {
286 if ((h_val == value) || cmp == 0) {
291 if ((h_val == NULL && value != NULL)
292 || (h_val != NULL && value == NULL)
297 }
else if (value == NULL || h_val == NULL) {
350 goldn = (y % 19) + 1;
351 epact = (11 * goldn + 18) % 30;
352 if ((epact == 25 && goldn > 11) || epact == 24)
355 return ((((((diy + epact) * 6) + 11) % 177) / 22) & 7);
359 decodeNVpair(
const char *srcstring,
char separator,
char **name,
char **value)
363 const char *temp = NULL;
369 crm_trace(
"Attempting to decode: [%s]", srcstring);
370 if (srcstring != NULL) {
371 len = strlen(srcstring);
373 if (srcstring[lpc] == separator) {
374 *name = calloc(1, lpc + 1);
378 memcpy(*name, srcstring, lpc);
390 *value = calloc(1, len + 1);
391 if (*value == NULL) {
394 temp = srcstring + lpc + 1;
395 memcpy(*value, temp, len);
396 (*value)[len] =
'\0';
414 #define cron_check(xml_field, time_field) \
415 value = crm_element_value(cron_spec, xml_field); \
416 if(value != NULL) { \
417 gboolean pass = TRUE; \
418 decodeNVpair(value, '-', &value_low, &value_high); \
419 if(value_low == NULL) { \
420 value_low = strdup(value); \
422 value_low_i = crm_parse_int(value_low, "0"); \
423 value_high_i = crm_parse_int(value_high, "-1"); \
424 if(value_high_i < 0) { \
425 if(value_low_i != time_field) { \
428 } else if(value_low_i > time_field) { \
430 } else if(value_high_i < time_field) { \
435 if(pass == FALSE) { \
436 crm_debug("Condition '%s' in %s: failed", value, xml_field); \
439 crm_debug("Condition '%s' in %s: passed", value, xml_field); \
445 const char *value = NULL;
446 char *value_low = NULL;
447 char *value_high = NULL;
450 int value_high_i = 0;
483 #define update_field(xml_field, time_fn) \
484 value = crm_element_value(duration_spec, xml_field); \
485 if(value != NULL) { \
486 int value_i = crm_parse_int(value, "0"); \
487 time_fn(end, value_i); \
494 const char *value = NULL;
515 const char *value = NULL;
518 xmlNode *duration_spec = NULL;
519 xmlNode *date_spec = NULL;
521 gboolean passed = FALSE;
523 crm_trace(
"Testing expression: %s",
ID(time_expr));
537 if (start != NULL && end == NULL && duration_spec != NULL) {
573 typedef struct sorted_set_s {
576 const char *special_name;
581 sort_pairs(gconstpointer a, gconstpointer b)
586 if (a == NULL && b == NULL) {
588 }
else if (a == NULL) {
590 }
else if (b == NULL) {
594 if (
safe_str_eq(pair_a->name, pair_a->special_name)) {
597 }
else if (
safe_str_eq(pair_b->name, pair_a->special_name)) {
601 if (pair_a->score < pair_b->score) {
603 }
else if (pair_a->score > pair_b->score) {
610 populate_hash(xmlNode * nvpair_list, GHashTable * hash, gboolean overwrite, xmlNode * top)
612 const char *name = NULL;
613 const char *value = NULL;
614 const char *old_value = NULL;
615 xmlNode *list = nvpair_list;
616 xmlNode *an_attr = NULL;
618 name = crm_element_name(list->children);
620 list = list->children;
623 for (an_attr = __xml_first_child(list); an_attr != NULL; an_attr = __xml_next_element(an_attr)) {
632 crm_trace(
"Setting attribute: %s", name);
638 if (name == NULL || value == NULL) {
643 old_value = g_hash_table_lookup(hash, name);
647 crm_trace(
"Removing value for %s (%s)", name, value);
648 g_hash_table_remove(hash, name);
652 }
else if (old_value == NULL) {
653 g_hash_table_insert(hash, strdup(name), strdup(value));
655 }
else if (overwrite) {
656 crm_debug(
"Overwriting value of %s: %s -> %s", name, old_value, value);
657 g_hash_table_replace(hash, strdup(name), strdup(value));
663 struct unpack_data_s {
665 GHashTable *node_hash;
672 unpack_attr_set(gpointer
data, gpointer user_data)
675 struct unpack_data_s *unpack_data = user_data;
677 if (
test_ruleset(pair->attr_set, unpack_data->node_hash, unpack_data->now) == FALSE) {
681 crm_trace(
"Adding attributes from %s", pair->name);
682 populate_hash(pair->attr_set, unpack_data->hash, unpack_data->overwrite, unpack_data->top);
687 GHashTable * node_hash, GHashTable * hash,
const char *always_first,
692 const char *score = NULL;
694 struct unpack_data_s data;
695 xmlNode *attr_set = NULL;
697 if (xml_obj == NULL) {
703 for (attr_set = __xml_first_child(xml_obj); attr_set != NULL; attr_set = __xml_next_element(attr_set)) {
705 if (set_name == NULL ||
crm_str_eq((
const char *)attr_set->name, set_name, TRUE)) {
708 if (attr_set == NULL) {
713 pair->name =
ID(attr_set);
714 pair->special_name = always_first;
715 pair->attr_set = attr_set;
720 unsorted = g_list_prepend(unsorted, pair);
726 data.node_hash = node_hash;
728 data.overwrite = overwrite;
733 sorted = g_list_sort(unsorted, sort_pairs);
734 g_list_foreach(sorted, unpack_attr_set, &data);
735 g_list_free_full(sorted, free);
#define CRM_CHECK(expr, failure_action)
void crm_time_add_years(crm_time_t *dt, int value)
#define cron_check(xml_field, time_field)
void crm_time_add_seconds(crm_time_t *dt, int value)
gboolean safe_str_neq(const char *a, const char *b)
#define XML_EXPR_ATTR_TYPE
struct crm_time_s crm_time_t
gboolean test_expression(xmlNode *expr, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now)
#define XML_RULE_ATTR_SCORE
int char2score(const char *score)
int crm_parse_int(const char *text, const char *default_text)
int crm_time_get_ordinal(crm_time_t *dt, uint32_t *y, uint32_t *d)
#define XML_NVPAIR_ATTR_NAME
gboolean test_attr_expression(xmlNode *expr, GHashTable *hash, crm_time_t *now)
#define XML_CIB_TAG_NVPAIR
void crm_time_add_hours(crm_time_t *dt, int value)
gboolean cron_range_satisfied(crm_time_t *now, xmlNode *cron_spec)
#define crm_debug(fmt, args...)
void crm_time_add_weeks(crm_time_t *dt, int value)
#define XML_EXPR_ATTR_VALUE
void crm_time_add_months(crm_time_t *dt, int value)
#define crm_trace(fmt, args...)
xmlNode * expand_idref(xmlNode *input, xmlNode *top)
Wrappers for and extensions to libxml2.
const char * crm_element_value(xmlNode *data, const char *name)
gboolean test_date_expression(xmlNode *time_expr, crm_time_t *now)
void crm_time_add_minutes(crm_time_t *dt, int value)
#define XML_EXPR_ATTR_OPERATION
crm_time_t * parse_xml_duration(crm_time_t *start, xmlNode *duration_spec)
enum rsc_role_e text2role(const char *role)
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
#define XML_RULE_ATTR_BOOLEAN_OP
gboolean test_rule(xmlNode *rule, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now)
void populate_hash(xmlNode *nvpair_list, GHashTable *hash, const char **attrs, int attrs_length)
CRM_TRACE_INIT_DATA(pe_rules)
struct sorted_set_s sorted_set_t
int crm_time_get_gregorian(crm_time_t *dt, uint32_t *y, uint32_t *m, uint32_t *d)
#define crm_err(fmt, args...)
int crm_time_get_timeofday(crm_time_t *dt, uint32_t *h, uint32_t *m, uint32_t *s)
gboolean test_ruleset(xmlNode *ruleset, GHashTable *node_hash, crm_time_t *now)
void crm_time_set(crm_time_t *target, crm_time_t *source)
crm_time_t * crm_time_new(const char *string)
int compare_version(const char *version1, const char *version2)
#define XML_NVPAIR_ATTR_VALUE
int crm_time_compare(crm_time_t *dt, crm_time_t *rhs)
gboolean test_role_expression(xmlNode *expr, enum rsc_role_e role, crm_time_t *now)
xmlNode * first_named_child(xmlNode *parent, const char *name)
void unpack_instance_attributes(xmlNode *top, xmlNode *xml_obj, const char *set_name, GHashTable *node_hash, GHashTable *hash, const char *always_first, gboolean overwrite, crm_time_t *now)
#define safe_str_eq(a, b)
enum expression_type find_expression_type(xmlNode *expr)
int crm_time_get_isoweek(crm_time_t *dt, uint32_t *y, uint32_t *w, uint32_t *d)
#define XML_EXPR_ATTR_ATTRIBUTE
void crm_time_add_days(crm_time_t *dt, int value)
#define update_field(xml_field, time_fn)
enum crm_ais_msg_types type
void crm_time_free(crm_time_t *dt)