diff options
Diffstat (limited to 'libglusterfs/src/dict.h')
| -rw-r--r-- | libglusterfs/src/dict.h | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index 17e9bcb45..9b41b5a7d 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -45,27 +45,21 @@ typedef struct _data_pair data_pair_t; #define GF_PROTOCOL_DICT_UNSERIALIZE(xl,to,buff,len,ret,ope,labl) do { \ - char *buf = NULL; \ if (!len) \ break; \ to = dict_new(); \ GF_VALIDATE_OR_GOTO (xl->name, to, labl); \ \ - buf = memdup (buff, len); \ - GF_VALIDATE_OR_GOTO (xl->name, buf, labl); \ - \ - ret = dict_unserialize (buf, len, &to); \ + ret = dict_unserialize (buff, len, &to); \ if (ret < 0) { \ gf_log (xl->name, GF_LOG_WARNING, \ "failed to unserialize dictionary (%s)", \ (#to)); \ \ ope = EINVAL; \ - GF_FREE (buf); \ goto labl; \ } \ \ - to->extra_free = buf; \ } while (0) struct _data { @@ -105,7 +99,11 @@ struct _dict { int32_t is_data_equal (data_t *one, data_t *two); void data_destroy (data_t *data); +/* function to set a key/value pair (overwrite existing if matches the key */ int32_t dict_set (dict_t *this, char *key, data_t *value); +/* function to set a new key/value pair (without checking for duplicate) */ +int32_t dict_add (dict_t *this, char *key, data_t *value); + data_t *dict_get (dict_t *this, char *key); void dict_del (dict_t *this, char *key); int dict_reset (dict_t *dict); @@ -122,7 +120,7 @@ dict_t *dict_ref (dict_t *dict); data_t *data_ref (data_t *data); void data_unref (data_t *data); -int32_t dict_lookup (dict_t *this, char *key, data_pair_t **data); +int32_t dict_lookup (dict_t *this, char *key, data_t **data); /* TODO: provide converts for differnt byte sizes, signedness, and void * */ @@ -165,14 +163,26 @@ data_t * data_copy (data_t *old); dict_t *get_new_dict_full (int size_hint); dict_t *get_new_dict (); -void dict_foreach (dict_t *this, - void (*fn)(dict_t *this, - char *key, - data_t *value, - void *data), - void *data); +int dict_foreach (dict_t *this, + int (*fn)(dict_t *this, + char *key, + data_t *value, + void *data), + void *data); + +int dict_foreach_fnmatch (dict_t *dict, char *pattern, + int (*fn)(dict_t *this, + char *key, + data_t *value, + void *data), + void *data); + +int dict_null_foreach_fn (dict_t *d, char *k, + data_t *v, void *tmp); dict_t *dict_copy (dict_t *this, dict_t *new); +int dict_keys_join (void *value, int size, dict_t *dict, + int (*filter_fn)(char *key)); /* CLEANED UP FUNCTIONS DECLARATIONS */ GF_MUST_CHECK dict_t *dict_new (void); @@ -224,5 +234,4 @@ GF_MUST_CHECK int dict_serialize_value_with_delim (dict_t *this, char *buf, int3 char delimiter); void dict_dump (dict_t *dict); - #endif |
