mirror of https://github.com/getdnsapi/getdns.git
Simplify _set_string functions
This commit is contained in:
parent
ad23c446b6
commit
f91e263f09
27
src/dict.c
27
src/dict.c
|
@ -578,7 +578,7 @@ getdns_dict_set_list(
|
||||||
/*---------------------------------------- getdns_dict_set_bindata */
|
/*---------------------------------------- getdns_dict_set_bindata */
|
||||||
getdns_return_t
|
getdns_return_t
|
||||||
_getdns_dict_set_const_bindata(
|
_getdns_dict_set_const_bindata(
|
||||||
getdns_dict *dict, const char *name, size_t size, const uint8_t *data)
|
getdns_dict *dict, const char *name, size_t size, const void *data)
|
||||||
{
|
{
|
||||||
getdns_item *item;
|
getdns_item *item;
|
||||||
getdns_bindata *newbindata;
|
getdns_bindata *newbindata;
|
||||||
|
@ -612,28 +612,9 @@ getdns_dict_set_bindata(
|
||||||
getdns_return_t
|
getdns_return_t
|
||||||
getdns_dict_util_set_string(getdns_dict *dict, char *name, const char *value)
|
getdns_dict_util_set_string(getdns_dict *dict, char *name, const char *value)
|
||||||
{
|
{
|
||||||
getdns_item *item;
|
return value
|
||||||
getdns_bindata *newbindata;
|
? _getdns_dict_set_const_bindata(dict, name, strlen(value), value)
|
||||||
getdns_return_t r;
|
: GETDNS_RETURN_INVALID_PARAMETER;
|
||||||
|
|
||||||
if (!dict || !name || !value)
|
|
||||||
return GETDNS_RETURN_INVALID_PARAMETER;
|
|
||||||
|
|
||||||
if (!(newbindata = GETDNS_MALLOC(dict->mf, getdns_bindata)))
|
|
||||||
return GETDNS_RETURN_MEMORY_ERROR;
|
|
||||||
|
|
||||||
newbindata->size = strlen(value);
|
|
||||||
if (!(newbindata->data = (void *)_getdns_strdup(&dict->mf, value))) {
|
|
||||||
GETDNS_FREE(dict->mf, newbindata);
|
|
||||||
return GETDNS_RETURN_MEMORY_ERROR;
|
|
||||||
}
|
|
||||||
if ((r = _getdns_dict_find_and_add(dict, name, &item))) {
|
|
||||||
_getdns_bindata_destroy(&dict->mf, newbindata);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
item->dtype = t_bindata;
|
|
||||||
item->data.bindata = newbindata;
|
|
||||||
return GETDNS_RETURN_GOOD;
|
|
||||||
} /* getdns_dict_util_set_dict */
|
} /* getdns_dict_util_set_dict */
|
||||||
|
|
||||||
/*---------------------------------------- getdns_dict_set_int */
|
/*---------------------------------------- getdns_dict_set_int */
|
||||||
|
|
29
src/list.c
29
src/list.c
|
@ -554,7 +554,7 @@ getdns_list_set_list(
|
||||||
/*---------------------------------------- getdns_list_set_bindata */
|
/*---------------------------------------- getdns_list_set_bindata */
|
||||||
static getdns_return_t
|
static getdns_return_t
|
||||||
_getdns_list_set_const_bindata(
|
_getdns_list_set_const_bindata(
|
||||||
getdns_list *list, size_t index, size_t size, const uint8_t *data)
|
getdns_list *list, size_t index, size_t size, const void *data)
|
||||||
{
|
{
|
||||||
getdns_bindata *newbindata;
|
getdns_bindata *newbindata;
|
||||||
getdns_return_t r;
|
getdns_return_t r;
|
||||||
|
@ -587,28 +587,9 @@ getdns_list_set_bindata(
|
||||||
static getdns_return_t
|
static getdns_return_t
|
||||||
getdns_list_set_string(getdns_list *list, size_t index, const char *value)
|
getdns_list_set_string(getdns_list *list, size_t index, const char *value)
|
||||||
{
|
{
|
||||||
getdns_bindata *newbindata;
|
return value
|
||||||
getdns_return_t r;
|
? _getdns_list_set_const_bindata(list, index, strlen(value), value)
|
||||||
|
: GETDNS_RETURN_INVALID_PARAMETER;
|
||||||
if (!list || !value)
|
|
||||||
return GETDNS_RETURN_INVALID_PARAMETER;
|
|
||||||
|
|
||||||
if (!(newbindata = GETDNS_MALLOC(list->mf, getdns_bindata)))
|
|
||||||
return GETDNS_RETURN_MEMORY_ERROR;
|
|
||||||
|
|
||||||
newbindata->size = strlen(value);
|
|
||||||
if (!(newbindata->data = (void *)_getdns_strdup(&list->mf, value))) {
|
|
||||||
GETDNS_FREE(list->mf, newbindata);
|
|
||||||
return GETDNS_RETURN_MEMORY_ERROR;
|
|
||||||
}
|
|
||||||
if ((r = _getdns_list_request_index(list, index))) {
|
|
||||||
GETDNS_FREE(list->mf, newbindata->data);
|
|
||||||
GETDNS_FREE(list->mf, newbindata);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
list->items[index].dtype = t_bindata;
|
|
||||||
list->items[index].data.bindata = newbindata;
|
|
||||||
return GETDNS_RETURN_GOOD;
|
|
||||||
} /* getdns_list_set_string */
|
} /* getdns_list_set_string */
|
||||||
|
|
||||||
/*---------------------------------------- getdns_list_set_int */
|
/*---------------------------------------- getdns_list_set_int */
|
||||||
|
@ -648,7 +629,7 @@ _getdns_list_append_bindata(getdns_list *list, const getdns_bindata *child_binda
|
||||||
}
|
}
|
||||||
getdns_return_t
|
getdns_return_t
|
||||||
_getdns_list_append_const_bindata(
|
_getdns_list_append_const_bindata(
|
||||||
getdns_list *list, size_t size, const uint8_t *data)
|
getdns_list *list, size_t size, const void *data)
|
||||||
{
|
{
|
||||||
if (!list) return GETDNS_RETURN_INVALID_PARAMETER;
|
if (!list) return GETDNS_RETURN_INVALID_PARAMETER;
|
||||||
return _getdns_list_set_const_bindata(list, list->numinuse, size, data);
|
return _getdns_list_set_const_bindata(list, list->numinuse, size, data);
|
||||||
|
|
|
@ -83,10 +83,10 @@ getdns_return_t _getdns_list_append_int(getdns_list *list,
|
||||||
uint32_t child_uint32);
|
uint32_t child_uint32);
|
||||||
|
|
||||||
getdns_return_t _getdns_list_append_const_bindata(getdns_list *list,
|
getdns_return_t _getdns_list_append_const_bindata(getdns_list *list,
|
||||||
size_t size, const uint8_t *data);
|
size_t size, const void *data);
|
||||||
|
|
||||||
getdns_return_t _getdns_dict_set_const_bindata(getdns_dict *dict,
|
getdns_return_t _getdns_dict_set_const_bindata(getdns_dict *dict,
|
||||||
const char *name, size_t size, const uint8_t *data);
|
const char *name, size_t size, const void *data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* private function (API users should not be calling this), this uses library
|
* private function (API users should not be calling this), this uses library
|
||||||
|
|
Loading…
Reference in New Issue