#include <corosync/corotypes.h>
#include <qb/qbdefs.h>
-#include <corosync/list.h>
+#include <qb/qblist.h>
#include <corosync/icmap.h>
#define ICMAP_MAX_VALUE_LEN (16*1024)
int32_t track_type;
icmap_notify_fn_t notify_fn;
void *user_data;
- struct list_head list;
+ struct qb_list_head list;
};
struct icmap_ro_access_item {
char *key_name;
int prefix;
- struct list_head list;
+ struct qb_list_head list;
};
-DECLARE_LIST_INIT(icmap_ro_access_item_list_head);
-DECLARE_LIST_INIT(icmap_track_list_head);
+QB_LIST_DECLARE (icmap_ro_access_item_list_head);
+QB_LIST_DECLARE (icmap_track_list_head);
/*
* Static functions declarations
*/
static int icmap_check_value_len(const void *value, size_t value_len, icmap_value_types_t type);
-/*
- * Returns length of value of given type, or 0 for string and binary data type
- */
-static size_t icmap_get_valuetype_len(icmap_value_types_t type);
-
-/*
- * Converts track type of icmap to qb
- */
-static int32_t icmap_tt_to_qbtt(int32_t track_type);
-
-/*
- * Convert track type of qb to icmap
- */
-static int32_t icmap_qbtt_to_tt(int32_t track_type);
-
/*
* Checks if item has same value as value with value_len and given type. Returns 0 if not, otherwise !0.
*/
/*
* Function implementation
*/
-static int32_t icmap_tt_to_qbtt(int32_t track_type)
+int32_t icmap_tt_to_qbtt(int32_t track_type)
{
int32_t res = 0;
return (res);
}
-static int32_t icmap_qbtt_to_tt(int32_t track_type)
+int32_t icmap_qbtt_to_tt(int32_t track_type)
{
int32_t res = 0;
}
(*result)->qb_map = qb_trie_create();
- if ((*result)->qb_map == NULL)
+ if ((*result)->qb_map == NULL) {
+ free(*result);
return (CS_ERR_INIT);
+ }
err = qb_map_notify_add((*result)->qb_map, NULL, icmap_map_free_cb, QB_MAP_NOTIFY_FREE, NULL);
static void icmap_set_ro_access_free(void)
{
- struct list_head *iter = icmap_ro_access_item_list_head.next;
+ struct qb_list_head *iter, *tmp_iter;
struct icmap_ro_access_item *icmap_ro_ai;
- while (iter != &icmap_ro_access_item_list_head) {
- icmap_ro_ai = list_entry(iter, struct icmap_ro_access_item, list);
- list_del(&icmap_ro_ai->list);
+ qb_list_for_each_safe(iter, tmp_iter, &icmap_ro_access_item_list_head) {
+ icmap_ro_ai = qb_list_entry(iter, struct icmap_ro_access_item, list);
+ qb_list_del(&icmap_ro_ai->list);
free(icmap_ro_ai->key_name);
free(icmap_ro_ai);
- iter = icmap_ro_access_item_list_head.next;
}
}
static void icmap_del_all_track(void)
{
- struct list_head *iter = icmap_track_list_head.next;
+ struct qb_list_head *iter, *tmp_iter;
struct icmap_track *icmap_track;
- while (iter != &icmap_track_list_head) {
- icmap_track = list_entry(iter, struct icmap_track, list);
+ qb_list_for_each_safe(iter, tmp_iter, &icmap_track_list_head) {
+ icmap_track = qb_list_entry(iter, struct icmap_track, list);
+
icmap_track_delete(icmap_track);
- iter = icmap_track_list_head.next;
}
}
return (0);
}
-static size_t icmap_get_valuetype_len(icmap_value_types_t type)
+size_t icmap_get_valuetype_len(icmap_value_types_t type)
{
size_t res = 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(
const icmap_map_t map,
const char *key_name,
return (icmap_get_r(icmap_global_map, key_name, value, value_len, type));
}
+cs_error_t icmap_get_string_r(icmap_map_t map, const char *key_name, char **str)
+{
+ cs_error_t res;
+ size_t str_len;
+ icmap_value_types_t type;
+
+ res = icmap_get_r(map, key_name, NULL, &str_len, &type);
+ if (res != CS_OK || type != ICMAP_VALUETYPE_STRING) {
+ if (res == CS_OK) {
+ res = CS_ERR_INVALID_PARAM;
+ }
+
+ goto return_error;
+ }
+
+ *str = malloc(str_len);
+ if (*str == NULL) {
+ res = CS_ERR_NO_MEMORY;
+
+ goto return_error;
+ }
+
+ res = icmap_get_r(map, key_name, *str, &str_len, &type);
+ if (res != CS_OK) {
+ free(*str);
+ goto return_error;
+ }
+
+ return (CS_OK);
+
+return_error:
+ return (res);
+}
+
static cs_error_t icmap_get_int_r(
const icmap_map_t map,
const char *key_name,
key_size = sizeof(key_value);
memset(key_value, 0, key_size);
- err = icmap_get(key_name, key_value, &key_size, &key_type);
+ err = icmap_get_r(map, key_name, key_value, &key_size, &key_type);
if (err != CS_OK)
return (err);
return (icmap_get_int_r(map, key_name, dbl, ICMAP_VALUETYPE_DOUBLE));
}
+cs_error_t icmap_get_string(const char *key_name, char **str)
+{
+
+ return (icmap_get_string_r(icmap_global_map, key_name, str));
+}
+
cs_error_t icmap_get_int8(const char *key_name, int8_t *i8)
{
return (icmap_get_double_r(icmap_global_map, key_name, dbl));
}
-cs_error_t icmap_get_string(const char *key_name, char **str)
-{
- cs_error_t res;
- size_t str_len;
- icmap_value_types_t type;
-
- res = icmap_get(key_name, NULL, &str_len, &type);
- if (res != CS_OK || type != ICMAP_VALUETYPE_STRING) {
- if (res == CS_OK) {
- res = CS_ERR_INVALID_PARAM;
- }
-
- goto return_error;
- }
-
- *str = malloc(str_len);
- if (*str == NULL) {
- res = CS_ERR_NO_MEMORY;
-
- goto return_error;
- }
-
- res = icmap_get(key_name, *str, &str_len, &type);
- if (res != CS_OK) {
- free(*str);
- goto return_error;
- }
-
- return (CS_OK);
-
-return_error:
- return (res);
-}
-
cs_error_t icmap_adjust_int_r(
const icmap_map_t map,
const char *key_name,
return (qb_to_cs_error(err));
}
- list_init(&(*icmap_track)->list);
- list_add (&(*icmap_track)->list, &icmap_track_list_head);
+ qb_list_init(&(*icmap_track)->list);
+ qb_list_add (&(*icmap_track)->list, &icmap_track_list_head);
return (CS_OK);
}
return (qb_to_cs_error(err));
}
- list_del(&icmap_track->list);
+ qb_list_del(&icmap_track->list);
free(icmap_track->key_name);
free(icmap_track);
cs_error_t icmap_set_ro_access(const char *key_name, int prefix, int ro_access)
{
- struct list_head *iter;
+ struct qb_list_head *iter, *tmp_iter;
struct icmap_ro_access_item *icmap_ro_ai;
- for (iter = icmap_ro_access_item_list_head.next; iter != &icmap_ro_access_item_list_head; iter = iter->next) {
- icmap_ro_ai = list_entry(iter, struct icmap_ro_access_item, list);
+ qb_list_for_each_safe(iter, tmp_iter, &icmap_ro_access_item_list_head) {
+ icmap_ro_ai = qb_list_entry(iter, struct icmap_ro_access_item, list);
if (icmap_ro_ai->prefix == prefix && strcmp(key_name, icmap_ro_ai->key_name) == 0) {
/*
if (ro_access) {
return (CS_ERR_EXIST);
} else {
- list_del(&icmap_ro_ai->list);
+ qb_list_del(&icmap_ro_ai->list);
free(icmap_ro_ai->key_name);
free(icmap_ro_ai);
}
icmap_ro_ai->prefix = prefix;
- list_init(&icmap_ro_ai->list);
- list_add (&icmap_ro_ai->list, &icmap_ro_access_item_list_head);
+ qb_list_init(&icmap_ro_ai->list);
+ qb_list_add (&icmap_ro_ai->list, &icmap_ro_access_item_list_head);
return (CS_OK);
}
int icmap_is_key_ro(const char *key_name)
{
- struct list_head *iter;
+ struct qb_list_head *iter;
struct icmap_ro_access_item *icmap_ro_ai;
- for (iter = icmap_ro_access_item_list_head.next; iter != &icmap_ro_access_item_list_head; iter = iter->next) {
- icmap_ro_ai = list_entry(iter, struct icmap_ro_access_item, list);
+ qb_list_for_each(iter, &icmap_ro_access_item_list_head) {
+ icmap_ro_ai = qb_list_entry(iter, struct icmap_ro_access_item, list);
if (icmap_ro_ai->prefix) {
if (strlen(icmap_ro_ai->key_name) > strlen(key_name))
return (CS_FALSE);
}
+
+cs_error_t icmap_copy_map(icmap_map_t dst_map, const icmap_map_t src_map)
+{
+ icmap_iter_t iter;
+ size_t value_len;
+ icmap_value_types_t value_type;
+ const char *key_name;
+ cs_error_t err;
+ void *value;
+
+ iter = icmap_iter_init_r(src_map, NULL);
+ if (iter == NULL) {
+ return (CS_ERR_NO_MEMORY);
+ }
+
+ err = CS_OK;
+
+ while ((key_name = icmap_iter_next(iter, &value_len, &value_type)) != NULL) {
+ err = icmap_get_ref_r(src_map, key_name, &value, &value_len, &value_type);
+ if (err != CS_OK) {
+ goto exit_iter_finalize;
+ }
+
+ err = icmap_set_r(dst_map, key_name, value, value_len, value_type);
+ if (err != CS_OK) {
+ goto exit_iter_finalize;
+ }
+ }
+
+exit_iter_finalize:
+ icmap_iter_finalize(iter);
+
+ return (err);
+}