MCPcopy Create free account
hub / github.com/ClusterLabs/pacemaker / test_attr_expression

Function test_attr_expression

lib/pengine/rules.c:206–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204}
205
206gboolean
207test_attr_expression(xmlNode * expr, GHashTable * hash, crm_time_t * now)
208{
209 gboolean accept = FALSE;
210 int cmp = 0;
211 const char *h_val = NULL;
212
213 const char *op = NULL;
214 const char *type = NULL;
215 const char *attr = NULL;
216 const char *value = NULL;
217
218 attr = crm_element_value(expr, XML_EXPR_ATTR_ATTRIBUTE);
219 op = crm_element_value(expr, XML_EXPR_ATTR_OPERATION);
220 value = crm_element_value(expr, XML_EXPR_ATTR_VALUE);
221 type = crm_element_value(expr, XML_EXPR_ATTR_TYPE);
222
223 if (attr == NULL || op == NULL) {
224 pe_err("Invlaid attribute or operation in expression"
225 " (\'%s\' \'%s\' \'%s\')", crm_str(attr), crm_str(op), crm_str(value));
226 return FALSE;
227 }
228
229 if (hash != NULL) {
230 h_val = (const char *)g_hash_table_lookup(hash, attr);
231 }
232
233 if (value != NULL && h_val != NULL) {
234 if (type == NULL) {
235 if (safe_str_eq(op, "lt")
236 || safe_str_eq(op, "lte")
237 || safe_str_eq(op, "gt")
238 || safe_str_eq(op, "gte")) {
239 type = "number";
240
241 } else {
242 type = "string";
243 }
244 crm_trace("Defaulting to %s based comparison for '%s' op", type, op);
245 }
246
247 if (safe_str_eq(type, "string")) {
248 cmp = strcasecmp(h_val, value);
249
250 } else if (safe_str_eq(type, "number")) {
251 int h_val_f = crm_parse_int(h_val, NULL);
252 int value_f = crm_parse_int(value, NULL);
253
254 if (h_val_f < value_f) {
255 cmp = -1;
256 } else if (h_val_f > value_f) {
257 cmp = 1;
258 } else {
259 cmp = 0;
260 }
261
262 } else if (safe_str_eq(type, "version")) {
263 cmp = compare_version(h_val, value);

Callers 1

test_expressionFunction · 0.85

Calls 3

crm_element_valueFunction · 0.85
crm_parse_intFunction · 0.85
compare_versionFunction · 0.85

Tested by

no test coverage detected