Просмотр исходного кода

icmap: Add func to test equality of two key values

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 12 лет назад
Родитель
Сommit
95133a5d77
2 измененных файлов с 35 добавлено и 0 удалено
  1. 22 0
      exec/icmap.c
  2. 13 0
      include/corosync/icmap.h

+ 22 - 0
exec/icmap.c

@@ -396,6 +396,28 @@ static int icmap_item_eq(const struct icmap_item *item, const void *value, size_
 	return (0);
 	return (0);
 }
 }
 
 
+int icmap_key_value_eq(
+	const icmap_map_t map1,
+	const char *key_name1,
+	const icmap_map_t map2,
+	const char *key_name2)
+{
+	struct icmap_item *item1, *item2;
+
+	if (map1 == NULL || key_name1 == NULL || map2 == NULL || key_name2 == NULL) {
+		return (0);
+	}
+
+	item1 = qb_map_get(map1->qb_map, key_name1);
+	item2 = qb_map_get(map2->qb_map, key_name2);
+
+	if (item1 == NULL || item2 == NULL) {
+		return (0);
+	}
+
+	return (icmap_item_eq(item1, item2->value, item2->value_len, item2->type));
+}
+
 cs_error_t icmap_set_r(
 cs_error_t icmap_set_r(
 	const icmap_map_t map,
 	const icmap_map_t map,
 	const char *key_name,
 	const char *key_name,

+ 13 - 0
include/corosync/icmap.h

@@ -151,6 +151,19 @@ extern void icmap_fini_r(const icmap_map_t map);
  */
  */
 extern icmap_map_t icmap_get_global_map(void);
 extern icmap_map_t icmap_get_global_map(void);
 
 
+/*
+ * Compare value of key with name key_name1 in map1 with key with name key_name2
+ * in map2. Two values must have same type, length and value to be considered equal.
+ * Function returns 0 when any of map1, key_name1, map2, key_name2 are NULL, or
+ * key_name is not found in map, or keys are not equal. != 0 is returned when
+ * values are equal.
+ */
+extern int icmap_key_value_eq(
+	const icmap_map_t map1,
+	const char *key_name1,
+	const icmap_map_t map2,
+	const char *key_name2);
+
 /*
 /*
  * Store value with value_len length and type as key_name name in global icmap.
  * Store value with value_len length and type as key_name name in global icmap.
  */
  */