diff options
Diffstat (limited to 'libglusterfs/src/dict.h')
| -rw-r--r-- | libglusterfs/src/dict.h | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index 2a8750396..9b41b5a7d 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -29,13 +29,11 @@ typedef struct _data_pair data_pair_t; #define GF_PROTOCOL_DICT_SERIALIZE(this,from_dict,to,len,ope,labl) do { \ int ret = 0; \ - size_t dictlen = 0; \ \ if (!from_dict) \ break; \ \ - ret = dict_allocate_and_serialize (from_dict, to, \ - &dictlen); \ + ret = dict_allocate_and_serialize (from_dict, to, &len);\ if (ret < 0) { \ gf_log (this->name, GF_LOG_WARNING, \ "failed to get serialized dict (%s)", \ @@ -43,32 +41,25 @@ typedef struct _data_pair data_pair_t; ope = EINVAL; \ goto labl; \ } \ - len = dictlen; \ } while (0) #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 { @@ -108,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); @@ -117,7 +112,7 @@ int32_t dict_serialized_length (dict_t *dict); int32_t dict_serialize (dict_t *dict, char *buf); int32_t dict_unserialize (char *buf, int32_t size, dict_t **fill); -int32_t dict_allocate_and_serialize (dict_t *this, char **buf, size_t *length); +int32_t dict_allocate_and_serialize (dict_t *this, char **buf, u_int *length); void dict_destroy (dict_t *dict); void dict_unref (dict_t *dict); @@ -125,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 * */ @@ -168,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); @@ -227,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 |
