1 /**
2  *
3  * \file list.h
4  * @brief getdns list management functions
5  *
6  * Originally taken from the getdns API description pseudo implementation.
7  *
8  */
9 
10 /*
11  * Copyright (c) 2013, NLnet Labs, Verisign, Inc.
12  * All rights reserved.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are met:
16  * * Redistributions of source code must retain the above copyright
17  *   notice, this list of conditions and the following disclaimer.
18  * * Redistributions in binary form must reproduce the above copyright
19  *   notice, this list of conditions and the following disclaimer in the
20  *   documentation and/or other materials provided with the distribution.
21  * * Neither the names of the copyright holders nor the
22  *   names of its contributors may be used to endorse or promote products
23  *   derived from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28  * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
29  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 #ifndef _GETDNS_LIST_H_
38 #define _GETDNS_LIST_H_
39 
40 #include "getdns/getdns.h"
41 #include "types-internal.h"
42 
43 #define GETDNS_LIST_BLOCKSZ 10
44 
45 /**
46  * getdns list data type
47  * Use helper functions getdns_list_* to manipulate and iterate lists
48  * lists are implemented as arrays internally since the helper functions
49  * like to reference indexes in the list.  Elements are allocated in blocks
50  * and then marked valid as they are used and invalid as they are not used
51  * The use cases do not justify working too hard at shrinking the structures.
52  * Indexes are 0 based.
53  */
54 struct getdns_list
55 {
56 	size_t numalloc;
57 	size_t numinuse;
58 	struct getdns_item *items;
59 	struct mem_funcs mf;
60 };
61 
_getdns_list_create_with_mf(struct mem_funcs * mf)62 static inline getdns_list *_getdns_list_create_with_mf(struct mem_funcs *mf)
63 { return getdns_list_create_with_extended_memory_functions(
64          mf->mf_arg, mf->mf.ext.malloc, mf->mf.ext.realloc, mf->mf.ext.free); }
65 
66 getdns_return_t _getdns_list_find(
67     const getdns_list *dict, const char *key, getdns_item **item);
68 
69 getdns_return_t _getdns_list_find_and_add(
70     getdns_list *list, const char *key, getdns_item **item);
71 
72 getdns_return_t _getdns_list_remove_name(
73     getdns_list *list, const char *name);
74 
75 #endif
76 
77 /* list.h */
78