diff options
Diffstat (limited to 'libglusterfs/src/dict.h')
| -rw-r--r-- | libglusterfs/src/dict.h | 77 |
1 files changed, 37 insertions, 40 deletions
diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index 8e81e539b..9b41b5a7d 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -1,20 +1,11 @@ /* - Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ #ifndef _DICT_H @@ -38,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)", \ @@ -52,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 { @@ -85,7 +67,6 @@ struct _data { unsigned char is_const:1; unsigned char is_stdalloc:1; int32_t len; - struct iovec *vec; char *data; int32_t refcount; gf_lock_t lock; @@ -109,13 +90,20 @@ struct _dict { char *extra_free; char *extra_stdfree; gf_lock_t lock; + data_pair_t *members_internal; + data_pair_t free_pair; + gf_boolean_t free_pair_in_use; }; 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); @@ -124,10 +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_iovec_len (dict_t *dict); -int32_t dict_to_iovec (dict_t *dict, struct iovec *vec, int32_t count); +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); @@ -135,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 * */ @@ -178,16 +163,26 @@ data_t * data_copy (data_t *old); dict_t *get_new_dict_full (int size_hint); dict_t *get_new_dict (); -data_pair_t *get_new_data_pair (); +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); -void dict_foreach (dict_t *this, - void (*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); @@ -237,4 +232,6 @@ GF_MUST_CHECK int dict_get_str (dict_t *this, char *key, char **str); GF_MUST_CHECK int dict_get_str_boolean (dict_t *this, char *key, int default_val); GF_MUST_CHECK int dict_serialize_value_with_delim (dict_t *this, char *buf, int32_t *serz_len, char delimiter); + +void dict_dump (dict_t *dict); #endif |
