summaryrefslogtreecommitdiffstats
path: root/xlators/protocol/legacy/client/src/client-protocol.h
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/protocol/legacy/client/src/client-protocol.h')
-rw-r--r--xlators/protocol/legacy/client/src/client-protocol.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/xlators/protocol/legacy/client/src/client-protocol.h b/xlators/protocol/legacy/client/src/client-protocol.h
index 81c5a2520..029b43c9f 100644
--- a/xlators/protocol/legacy/client/src/client-protocol.h
+++ b/xlators/protocol/legacy/client/src/client-protocol.h
@@ -3,16 +3,16 @@
This file is part of GlusterFS.
GlusterFS is free software; you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
+ 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
- Affero General Public License for more details.
+ General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
+ You should have received a copy of the GNU General Public License
along with this program. If not, see
<http://www.gnu.org/licenses/>.
*/
* in such case avoid hash calculation. */ if (this->hash_size != 1) hashval = SuperFastHash (key, strlen (key)) % this->hash_size; data_pair_t *pair; for (pair = this->members[hashval]; pair != NULL; pair = pair->hash_next) { if (pair->key && !strcmp (pair->key, key)) return pair; } return NULL; } int32_t dict_lookup (dict_t *this, char *key, data_t **data) { if (!this || !key || !data) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "!this || !key || " "!data"); return -1; } data_pair_t *tmp = NULL; LOCK (&this->lock); { tmp = _dict_lookup (this, key); } UNLOCK (&this->lock); if (!tmp) return -1; *data = tmp->value; return 0; } static int32_t _dict_set (dict_t *this, char *key, data_t *value, gf_boolean_t replace) { int hashval = 0; data_pair_t *pair; char key_free = 0; int tmp = 0; int ret = 0; if (!key) { ret = gf_asprintf (&key, "ref:%p", value); if (-1 == ret) { return -1; } key_free = 1; } /* If the divisor is 1, the modulo is always 0, * in such case avoid hash calculation. */ if (this->hash_size != 1) { tmp = SuperFastHash (key, strlen (key)); hashval = (tmp % this->hash_size); } /* Search for a existing key if 'replace' is asked for */ if (replace) { pair = _dict_lookup (this, key); if (pair) { data_t *unref_data = pair->value; pair->value = data_ref (value); data_unref (unref_data); if (key_free) GF_FREE (key); /* Indicates duplicate key */ return 0; } } if (this->free_pair_in_use) { pair = mem_get0 (THIS->ctx->dict_pair_pool); if (!pair) { if (key_free) GF_FREE (key); return -1; } } else { pair = &this->free_pair; this->free_pair_in_use = _gf_true; } if (key_free) { /* It's ours. Use it. */ pair->key = key; key_free = 0; } else { pair->key = (char *) GF_CALLOC (1, strlen (key) + 1, gf_common_mt_char); if (!pair->key) { if (pair == &this->free_pair) { this->free_pair_in_use = _gf_false; } else { mem_put (pair); } return -1; } strcpy (pair->key, key); } pair->value = data_ref (value); pair->hash_next = this->members[hashval]; this->members[hashval] = pair; pair->next = this->members_list; pair->prev = NULL; if (this->members_list) this->members_list->prev = pair; this->members_list = pair; this->count++; if (key_free) GF_FREE (key); return 0; } int32_t dict_set (dict_t *this, char *key, data_t *value) { int32_t ret; if (!this || !value) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "!this || !value for " "key=%s", key); return -1; } LOCK (&this->lock); ret = _dict_set (this, key, value, 1); UNLOCK (&this->lock); return ret; } int32_t dict_add (dict_t *this, char *key, data_t *value) { int32_t ret; if (!this || !value) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "!this || !value for key=%s", key); return -1; } LOCK (&this->lock); ret = _dict_set (this, key, value, 0); UNLOCK (&this->lock); return ret; } data_t * dict_get (dict_t *this, char *key) { data_pair_t *pair; if (!this || !key) { gf_msg_callingfn ("dict", GF_LOG_INFO, EINVAL, LG_MSG_INVALID_ARG, "!this || key=%s", (key) ? key : "()"); return NULL; } LOCK (&this->lock); pair = _dict_lookup (this, key); UNLOCK (&this->lock); if (pair) return pair->value; return NULL; } void dict_del (dict_t *this, char *key) { int hashval = 0; if (!this || !key) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "!this || key=%s", key); return; } LOCK (&this->lock); /* If the divisor is 1, the modulo is always 0, * in such case avoid hash calculation. */ if (this->hash_size != 1) hashval = SuperFastHash (key, strlen (key)) % this->hash_size; data_pair_t *pair = this->members[hashval]; data_pair_t *prev = NULL; while (pair) { if (strcmp (pair->key, key) == 0) { if (prev) prev->hash_next = pair->hash_next; else this->members[hashval] = pair->hash_next; data_unref (pair->value); if (pair->prev) pair->prev->next = pair->next; else this->members_list = pair->next; if (pair->next) pair->next->prev = pair->prev; GF_FREE (pair->key); if (pair == &this->free_pair) { this->free_pair_in_use = _gf_false; } else { mem_put (pair); } this->count--; break; } prev = pair; pair = pair->hash_next; } UNLOCK (&this->lock); return; } void dict_destroy (dict_t *this) { if (!this) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "dict is NULL"); return; } data_pair_t *pair = this->members_list; data_pair_t *prev = this->members_list; LOCK_DESTROY (&this->lock); while (prev) { pair = pair->next; data_unref (prev->value); GF_FREE (prev->key); if (prev != &this->free_pair) { mem_put (prev); } prev = pair; } if (this->members != &this->members_internal) { mem_put (this->members); } GF_FREE (this->extra_free); free (this->extra_stdfree); if (!this->is_static) mem_put (this); return; } void dict_unref (dict_t *this) { int32_t ref; if (!this) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "dict is NULL"); return; } LOCK (&this->lock); this->refcount--; ref = this->refcount; UNLOCK (&this->lock); if (!ref) dict_destroy (this); } dict_t * dict_ref (dict_t *this) { if (!this) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "dict is NULL"); return NULL; } LOCK (&this->lock); this->refcount++; UNLOCK (&this->lock); return this; } void data_unref (data_t *this) { int32_t ref; if (!this) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "dict is NULL"); return; } LOCK (&this->lock); this->refcount--; ref = this->refcount; UNLOCK (&this->lock); if (!ref) data_destroy (this); } data_t * data_ref (data_t *this) { if (!this) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "dict is NULL"); return NULL; } LOCK (&this->lock); this->refcount++; UNLOCK (&this->lock); return this; } data_t * int_to_data (int64_t value) { int ret = 0; data_t *data = get_new_data (); if (!data) { return NULL; } ret = gf_asprintf (&data->data, "%"PRId64, value); if (-1 == ret) { gf_msg_debug ("dict", 0, "asprintf failed"); return NULL; } data->len = strlen (data->data) + 1; return data; } data_t * data_from_int64 (int64_t value) { int ret = 0; data_t *data = get_new_data (); if (!data) { return NULL; } ret = gf_asprintf (&data->data, "%"PRId64, value); if (-1 == ret) { gf_msg_debug ("dict", 0, "asprintf failed"); return NULL; } data->len = strlen (data->data) + 1; return data; } data_t * data_from_int32 (int32_t value) { int ret = 0; data_t *data = get_new_data (); if (!data) { return NULL; } ret = gf_asprintf (&data->data, "%"PRId32, value); if (-1 == ret) { gf_msg_debug ("dict", 0, "asprintf failed"); return NULL; } data->len = strlen (data->data) + 1; return data; } data_t * data_from_int16 (int16_t value) { int ret = 0; data_t *data = get_new_data (); if (!data) { return NULL; } ret = gf_asprintf (&data->data, "%"PRId16, value); if (-1 == ret) { gf_msg_debug ("dict", 0, "asprintf failed"); return NULL; } data->len = strlen (data->data) + 1; return data; } data_t * data_from_int8 (int8_t value) { int ret = 0; data_t *data = get_new_data (); if (!data) { return NULL; } ret = gf_asprintf (&data->data, "%d", value); if (-1 == ret) { gf_msg_debug ("dict", 0, "asprintf failed"); return NULL; } data->len = strlen (data->data) + 1; return data; } data_t * data_from_uint64 (uint64_t value) { int ret = 0; data_t *data = get_new_data (); if (!data) { return NULL; } ret = gf_asprintf (&data->data, "%"PRIu64, value); if (-1 == ret) { gf_msg_debug ("dict", 0, "asprintf failed"); return NULL; } data->len = strlen (data->data) + 1; return data; } static data_t * data_from_double (double value) { data_t *data = NULL; int ret = 0; data = get_new_data (); if (!data) { return NULL; } ret = gf_asprintf (&data->data, "%f", value); if (ret == -1) { return NULL; } data->len = strlen (data->data) + 1; return data; } data_t * data_from_uint32 (uint32_t value) { int ret = 0; data_t *data = get_new_data (); if (!data) { return NULL; } ret = gf_asprintf (&data->data, "%"PRIu32, value); if (-1 == ret) { gf_msg_debug ("dict", 0, "asprintf failed"); return NULL; } data->len = strlen (data->data) + 1; return data; } data_t * data_from_uint16 (uint16_t value) { int ret = 0; data_t *data = get_new_data (); if (!data) { return NULL; } ret = gf_asprintf (&data->data, "%"PRIu16, value); if (-1 == ret) { return NULL; } data->len = strlen (data->data) + 1; return data; } data_t * data_from_ptr (void *value) { if (!value) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "value is NULL"); return NULL; } data_t *data = get_new_data (); if (!data) { return NULL; } data->data = value; return data; } data_t * data_from_static_ptr (void *value) { /* this is valid to set 0 as value.. if (!value) { gf_log ("dict", GF_LOG_CRITICAL, "@value=%p", value); return NULL; } */ data_t *data = get_new_data (); if (!data) { return NULL; } data->is_static = 1; data->data = value; return data; } data_t * str_to_data (char *value) { if (!value) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "value is NULL"); return NULL; } data_t *data = get_new_data (); if (!data) { return NULL; } data->len = strlen (value) + 1; data->data = value; data->is_static = 1; return data; } data_t * data_from_dynstr (char *value) { if (!value) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "value is NULL"); return NULL; } data_t *data = get_new_data (); if (!data) return NULL; data->len = strlen (value) + 1; data->data = value; return data; } data_t * data_from_dynmstr (char *value) { if (!value) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "value is NULL"); return NULL; } data_t *data = get_new_data (); if (!data) return NULL; data->len = strlen (value) + 1; data->data = value; data->is_stdalloc = 1; return data; } data_t * data_from_dynptr (void *value, int32_t len) { data_t *data = get_new_data (); if (!data) return NULL; data->len = len; data->data = value; return data; } data_t * bin_to_data (void *value, int32_t len) { if (!value) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "value is NULL"); return NULL; } data_t *data = get_new_data (); if (!data) return NULL; data->is_static = 1; data->len = len; data->data = value; return data; } int64_t data_to_int64 (data_t *data) { if (!data) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "data is NULL"); return -1; } char *str = alloca (data->len + 1); if (!str) return -1; memcpy (str, data->data, data->len); str[data->len] = '\0'; return (int64_t) strtoull (str, NULL, 0); } int32_t data_to_int32 (data_t *data) { if (!data) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "data is NULL"); return -1; } char *str = alloca (data->len + 1); if (!str) return -1; memcpy (str, data->data, data->len); str[data->len] = '\0'; return strtoul (str, NULL, 0); } int16_t data_to_int16 (data_t *data) { int16_t value = 0; if (!data) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "data is NULL"); return -1; } char *str = alloca (data->len + 1); if (!str) return -1; memcpy (str, data->data, data->len); str[data->len] = '\0'; errno = 0; value = strtol (str, NULL, 0); if ((value > SHRT_MAX) || (value < SHRT_MIN)) { errno = ERANGE; gf_msg_callingfn ("dict", GF_LOG_WARNING, errno, LG_MSG_DATA_CONVERSION_ERROR, "Error in data" " conversion: detected overflow"); return -1; } return (int16_t)value; } int8_t data_to_int8 (data_t *data) { int8_t value = 0; if (!data) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "data is NULL"); return -1; } char *str = alloca (data->len + 1); if (!str) return -1; memcpy (str, data->data, data->len); str[data->len] = '\0'; errno = 0; value = strtol (str, NULL, 0); if ((value > SCHAR_MAX) || (value < SCHAR_MIN)) { errno = ERANGE; gf_msg_callingfn ("dict", GF_LOG_WARNING, errno, LG_MSG_DATA_CONVERSION_ERROR, "Error in data" " conversion: detected overflow"); return -1; } return (int8_t)value; } uint64_t data_to_uint64 (data_t *data) { if (!data) return -1; char *str = alloca (data->len + 1); if (!str) return -1; memcpy (str, data->data, data->len); str[data->len] = '\0'; return strtoll (str, NULL, 0); } uint32_t data_to_uint32 (data_t *data) { if (!data) return -1; char *str = alloca (data->len + 1); if (!str) return -1; memcpy (str, data->data, data->len); str[data->len] = '\0'; return strtol (str, NULL, 0); } uint16_t data_to_uint16 (data_t *data) { uint16_t value = 0; if (!data) return -1; char *str = alloca (data->len + 1); if (!str) return -1; memcpy (str, data->data, data->len); str[data->len] = '\0'; errno = 0; value = strtol (str, NULL, 0); if ((USHRT_MAX - value) < 0) { errno = ERANGE; gf_msg_callingfn ("dict", GF_LOG_WARNING, errno, LG_MSG_DATA_CONVERSION_ERROR, "Error in data conversion: " "overflow detected"); return -1; } return (uint16_t)value; } uint8_t data_to_uint8 (data_t *data) { uint32_t value = 0; if (!data) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "data is NULL"); return -1; } char *str = alloca (data->len + 1); if (!str) return -1; memcpy (str, data->data, data->len); str[data->len] = '\0'; errno = 0; value = strtol (str, NULL, 0); if ((UCHAR_MAX - (uint8_t)value) < 0) { errno = ERANGE; gf_msg_callingfn ("dict", GF_LOG_WARNING, errno, LG_MSG_DATA_CONVERSION_ERROR, "data " "conversion overflow detected"); return -1; } return (uint8_t) value; } char * data_to_str (data_t *data) { if (!data) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "data is NULL"); return NULL; } return data->data; } void * data_to_ptr (data_t *data) { if (!data) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "data is NULL"); return NULL; } return data->data; } void * data_to_bin (data_t *data) { if (!data) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "data is NULL"); return NULL; } return data->data; } int dict_null_foreach_fn (dict_t *d, char *k, data_t *v, void *tmp) { return 0; } int dict_remove_foreach_fn (dict_t *d, char *k, data_t *v, void *_tmp) { if (!d || !k) { gf_msg ("glusterfs", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ENTRY, "%s is NULL", d?"key":"dictionary"); return -1; } dict_del (d, k); return 0; } gf_boolean_t dict_match_everything (dict_t *d, char *k, data_t *v, void *data) { return _gf_true; } int dict_foreach (dict_t *dict, int (*fn)(dict_t *this, char *key, data_t *value, void *data), void *data) { int ret = 0; ret = dict_foreach_match (dict, dict_match_everything, NULL, fn, data); if (ret > 0) ret = 0; return ret; } /* return values: -1 = failure, 0 = no matches found, +n = n number of matches */ int dict_foreach_match (dict_t *dict, gf_boolean_t (*match)(dict_t *this, char *key, data_t *value, void *mdata), void *match_data, int (*action)(dict_t *this, char *key, data_t *value, void *adata), void *action_data) { if (!dict || !match || !action) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "dict|match|action is " "NULL"); return -1; } int ret = -1; int count = 0; data_pair_t *pairs = NULL; data_pair_t *next = NULL; pairs = dict->members_list; while (pairs) { next = pairs->next; if (match (dict, pairs->key, pairs->value, match_data)) { ret = action (dict, pairs->key, pairs->value, action_data); if (ret < 0) return ret; count++; } pairs = next; } return count; } static gf_boolean_t dict_fnmatch (dict_t *d, char *k, data_t *val, void *match_data) { return (fnmatch (match_data, k, 0) == 0); } /* return values: -1 = failure, 0 = no matches found, +n = n number of matches */ int dict_foreach_fnmatch (dict_t *dict, char *pattern, int (*fn)(dict_t *this, char *key, data_t *value, void *data), void *data) { return dict_foreach_match (dict, dict_fnmatch, pattern, fn, data); } /** * 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)){ pairs = next; 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, data_t *value, void *newdict) { return dict_set ((dict_t *)newdict, key, (value)); } dict_t * dict_copy (dict_t *dict, dict_t *new) { if (!dict) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "dict is NULL"); return NULL; } if (!new) new = get_new_dict_full (dict->hash_size); dict_foreach (dict, _copy, new); return new; } int dict_reset (dict_t *dict) { int32_t ret = -1; if (!dict) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "dict is NULL"); goto out; } dict_foreach (dict, dict_remove_foreach_fn, NULL); ret = 0; out: return ret; } dict_t * dict_copy_with_ref (dict_t *dict, dict_t *new) { dict_t *local_new = NULL; GF_VALIDATE_OR_GOTO("dict", dict, fail); if (new == NULL) { local_new = dict_new (); GF_VALIDATE_OR_GOTO("dict", local_new, fail); new = local_new; } dict_foreach (dict, _copy, new); fail: return new; } /* * !!!!!!! CLEANED UP CODE !!!!!!! */ /** * Common cleaned up interface: * * Return value: 0 success * -val error, val = errno */ static int dict_get_with_ref (dict_t *this, char *key, data_t **data) { data_pair_t * pair = NULL; int ret = -ENOENT; if (!this || !key || !data) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "dict OR key (%s) is NULL", key); ret = -EINVAL; goto err; } LOCK (&this->lock); { pair = _dict_lookup (this, key); } UNLOCK (&this->lock); if (pair) { ret = 0; *data = data_ref (pair->value); } err: return ret; } static int _data_to_ptr (data_t *data, void **val) { int ret = 0; if (!data) { ret = -EINVAL; goto err; } *val = data->data; err: return ret; } static int _data_to_int8 (data_t *data, int8_t *val) { int ret = 0; char * str = NULL; if (!data || !val) { ret = -EINVAL; goto err; } str = alloca (data->len + 1); if (!str) { ret = -ENOMEM; goto err; } memcpy (str, data->data, data->len); str[data->len] = '\0'; errno = 0; *val = strtol (str, NULL, 0); if (errno != 0) ret = -errno; err: return ret; } static int _data_to_int16 (data_t *data, int16_t *val) { int ret = 0; char * str = NULL; if (!data || !val) { ret = -EINVAL; goto err; } str = alloca (data->len + 1); if (!str) { ret = -ENOMEM; goto err; } memcpy (str, data->data, data->len); str[data->len] = '\0'; errno = 0; *val = strtol (str, NULL, 0); if (errno != 0) ret = -errno; err: return ret; } static int _data_to_int32 (data_t *data, int32_t *val) { int ret = 0; char * str = NULL; if (!data || !val) { ret = -EINVAL; goto err; } str = alloca (data->len + 1); if (!str) { ret = -ENOMEM; goto err; } memcpy (str, data->data, data->len); str[data->len] = '\0'; errno = 0; *val = strtol (str, NULL, 0); if (errno != 0) ret = -errno; err: return ret; } static int _data_to_int64 (data_t *data, int64_t *val) { int ret = 0; char * str = NULL; if (!data || !val) { ret = -EINVAL; goto err; } str = alloca (data->len + 1); if (!str) { ret = -ENOMEM; goto err; } memcpy (str, data->data, data->len); str[data->len] = '\0'; errno = 0; *val = strtoll (str, NULL, 0); if (errno != 0) ret = -errno; err: return ret; } static int _data_to_uint16 (data_t *data, uint16_t *val) { int ret = 0; char * str = NULL; if (!data || !val) { ret = -EINVAL; goto err; } str = alloca (data->len + 1); if (!str) { ret = -ENOMEM; goto err; } memcpy (str, data->data, data->len); str[data->len] = '\0'; errno = 0; *val = strtoul (str, NULL, 0); if (errno != 0) ret = -errno; err: return ret; } static int _data_to_uint32 (data_t *data, uint32_t *val) { int ret = 0; char * str = NULL; if (!data || !val) { ret = -EINVAL; goto err; } str = alloca (data->len + 1); if (!str) { ret = -ENOMEM; goto err; } memcpy (str, data->data, data->len); str[data->len] = '\0'; errno = 0; *val = strtoul (str, NULL, 0); if (errno != 0) ret = -errno; err: return ret; } static int _data_to_uint64 (data_t *data, uint64_t *val) { int ret = 0; char * str = NULL; if (!data || !val) { ret = -EINVAL; goto err; } str = alloca (data->len + 1); if (!str) { ret = -ENOMEM; goto err; } memcpy (str, data->data, data->len); str[data->len] = '\0'; errno = 0; *val = strtoull (str, NULL, 0); if (errno != 0) ret = -errno; err: return ret; } static int _data_to_double (data_t *data, double *val) { int ret = 0; char * str = NULL; if (!data || !val) { ret = -EINVAL; goto err; } str = alloca (data->len + 1); if (!str) { ret = -ENOMEM; goto err; } memcpy (str, data->data, data->len); str[data->len] = '\0'; errno = 0; *val = strtod (str, NULL); if (errno != 0) ret = -errno; err: return ret; } int dict_get_int8 (dict_t *this, char *key, int8_t *val) { data_t * data = NULL; int ret = 0; if (!this || !key || !val) { ret = -EINVAL; goto err; } ret = dict_get_with_ref (this, key, &data); if (ret != 0) { goto err; } ret = _data_to_int8 (data, val); err: if (data) data_unref (data); return ret; } int dict_set_int8 (dict_t *this, char *key, int8_t val) { data_t * data = NULL; int ret = 0; data = data_from_int8 (val); if (!data) { ret = -EINVAL; goto err; } ret = dict_set (this, key, data); if (ret < 0) data_destroy (data); err: return ret; } int dict_get_int16 (dict_t *this, char *key, int16_t *val) { data_t * data = NULL; int ret = 0; if (!this || !key || !val) { ret = -EINVAL; goto err; } ret = dict_get_with_ref (this, key, &data); if (ret != 0) { goto err; } ret = _data_to_int16 (data, val); err: if (data) data_unref (data); return ret; } int dict_set_int16 (dict_t *this, char *key, int16_t val) { data_t * data = NULL; int ret = 0; data = data_from_int16 (val); if (!data) { ret = -EINVAL; goto err; } ret = dict_set (this, key, data); if (ret < 0) data_destroy (data); err: return ret; } int dict_get_int32 (dict_t *this, char *key, int32_t *val) { data_t * data = NULL; int ret = 0; if (!this || !key || !val) { ret = -EINVAL; goto err; } ret = dict_get_with_ref (this, key, &data); if (ret != 0) { goto err; } ret = _data_to_int32 (data, val); err: if (data) data_unref (data); return ret; } int dict_set_int32 (dict_t *this, char *key, int32_t val) { data_t * data = NULL; int ret = 0; data = data_from_int32 (val); if (!data) { ret = -EINVAL; goto err; } ret = dict_set (this, key, data); if (ret < 0) data_destroy (data); err: return ret; } int dict_get_int64 (dict_t *this, char *key, int64_t *val) { data_t * data = NULL; int ret = 0; if (!this || !key || !val) { ret = -EINVAL; goto err; } ret = dict_get_with_ref (this, key, &data); if (ret != 0) { goto err; } ret = _data_to_int64 (data, val); err: if (data) data_unref (data); return ret; } int dict_set_int64 (dict_t *this, char *key, int64_t val) { data_t * data = NULL; int ret = 0; data = data_from_int64 (val); if (!data) { ret = -EINVAL; goto err; } ret = dict_set (this, key, data); if (ret < 0) data_destroy (data); err: return ret; } int dict_get_uint16 (dict_t *this, char *key, uint16_t *val) { data_t * data = NULL; int ret = 0; if (!this || !key || !val) { ret = -EINVAL; goto err; } ret = dict_get_with_ref (this, key, &data); if (ret != 0) { goto err; } ret = _data_to_uint16 (data, val); err: if (data) data_unref (data); return ret; } int dict_set_uint16 (dict_t *this, char *key, uint16_t val) { data_t * data = NULL; int ret = 0; data = data_from_uint16 (val); if (!data) { ret = -EINVAL; goto err; } ret = dict_set (this, key, data); if (ret < 0) data_destroy (data); err: return ret; } int dict_get_uint32 (dict_t *this, char *key, uint32_t *val) { data_t * data = NULL; int ret = 0; if (!this || !key || !val) { ret = -EINVAL; goto err; } ret = dict_get_with_ref (this, key, &data); if (ret != 0) { goto err;