2013-07-15 17:43:30 -05:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* /brief getdns list management functions
|
2013-12-09 13:11:17 -06:00
|
|
|
*
|
2013-07-15 17:43:30 -05:00
|
|
|
* This is the meat of the API
|
|
|
|
* Originally taken from the getdns API description pseudo implementation.
|
|
|
|
*
|
|
|
|
*/
|
2013-11-04 17:37:54 -06:00
|
|
|
|
|
|
|
/*
|
2014-02-25 07:12:33 -06:00
|
|
|
* Copyright (c) 2013, NLnet Labs, Verisign, Inc.
|
2013-11-04 17:37:54 -06:00
|
|
|
* All rights reserved.
|
2013-12-09 13:11:17 -06:00
|
|
|
*
|
2013-11-04 17:37:54 -06:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2014-02-25 07:23:19 -06:00
|
|
|
* * Neither the names of the copyright holders nor the
|
2013-11-04 17:37:54 -06:00
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2013-07-15 17:43:30 -05:00
|
|
|
*/
|
|
|
|
|
2013-07-22 14:16:40 -05:00
|
|
|
#include <string.h>
|
2013-11-12 10:00:19 -06:00
|
|
|
#include "types-internal.h"
|
2013-12-03 07:13:10 -06:00
|
|
|
#include "util-internal.h"
|
2013-10-29 15:02:21 -05:00
|
|
|
#include "list.h"
|
2013-07-15 17:43:30 -05:00
|
|
|
|
2013-07-31 15:21:42 -05:00
|
|
|
/*---------------------------------------- getdns_list_get_length */
|
2013-07-19 15:19:22 -05:00
|
|
|
getdns_return_t
|
2014-01-14 10:25:23 -06:00
|
|
|
getdns_list_get_length(const struct getdns_list * list, size_t * answer)
|
2013-07-19 15:19:22 -05:00
|
|
|
{
|
2013-11-11 16:10:22 -06:00
|
|
|
if (!list || !answer)
|
2014-02-03 20:34:11 -06:00
|
|
|
return GETDNS_RETURN_INVALID_PARAMETER;
|
2013-07-19 15:19:22 -05:00
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
*answer = list->numinuse;
|
|
|
|
return GETDNS_RETURN_GOOD;;
|
2013-11-05 14:03:44 -06:00
|
|
|
} /* getdns_list_get_length */
|
2013-07-19 15:19:22 -05:00
|
|
|
|
|
|
|
/*---------------------------------------- getdns_list_get_data_type */
|
2013-11-05 14:03:44 -06:00
|
|
|
getdns_return_t
|
2014-01-14 10:25:23 -06:00
|
|
|
getdns_list_get_data_type(const struct getdns_list * list, size_t index,
|
2014-03-07 09:42:37 -06:00
|
|
|
getdns_data_type * answer)
|
2013-07-19 15:19:22 -05:00
|
|
|
{
|
2014-03-07 09:42:37 -06:00
|
|
|
if (!list || !answer)
|
|
|
|
return GETDNS_RETURN_INVALID_PARAMETER;
|
2014-01-10 09:35:03 -06:00
|
|
|
|
2014-01-15 15:25:46 -06:00
|
|
|
if (index >= list->numinuse)
|
|
|
|
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
|
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
*answer = list->items[index].dtype;
|
|
|
|
return GETDNS_RETURN_GOOD;
|
2013-11-05 14:03:44 -06:00
|
|
|
} /* getdns_list_get_data_type */
|
2013-07-15 17:43:30 -05:00
|
|
|
|
2013-07-31 15:21:42 -05:00
|
|
|
/*---------------------------------------- getdns_list_get_dict */
|
|
|
|
getdns_return_t
|
2014-01-14 10:25:23 -06:00
|
|
|
getdns_list_get_dict(const struct getdns_list * list, size_t index,
|
2014-03-07 09:42:37 -06:00
|
|
|
struct getdns_dict ** answer)
|
2013-07-31 15:21:42 -05:00
|
|
|
{
|
2014-03-07 09:42:37 -06:00
|
|
|
if (!list || !answer)
|
|
|
|
return GETDNS_RETURN_INVALID_PARAMETER;
|
2014-01-10 09:35:03 -06:00
|
|
|
|
2014-03-07 09:42:37 -06:00
|
|
|
if (index >= list->numinuse)
|
2014-01-15 15:25:46 -06:00
|
|
|
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
|
|
|
|
|
2014-03-07 09:42:37 -06:00
|
|
|
if (list->items[index].dtype != t_dict)
|
2013-11-11 16:10:22 -06:00
|
|
|
return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
|
|
|
|
|
|
|
|
*answer = list->items[index].data.dict;
|
|
|
|
return GETDNS_RETURN_GOOD;
|
2013-11-05 14:03:44 -06:00
|
|
|
} /* getdns_list_get_dict */
|
2013-07-15 17:43:30 -05:00
|
|
|
|
2013-07-19 15:19:22 -05:00
|
|
|
/*---------------------------------------- getdns_list_get_list */
|
|
|
|
getdns_return_t
|
2014-01-14 10:25:23 -06:00
|
|
|
getdns_list_get_list(const struct getdns_list * list, size_t index,
|
2014-03-07 09:42:37 -06:00
|
|
|
struct getdns_list ** answer)
|
2013-07-19 15:19:22 -05:00
|
|
|
{
|
2014-03-07 09:42:37 -06:00
|
|
|
if (!list || !answer)
|
|
|
|
return GETDNS_RETURN_INVALID_PARAMETER;
|
2013-11-05 14:03:44 -06:00
|
|
|
|
2014-01-15 15:25:46 -06:00
|
|
|
if (index >= list->numinuse)
|
2013-11-11 16:10:22 -06:00
|
|
|
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
|
|
|
|
|
2014-01-10 09:35:03 -06:00
|
|
|
if (list->items[index].dtype != t_list)
|
2013-11-11 16:10:22 -06:00
|
|
|
return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
|
|
|
|
|
|
|
|
*answer = list->items[index].data.list;
|
|
|
|
return GETDNS_RETURN_GOOD;
|
2013-11-05 14:03:44 -06:00
|
|
|
} /* getdns_list_get_list */
|
2013-07-15 17:43:30 -05:00
|
|
|
|
2013-07-22 14:16:40 -05:00
|
|
|
/*---------------------------------------- getdns_list_get_bindata */
|
2013-11-05 14:03:44 -06:00
|
|
|
getdns_return_t
|
2014-01-14 10:25:23 -06:00
|
|
|
getdns_list_get_bindata(const struct getdns_list * list, size_t index,
|
2014-03-07 09:42:37 -06:00
|
|
|
struct getdns_bindata ** answer)
|
2013-07-22 14:16:40 -05:00
|
|
|
{
|
2013-12-09 13:11:17 -06:00
|
|
|
|
2014-03-07 09:42:37 -06:00
|
|
|
if (!list || !answer)
|
|
|
|
return GETDNS_RETURN_INVALID_PARAMETER;
|
2014-01-10 09:35:03 -06:00
|
|
|
|
2014-03-07 09:42:37 -06:00
|
|
|
if (index >= list->numinuse)
|
|
|
|
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
|
2014-01-15 15:25:46 -06:00
|
|
|
|
2014-01-10 09:35:03 -06:00
|
|
|
if (list->items[index].dtype != t_bindata)
|
2013-11-11 16:10:22 -06:00
|
|
|
return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
|
|
|
|
|
|
|
|
*answer = list->items[index].data.bindata;
|
|
|
|
return GETDNS_RETURN_GOOD;
|
2013-11-05 14:03:44 -06:00
|
|
|
} /* getdns_list_get_bindata */
|
2013-07-15 17:43:30 -05:00
|
|
|
|
2013-07-19 15:19:22 -05:00
|
|
|
/*---------------------------------------- getdns_list_get_int */
|
|
|
|
getdns_return_t
|
2014-01-14 10:25:23 -06:00
|
|
|
getdns_list_get_int(const struct getdns_list * list, size_t index,
|
2014-03-07 09:42:37 -06:00
|
|
|
uint32_t * answer)
|
2013-07-19 15:19:22 -05:00
|
|
|
{
|
2014-03-07 09:42:37 -06:00
|
|
|
if (!list || !answer)
|
|
|
|
return GETDNS_RETURN_INVALID_PARAMETER;
|
2014-01-10 09:35:03 -06:00
|
|
|
|
2014-03-07 09:42:37 -06:00
|
|
|
if (index >= list->numinuse)
|
|
|
|
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
|
2014-01-15 15:25:46 -06:00
|
|
|
|
2014-01-10 09:35:03 -06:00
|
|
|
if (list->items[index].dtype != t_int)
|
2013-11-11 16:10:22 -06:00
|
|
|
return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
|
2013-11-05 14:03:44 -06:00
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
*answer = list->items[index].data.n;
|
|
|
|
return GETDNS_RETURN_GOOD;
|
2013-11-05 14:03:44 -06:00
|
|
|
} /* getdns_list_get_int */
|
2013-07-15 17:43:30 -05:00
|
|
|
|
2013-07-19 15:19:22 -05:00
|
|
|
/*---------------------------------------- getdns_list_realloc */
|
|
|
|
/**
|
|
|
|
* private function (API users should not be calling this)
|
|
|
|
* allocates a block of items, should be called when a list needs to grow
|
|
|
|
* preserves the existing items
|
|
|
|
* in case of an error the list should be considered unusable
|
|
|
|
* @return GETDNS_RETURN_GOOD on success, GETDNS_RETURN_GENERIC_ERROR if out of memory
|
|
|
|
*/
|
|
|
|
getdns_return_t
|
2013-11-11 16:10:22 -06:00
|
|
|
getdns_list_realloc(struct getdns_list *list)
|
2013-07-19 15:19:22 -05:00
|
|
|
{
|
2013-11-05 14:03:44 -06:00
|
|
|
struct getdns_list_item *newlist;
|
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
if (!list)
|
2014-01-15 15:25:46 -06:00
|
|
|
return GETDNS_RETURN_INVALID_PARAMETER;
|
2013-11-11 16:10:22 -06:00
|
|
|
|
2013-12-08 17:05:18 -06:00
|
|
|
newlist = GETDNS_XREALLOC(list->mf, list->items,
|
2014-03-07 09:42:37 -06:00
|
|
|
struct getdns_list_item,
|
|
|
|
list->numalloc + GETDNS_LIST_BLOCKSZ);
|
2013-11-11 16:10:22 -06:00
|
|
|
if (!newlist)
|
|
|
|
return GETDNS_RETURN_GENERIC_ERROR;
|
|
|
|
|
|
|
|
list->items = newlist;
|
|
|
|
list->numalloc += GETDNS_LIST_BLOCKSZ;
|
|
|
|
return GETDNS_RETURN_GOOD;
|
2013-11-05 14:03:44 -06:00
|
|
|
} /* getdns_list_realloc */
|
2013-07-22 14:16:40 -05:00
|
|
|
|
|
|
|
/*---------------------------------------- getdns_list_copy */
|
|
|
|
getdns_return_t
|
2014-02-09 14:41:26 -06:00
|
|
|
getdns_list_copy(const struct getdns_list * srclist,
|
2014-03-07 09:42:37 -06:00
|
|
|
struct getdns_list ** dstlist)
|
2013-07-22 14:16:40 -05:00
|
|
|
{
|
2013-11-05 14:03:44 -06:00
|
|
|
int i;
|
|
|
|
size_t index;
|
2013-11-11 16:10:22 -06:00
|
|
|
getdns_return_t retval;
|
2013-11-05 14:03:44 -06:00
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
if (!dstlist)
|
2014-01-15 15:25:46 -06:00
|
|
|
return GETDNS_RETURN_INVALID_PARAMETER;
|
2013-11-11 16:10:22 -06:00
|
|
|
|
|
|
|
if (!srclist) {
|
|
|
|
*dstlist = NULL;
|
|
|
|
return GETDNS_RETURN_GOOD;
|
|
|
|
}
|
2013-12-08 17:52:38 -06:00
|
|
|
*dstlist = getdns_list_create_with_extended_memory_functions(
|
2014-03-07 09:42:37 -06:00
|
|
|
srclist->mf.mf_arg,
|
|
|
|
srclist->mf.mf.ext.malloc,
|
|
|
|
srclist->mf.mf.ext.realloc,
|
|
|
|
srclist->mf.mf.ext.free
|
2013-12-08 17:05:18 -06:00
|
|
|
);
|
2013-11-11 16:10:22 -06:00
|
|
|
if (!dstlist)
|
2014-01-15 15:25:46 -06:00
|
|
|
return GETDNS_RETURN_GENERIC_ERROR;
|
2013-11-11 16:10:22 -06:00
|
|
|
|
|
|
|
for (i = 0; i < srclist->numinuse; i++) {
|
|
|
|
retval = getdns_list_add_item(*dstlist, &index);
|
|
|
|
if (retval != GETDNS_RETURN_GOOD) {
|
|
|
|
getdns_list_destroy(*dstlist);
|
|
|
|
*dstlist = NULL;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
switch (srclist->items[i].dtype) {
|
|
|
|
case t_int:
|
|
|
|
retval = getdns_list_set_int(*dstlist, index,
|
2015-03-12 15:37:03 -05:00
|
|
|
srclist->items[i].data.n);
|
2013-11-11 16:10:22 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case t_list:
|
|
|
|
retval =getdns_list_set_list(*dstlist, index,
|
2014-03-07 09:42:37 -06:00
|
|
|
srclist->items[i].data.list);
|
2013-11-11 16:10:22 -06:00
|
|
|
break;
|
2013-12-09 13:11:17 -06:00
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
case t_bindata:
|
|
|
|
retval = getdns_list_set_bindata(*dstlist, index,
|
2014-03-07 09:42:37 -06:00
|
|
|
srclist->items[i].data.bindata);
|
2013-11-11 16:10:22 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case t_dict:
|
|
|
|
retval = getdns_list_set_dict(*dstlist, index,
|
2014-03-07 09:42:37 -06:00
|
|
|
srclist->items[i].data.dict);
|
2013-11-11 16:10:22 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (retval != GETDNS_RETURN_GOOD) {
|
|
|
|
getdns_list_destroy(*dstlist);
|
|
|
|
*dstlist = NULL;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return GETDNS_RETURN_GOOD;
|
2013-11-05 14:03:44 -06:00
|
|
|
} /* getdns_list_copy */
|
2013-07-19 15:19:22 -05:00
|
|
|
|
|
|
|
struct getdns_list *
|
2013-12-08 17:52:38 -06:00
|
|
|
getdns_list_create_with_extended_memory_functions(
|
2014-03-07 09:42:37 -06:00
|
|
|
void *userarg,
|
|
|
|
void *(*malloc)(void *userarg, size_t),
|
|
|
|
void *(*realloc)(void *userarg, void *, size_t),
|
|
|
|
void (*free)(void *userarg, void *))
|
2013-07-19 15:19:22 -05:00
|
|
|
{
|
2013-11-11 16:10:22 -06:00
|
|
|
struct getdns_list *list;
|
2013-12-08 17:52:38 -06:00
|
|
|
mf_union mf;
|
2013-11-11 16:10:22 -06:00
|
|
|
|
2013-11-12 10:00:19 -06:00
|
|
|
if (!malloc || !realloc || !free)
|
|
|
|
return NULL;
|
|
|
|
|
2013-12-08 17:52:38 -06:00
|
|
|
mf.ext.malloc = malloc;
|
|
|
|
list = userarg == MF_PLAIN
|
2014-03-07 09:42:37 -06:00
|
|
|
? (struct getdns_list *)(*mf.pln.malloc)(
|
|
|
|
sizeof(struct getdns_list))
|
|
|
|
: (struct getdns_list *)(*mf.ext.malloc)(userarg,
|
|
|
|
sizeof(struct getdns_list));
|
2013-11-11 16:10:22 -06:00
|
|
|
if (!list)
|
|
|
|
return NULL;
|
2013-12-09 13:11:17 -06:00
|
|
|
|
2013-12-08 17:52:38 -06:00
|
|
|
list->mf.mf_arg = userarg;
|
|
|
|
list->mf.mf.ext.malloc = malloc;
|
|
|
|
list->mf.mf.ext.realloc = realloc;
|
|
|
|
list->mf.mf.ext.free = free;
|
2013-12-08 15:56:34 -06:00
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
list->numalloc = 0;
|
|
|
|
list->numinuse = 0;
|
|
|
|
list->items = NULL;
|
|
|
|
if (getdns_list_realloc(list) != GETDNS_RETURN_GOOD) {
|
|
|
|
getdns_list_destroy(list);
|
|
|
|
return NULL;
|
2013-11-05 14:03:44 -06:00
|
|
|
}
|
|
|
|
return list;
|
2013-11-12 10:00:19 -06:00
|
|
|
}
|
|
|
|
|
2013-12-08 17:52:38 -06:00
|
|
|
struct getdns_list *
|
|
|
|
getdns_list_create_with_memory_functions(void *(*malloc)(size_t),
|
2014-03-07 09:42:37 -06:00
|
|
|
void *(*realloc)(void *, size_t), void (*free)(void *))
|
2013-12-08 17:52:38 -06:00
|
|
|
{
|
|
|
|
mf_union mf;
|
|
|
|
mf.pln.malloc = malloc;
|
|
|
|
mf.pln.realloc = realloc;
|
|
|
|
mf.pln.free = free;
|
|
|
|
return getdns_list_create_with_extended_memory_functions(
|
2014-03-07 09:42:37 -06:00
|
|
|
MF_PLAIN, mf.ext.malloc, mf.ext.realloc, mf.ext.free);
|
2013-12-08 17:52:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-12 10:00:19 -06:00
|
|
|
/*-------------------------- getdns_list_create_with_context */
|
|
|
|
struct getdns_list *
|
2013-12-06 08:54:06 -06:00
|
|
|
getdns_list_create_with_context(struct getdns_context *context)
|
2013-11-12 10:00:19 -06:00
|
|
|
{
|
|
|
|
if (context)
|
2013-12-08 17:52:38 -06:00
|
|
|
return getdns_list_create_with_extended_memory_functions(
|
2014-03-07 09:42:37 -06:00
|
|
|
context->mf.mf_arg,
|
|
|
|
context->mf.mf.ext.malloc,
|
|
|
|
context->mf.mf.ext.realloc,
|
|
|
|
context->mf.mf.ext.free
|
2013-12-08 17:05:18 -06:00
|
|
|
);
|
2013-11-12 10:00:19 -06:00
|
|
|
else
|
|
|
|
return getdns_list_create_with_memory_functions(malloc,
|
2014-03-07 09:42:37 -06:00
|
|
|
realloc, free);
|
2013-11-11 16:10:22 -06:00
|
|
|
} /* getdns_list_create_with_context */
|
|
|
|
|
|
|
|
/*---------------------------------------- getdns_list_create */
|
|
|
|
struct getdns_list *
|
|
|
|
getdns_list_create()
|
|
|
|
{
|
|
|
|
return getdns_list_create_with_context(NULL);
|
2013-11-05 14:03:44 -06:00
|
|
|
} /* getdns_list_create */
|
2013-07-19 15:19:22 -05:00
|
|
|
|
2013-12-09 09:26:18 -06:00
|
|
|
static void
|
|
|
|
getdns_list_destroy_item(struct getdns_list *list, size_t index)
|
|
|
|
{
|
|
|
|
switch (list->items[index].dtype) {
|
|
|
|
case t_dict:
|
|
|
|
getdns_dict_destroy(list->items[index].data.dict);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case t_list:
|
|
|
|
getdns_list_destroy(list->items[index].data.list);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case t_bindata:
|
|
|
|
getdns_bindata_destroy(&list->mf,
|
2014-03-07 09:42:37 -06:00
|
|
|
list->items[index].data.bindata);
|
2013-12-09 09:26:18 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-19 15:19:22 -05:00
|
|
|
/*---------------------------------------- getdns_list_destroy */
|
2014-03-11 10:43:41 -05:00
|
|
|
void
|
2013-07-19 15:19:22 -05:00
|
|
|
getdns_list_destroy(struct getdns_list *list)
|
|
|
|
{
|
2013-12-09 09:26:18 -06:00
|
|
|
size_t i;
|
2013-11-05 14:03:44 -06:00
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
if (!list)
|
2014-03-11 10:43:41 -05:00
|
|
|
return;
|
2013-11-11 16:10:22 -06:00
|
|
|
|
2013-12-09 09:26:18 -06:00
|
|
|
for (i = 0; i < list->numinuse; i++)
|
|
|
|
getdns_list_destroy_item(list, i);
|
2013-11-11 16:10:22 -06:00
|
|
|
|
|
|
|
if (list->items)
|
2013-12-08 17:05:18 -06:00
|
|
|
GETDNS_FREE(list->mf, list->items);
|
|
|
|
GETDNS_FREE(list->mf, list);
|
2013-11-05 14:03:44 -06:00
|
|
|
} /* getdns_list_destroy */
|
2013-07-19 15:19:22 -05:00
|
|
|
|
|
|
|
/*---------------------------------------- getdns_list_add_item */
|
|
|
|
getdns_return_t
|
2013-11-05 14:03:44 -06:00
|
|
|
getdns_list_add_item(struct getdns_list *list, size_t * index)
|
2013-07-19 15:19:22 -05:00
|
|
|
{
|
2013-11-11 16:10:22 -06:00
|
|
|
getdns_return_t retval;
|
|
|
|
|
|
|
|
if (!list || !index)
|
2014-01-10 09:35:03 -06:00
|
|
|
return GETDNS_RETURN_INVALID_PARAMETER;
|
2013-11-11 16:10:22 -06:00
|
|
|
|
|
|
|
if (list->numalloc == list->numinuse) {
|
|
|
|
retval = getdns_list_realloc(list);
|
|
|
|
if (retval != GETDNS_RETURN_GOOD)
|
|
|
|
return retval;
|
2013-11-05 14:03:44 -06:00
|
|
|
}
|
2013-11-11 16:10:22 -06:00
|
|
|
*index = list->numinuse;
|
2014-03-07 09:42:37 -06:00
|
|
|
list->items[*index].dtype = t_int;
|
|
|
|
list->items[*index].data.n = 0;
|
2013-11-11 16:10:22 -06:00
|
|
|
list->numinuse++;
|
|
|
|
return GETDNS_RETURN_GOOD;
|
2013-11-05 14:03:44 -06:00
|
|
|
} /* getdns_list_add_item */
|
2013-07-15 17:43:30 -05:00
|
|
|
|
2013-07-31 15:21:42 -05:00
|
|
|
/*---------------------------------------- getdns_list_set_dict */
|
|
|
|
getdns_return_t
|
2013-11-05 14:03:44 -06:00
|
|
|
getdns_list_set_dict(struct getdns_list * list, size_t index,
|
2014-03-07 09:42:37 -06:00
|
|
|
const struct getdns_dict * child_dict)
|
2013-07-31 15:21:42 -05:00
|
|
|
{
|
2013-11-11 16:10:22 -06:00
|
|
|
struct getdns_dict *newdict;
|
|
|
|
getdns_return_t retval;
|
|
|
|
|
|
|
|
if (!list || !child_dict)
|
2014-01-10 09:35:03 -06:00
|
|
|
return GETDNS_RETURN_INVALID_PARAMETER;
|
2013-07-31 15:21:42 -05:00
|
|
|
|
2013-12-09 09:26:18 -06:00
|
|
|
if (index > list->numinuse)
|
2013-11-11 16:10:22 -06:00
|
|
|
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
|
|
|
|
|
|
|
|
retval = getdns_dict_copy(child_dict, &newdict);
|
|
|
|
if (retval != GETDNS_RETURN_GOOD)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
if (index == list->numinuse) {
|
|
|
|
retval = getdns_list_add_item(list, &index);
|
2013-12-09 09:26:18 -06:00
|
|
|
if (retval != GETDNS_RETURN_GOOD) {
|
|
|
|
getdns_dict_destroy(newdict);
|
2013-11-11 16:10:22 -06:00
|
|
|
return retval;
|
2013-12-09 09:26:18 -06:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
getdns_list_destroy_item(list, index);
|
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
list->items[index].dtype = t_dict;
|
|
|
|
list->items[index].data.dict = newdict;
|
|
|
|
return GETDNS_RETURN_GOOD;
|
2013-11-05 14:03:44 -06:00
|
|
|
} /* getdns_list_set_dict */
|
2013-07-15 17:43:30 -05:00
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
/*---------------------------------------- getdns_list_set_list */
|
2013-07-22 14:16:40 -05:00
|
|
|
getdns_return_t
|
2013-11-05 14:03:44 -06:00
|
|
|
getdns_list_set_list(struct getdns_list * list, size_t index,
|
2014-03-07 09:42:37 -06:00
|
|
|
const struct getdns_list * child_list)
|
2013-07-22 14:16:40 -05:00
|
|
|
{
|
2013-11-11 16:10:22 -06:00
|
|
|
struct getdns_list *newlist;
|
|
|
|
getdns_return_t retval;
|
|
|
|
|
|
|
|
if (!list || !child_list)
|
2014-01-10 09:35:03 -06:00
|
|
|
return GETDNS_RETURN_INVALID_PARAMETER;
|
2013-11-11 16:10:22 -06:00
|
|
|
|
2013-12-09 09:26:18 -06:00
|
|
|
if (index > list->numinuse)
|
2013-11-11 16:10:22 -06:00
|
|
|
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
|
2013-07-15 17:43:30 -05:00
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
retval = getdns_list_copy(child_list, &newlist);
|
|
|
|
if (retval != GETDNS_RETURN_GOOD)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
if (index == list->numinuse) {
|
|
|
|
retval = getdns_list_add_item(list, &index);
|
2013-12-09 09:26:18 -06:00
|
|
|
if (retval != GETDNS_RETURN_GOOD) {
|
|
|
|
getdns_list_destroy(newlist);
|
2013-11-11 16:10:22 -06:00
|
|
|
return retval;
|
2013-12-09 09:26:18 -06:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
getdns_list_destroy_item(list, index);
|
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
list->items[index].dtype = t_list;
|
|
|
|
list->items[index].data.list = newlist;
|
|
|
|
return GETDNS_RETURN_GOOD;
|
|
|
|
} /* getdns_list_set_list */
|
2013-07-15 17:43:30 -05:00
|
|
|
|
2013-07-22 14:16:40 -05:00
|
|
|
/*---------------------------------------- getdns_list_set_bindata */
|
|
|
|
getdns_return_t
|
2013-11-05 14:03:44 -06:00
|
|
|
getdns_list_set_bindata(struct getdns_list * list, size_t index,
|
2014-03-07 09:42:37 -06:00
|
|
|
const struct getdns_bindata * child_bindata)
|
2013-07-22 14:16:40 -05:00
|
|
|
{
|
2013-11-11 16:10:22 -06:00
|
|
|
struct getdns_bindata *newbindata;
|
|
|
|
getdns_return_t retval;
|
|
|
|
|
|
|
|
if (!list || !child_bindata)
|
2014-01-10 09:35:03 -06:00
|
|
|
return GETDNS_RETURN_INVALID_PARAMETER;
|
2013-11-11 16:10:22 -06:00
|
|
|
|
2013-12-09 09:26:18 -06:00
|
|
|
if (index > list->numinuse)
|
2013-11-11 16:10:22 -06:00
|
|
|
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
|
2013-11-05 14:03:44 -06:00
|
|
|
|
2013-12-08 17:05:18 -06:00
|
|
|
newbindata = getdns_bindata_copy(&list->mf, child_bindata);
|
2013-11-11 16:10:22 -06:00
|
|
|
if (!newbindata)
|
|
|
|
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
|
|
|
|
|
|
|
|
if (index == list->numinuse) {
|
|
|
|
retval = getdns_list_add_item(list, &index);
|
2013-12-09 09:26:18 -06:00
|
|
|
if (retval != GETDNS_RETURN_GOOD) {
|
|
|
|
getdns_bindata_destroy(&list->mf, newbindata);
|
2013-11-11 16:10:22 -06:00
|
|
|
return retval;
|
2013-12-09 09:26:18 -06:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
getdns_list_destroy_item(list, index);
|
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
list->items[index].dtype = t_bindata;
|
|
|
|
list->items[index].data.bindata = newbindata;
|
|
|
|
return GETDNS_RETURN_GOOD;
|
2013-11-05 14:03:44 -06:00
|
|
|
} /* getdns_list_set_bindata */
|
2013-07-22 14:16:40 -05:00
|
|
|
|
|
|
|
/*---------------------------------------- getdns_list_set_int */
|
2013-07-19 15:19:22 -05:00
|
|
|
getdns_return_t
|
2013-11-05 14:03:44 -06:00
|
|
|
getdns_list_set_int(struct getdns_list * list, size_t index,
|
2014-03-07 09:42:37 -06:00
|
|
|
uint32_t child_int)
|
2013-07-19 15:19:22 -05:00
|
|
|
{
|
2013-11-11 16:10:22 -06:00
|
|
|
getdns_return_t retval;
|
2013-11-05 14:03:44 -06:00
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
if (!list)
|
2014-01-10 09:35:03 -06:00
|
|
|
return GETDNS_RETURN_INVALID_PARAMETER;
|
2013-11-05 14:03:44 -06:00
|
|
|
|
2013-12-09 09:26:18 -06:00
|
|
|
if (index > list->numinuse)
|
2013-11-11 16:10:22 -06:00
|
|
|
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
|
2013-07-15 17:43:30 -05:00
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
if (index == list->numinuse) {
|
|
|
|
retval = getdns_list_add_item(list, &index);
|
|
|
|
if (retval != GETDNS_RETURN_GOOD)
|
|
|
|
return retval;
|
2013-12-09 09:26:18 -06:00
|
|
|
} else
|
|
|
|
getdns_list_destroy_item(list, index);
|
|
|
|
|
2013-11-11 16:10:22 -06:00
|
|
|
list->items[index].dtype = t_int;
|
|
|
|
list->items[index].data.n = child_int;
|
|
|
|
return GETDNS_RETURN_GOOD;
|
|
|
|
} /* getdns_list_set_int */
|
2015-02-16 09:01:15 -06:00
|
|
|
|
|
|
|
getdns_return_t
|
|
|
|
getdns_list_append_dict(getdns_list *list, const getdns_dict *child_dict)
|
|
|
|
{
|
|
|
|
if (!list) return GETDNS_RETURN_INVALID_PARAMETER;
|
|
|
|
return getdns_list_set_dict(list, list->numinuse, child_dict);
|
|
|
|
}
|
|
|
|
getdns_return_t
|
|
|
|
getdns_list_append_list(getdns_list *list, const getdns_list *child_list)
|
|
|
|
{
|
|
|
|
if (!list) return GETDNS_RETURN_INVALID_PARAMETER;
|
|
|
|
return getdns_list_set_list(list, list->numinuse, child_list);
|
|
|
|
}
|
|
|
|
getdns_return_t
|
|
|
|
getdns_list_append_bindata(getdns_list *list, const getdns_bindata *child_bindata)
|
|
|
|
{
|
|
|
|
if (!list) return GETDNS_RETURN_INVALID_PARAMETER;
|
|
|
|
return getdns_list_set_bindata(list, list->numinuse, child_bindata);
|
|
|
|
}
|
|
|
|
getdns_return_t
|
|
|
|
getdns_list_append_int(getdns_list *list, uint32_t child_int)
|
|
|
|
{
|
|
|
|
if (!list) return GETDNS_RETURN_INVALID_PARAMETER;
|
|
|
|
return getdns_list_set_int(list, list->numinuse, child_int);
|
|
|
|
}
|
2013-07-15 17:43:30 -05:00
|
|
|
/* getdns_list.c */
|
2013-11-11 16:10:22 -06:00
|
|
|
|