Non copying dict_set functions

This commit is contained in:
Willem Toorop 2016-03-21 11:54:55 +01:00
parent e4e3dde61f
commit fc5f16dbcb
2 changed files with 75 additions and 28 deletions

View File

@ -530,75 +530,113 @@ getdns_dict_destroy(struct getdns_dict *dict)
/*---------------------------------------- getdns_dict_set_dict */
getdns_return_t
getdns_dict_set_dict(
getdns_dict *dict, const char *name, const getdns_dict *child_dict)
_getdns_dict_set_this_dict(
getdns_dict *dict, const char *name, getdns_dict *child_dict)
{
getdns_item *item;
getdns_dict *newdict;
getdns_return_t r;
if (!dict || !name || !child_dict)
return GETDNS_RETURN_INVALID_PARAMETER;
if ((r = _getdns_dict_copy(child_dict, &newdict)))
if ((r = _getdns_dict_find_and_add(dict, name, &item)))
return r;
if ((r = _getdns_dict_find_and_add(dict, name, &item))) {
getdns_dict_destroy(newdict);
return r;
}
item->dtype = t_dict;
item->data.dict = newdict;
item->data.dict = child_dict;
return GETDNS_RETURN_GOOD;
} /* getdns_dict_set_dict */
getdns_return_t
getdns_dict_set_dict(
getdns_dict *dict, const char *name, const getdns_dict *child_dict)
{
getdns_dict *newdict;
getdns_return_t r;
if ((r = _getdns_dict_copy(child_dict, &newdict)))
return r;
if ((r = _getdns_dict_set_this_dict(dict, name, newdict)))
getdns_dict_destroy(newdict);
return r;
}
/*---------------------------------------- getdns_dict_set_list */
getdns_return_t
getdns_dict_set_list(
getdns_dict *dict, const char *name, const getdns_list *child_list)
_getdns_dict_set_this_list(
getdns_dict *dict, const char *name, getdns_list *child_list)
{
getdns_item *item;
getdns_list *newlist;
getdns_return_t r;
if (!dict || !name || !child_list)
return GETDNS_RETURN_INVALID_PARAMETER;
if ((r = _getdns_list_copy(child_list, &newlist)))
if ((r = _getdns_dict_find_and_add(dict, name, &item)))
return r;
if ((r = _getdns_dict_find_and_add(dict, name, &item))) {
getdns_list_destroy(newlist);
return r;
}
item->dtype = t_list;
item->data.list = newlist;
item->data.list = child_list;
return GETDNS_RETURN_GOOD;
} /* getdns_dict_set_list */
getdns_return_t
getdns_dict_set_list(
getdns_dict *dict, const char *name, const getdns_list *child_list)
{
getdns_list *newlist;
getdns_return_t r;
if ((r = _getdns_list_copy(child_list, &newlist)))
return r;
if ((r = _getdns_dict_set_this_list(dict, name, newlist)))
getdns_list_destroy(newlist);
return r;
}
/*---------------------------------------- getdns_dict_set_bindata */
getdns_return_t
_getdns_dict_set_const_bindata(
getdns_dict *dict, const char *name, size_t size, const void *data)
_getdns_dict_set_this_bindata(
getdns_dict *dict, const char *name, getdns_bindata *bindata)
{
getdns_item *item;
getdns_bindata *newbindata;
getdns_return_t r;
if (!dict || !name)
return GETDNS_RETURN_INVALID_PARAMETER;
if ((r = _getdns_dict_find_and_add(dict, name, &item)))
return r;
item->dtype = t_bindata;
item->data.bindata = bindata;
return GETDNS_RETURN_GOOD;
} /* getdns_dict_set_bindata */
getdns_return_t
_getdns_dict_set_const_bindata(
getdns_dict *dict, const char *name, size_t size, const void *data)
{
getdns_bindata *newbindata;
getdns_return_t r;
if (!dict)
return GETDNS_RETURN_INVALID_PARAMETER;
if (!(newbindata = _getdns_bindata_copy(&dict->mf, size, data)))
return GETDNS_RETURN_MEMORY_ERROR;
if ((r = _getdns_dict_find_and_add(dict, name, &item))) {
if ((r = _getdns_dict_set_this_bindata(dict, name, newbindata)))
_getdns_bindata_destroy(&dict->mf, newbindata);
return r;
}
item->dtype = t_bindata;
item->data.bindata = newbindata;
return GETDNS_RETURN_GOOD;
} /* getdns_dict_set_bindata */
return r;
}
getdns_return_t
getdns_dict_set_bindata(

View File

@ -86,6 +86,15 @@ getdns_return_t _getdns_list_append_int(getdns_list *list,
getdns_return_t _getdns_list_append_const_bindata(getdns_list *list,
size_t size, const void *data);
getdns_return_t _getdns_dict_set_this_dict(getdns_dict *dict,
const char *name, getdns_dict *child_dict);
getdns_return_t _getdns_dict_set_this_list(getdns_dict *dict,
const char *name, getdns_list *child_list);
getdns_return_t _getdns_dict_set_this_bindata(getdns_dict *dict,
const char *name, getdns_bindata *child_bindata);
getdns_return_t _getdns_dict_set_const_bindata(getdns_dict *dict,
const char *name, size_t size, const void *data);