diff options
Diffstat (limited to 'libglusterfs/src')
| -rw-r--r-- | libglusterfs/src/common-utils.h | 11 | ||||
| -rw-r--r-- | libglusterfs/src/dict.c | 46 | ||||
| -rw-r--r-- | libglusterfs/src/dict.h | 5 | 
3 files changed, 54 insertions, 8 deletions
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 75692309e14..d9d3082c0fc 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -172,7 +172,6 @@ void gf_print_trace (int32_t signal, glusterfs_ctx_t *ctx);                  }                                                       \          } while (0) -  #define GF_IF_INTERNAL_XATTR_GOTO(pattern, dict, op_errno, label)       \          do {                                                            \                  if (!dict) {                                            \ @@ -180,13 +179,9 @@ void gf_print_trace (int32_t signal, glusterfs_ctx_t *ctx);                                  "setxattr dict is null");               \                          goto label;                                     \                  }                                                       \ -                int _handle_keyvalue_pair (dict_t *d, char *k,          \ -                                           data_t *v, void *tmp)        \ -                {                                                       \ -                        return 0;                                       \ -                }                                                       \ -                if (dict_foreach_fnmatch (dict, pattern,                  \ -                                          _handle_keyvalue_pair, NULL) > 0) { \ +                if (dict_foreach_fnmatch (dict, pattern,                \ +                                          dict_null_foreach_fn,         \ +                                          NULL) > 0) {                  \                          op_errno = EPERM;                               \                          gf_log (this->name, GF_LOG_ERROR,               \                                  "attempt to set internal"               \ diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index e9b8da1c4e9..a8cdeaf28f8 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -1079,6 +1079,13 @@ data_to_bin (data_t *data)  }  int +dict_null_foreach_fn (dict_t *d, char *k, +                      data_t *v, void *tmp) +{ +        return 0; +} + +int  dict_foreach (dict_t *dict,                int (*fn)(dict_t *this,                          char *key, @@ -1148,6 +1155,45 @@ dict_foreach_fnmatch (dict_t *dict, char *pattern,  } +/** + * dict_keys_join - pack the keys of the dictionary in a buffer. + * + * @value     : buffer in which the keys will be packed (can be NULL) + * @size      : size of the buffer which is sent (can be 0, in which case buffer + *              is not packed but only length is returned) + * @dict      : dictionary of which all the keys will be packed + * @filter_fn : keys matched in filter_fn() is counted. + * + * @return : @length of string after joining keys. + * + */ + +int +dict_keys_join (void *value, int size, dict_t *dict, +                int (*filter_fn)(char *k)) +{ +	int          len = 0; +        data_pair_t *pairs = NULL; +        data_pair_t *next  = NULL; + +        pairs = dict->members_list; +        while (pairs) { +                next = pairs->next; + +                if (filter_fn && filter_fn (pairs->key)) +                        continue; + +		if (value && (size > len)) +			strncpy (value + len, pairs->key, size - len); + +                len += (strlen (pairs->key) + 1); + +                pairs = next; +        } + +	return len; +} +  static int  _copy (dict_t *unused,         char *key, diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index dbf98046f4f..c7606352cc1 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -177,7 +177,12 @@ int dict_foreach_fnmatch (dict_t *dict, char *pattern,                                      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);  | 
