2 * Copyright (c) 2009-2013 The FreeBSD Foundation
5 * This software was developed by Pawel Jakub Dawidek under sponsorship from
6 * the FreeBSD Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
42 #ifndef _NVLIST_T_DECLARED
43 #define _NVLIST_T_DECLARED
46 typedef struct nvlist nvlist_t;
49 #define NV_NAME_MAX 2048
51 #define NV_TYPE_NONE 0
53 #define NV_TYPE_NULL 1
54 #define NV_TYPE_BOOL 2
55 #define NV_TYPE_NUMBER 3
56 #define NV_TYPE_STRING 4
57 #define NV_TYPE_NVLIST 5
58 #define NV_TYPE_DESCRIPTOR 6
59 #define NV_TYPE_BINARY 7
62 * Perform case-insensitive lookups of provided names.
64 #define NV_FLAG_IGNORE_CASE 0x01
66 nvlist_t *nvlist_create(int flags);
67 void nvlist_destroy(nvlist_t *nvl);
68 int nvlist_error(const nvlist_t *nvl);
69 bool nvlist_empty(const nvlist_t *nvl);
71 nvlist_t *nvlist_clone(const nvlist_t *nvl);
73 void nvlist_dump(const nvlist_t *nvl, int fd);
74 void nvlist_fdump(const nvlist_t *nvl, FILE *fp);
76 size_t nvlist_size(const nvlist_t *nvl);
77 void *nvlist_pack(const nvlist_t *nvl, size_t *sizep);
78 nvlist_t *nvlist_unpack(const void *buf, size_t size);
80 int nvlist_send(int sock, const nvlist_t *nvl);
81 nvlist_t *nvlist_recv(int sock);
82 nvlist_t *nvlist_xfer(int sock, nvlist_t *nvl);
84 const char *nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep);
87 * The nvlist_exists functions check if the given name (optionally of the given
88 * type) exists on nvlist.
91 bool nvlist_exists(const nvlist_t *nvl, const char *name);
92 bool nvlist_exists_type(const nvlist_t *nvl, const char *name, int type);
94 bool nvlist_exists_null(const nvlist_t *nvl, const char *name);
95 bool nvlist_exists_bool(const nvlist_t *nvl, const char *name);
96 bool nvlist_exists_number(const nvlist_t *nvl, const char *name);
97 bool nvlist_exists_string(const nvlist_t *nvl, const char *name);
98 bool nvlist_exists_nvlist(const nvlist_t *nvl, const char *name);
99 bool nvlist_exists_descriptor(const nvlist_t *nvl, const char *name);
100 bool nvlist_exists_binary(const nvlist_t *nvl, const char *name);
103 * The nvlist_add functions add the given name/value pair.
104 * If a pointer is provided, nvlist_add will internally allocate memory for the
105 * given data (in other words it won't consume provided buffer).
108 void nvlist_add_null(nvlist_t *nvl, const char *name);
109 void nvlist_add_bool(nvlist_t *nvl, const char *name, bool value);
110 void nvlist_add_number(nvlist_t *nvl, const char *name, uint64_t value);
111 void nvlist_add_string(nvlist_t *nvl, const char *name, const char *value);
112 void nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...) __printflike(3, 4);
113 void nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt, va_list valueap) __printflike(3, 0);
114 void nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *value);
115 void nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value);
116 void nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value, size_t size);
119 * The nvlist_move functions add the given name/value pair.
120 * The functions consumes provided buffer.
123 void nvlist_move_string(nvlist_t *nvl, const char *name, char *value);
124 void nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value);
125 void nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value);
126 void nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size);
129 * The nvlist_get functions returns value associated with the given name.
130 * If it returns a pointer, the pointer represents internal buffer and should
131 * not be freed by the caller.
134 bool nvlist_get_bool(const nvlist_t *nvl, const char *name);
135 uint64_t nvlist_get_number(const nvlist_t *nvl, const char *name);
136 const char *nvlist_get_string(const nvlist_t *nvl, const char *name);
137 const nvlist_t *nvlist_get_nvlist(const nvlist_t *nvl, const char *name);
138 int nvlist_get_descriptor(const nvlist_t *nvl, const char *name);
139 const void *nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep);
142 * The nvlist_take functions returns value associated with the given name and
143 * remove the given entry from the nvlist.
144 * The caller is responsible for freeing received data.
147 bool nvlist_take_bool(nvlist_t *nvl, const char *name);
148 uint64_t nvlist_take_number(nvlist_t *nvl, const char *name);
149 char *nvlist_take_string(nvlist_t *nvl, const char *name);
150 nvlist_t *nvlist_take_nvlist(nvlist_t *nvl, const char *name);
151 int nvlist_take_descriptor(nvlist_t *nvl, const char *name);
152 void *nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep);
155 * The nvlist_free functions removes the given name/value pair from the nvlist
156 * and frees memory associated with it.
159 void nvlist_free(nvlist_t *nvl, const char *name);
160 void nvlist_free_type(nvlist_t *nvl, const char *name, int type);
162 void nvlist_free_null(nvlist_t *nvl, const char *name);
163 void nvlist_free_bool(nvlist_t *nvl, const char *name);
164 void nvlist_free_number(nvlist_t *nvl, const char *name);
165 void nvlist_free_string(nvlist_t *nvl, const char *name);
166 void nvlist_free_nvlist(nvlist_t *nvl, const char *name);
167 void nvlist_free_descriptor(nvlist_t *nvl, const char *name);
168 void nvlist_free_binary(nvlist_t *nvl, const char *name);
171 * Below are the same functions, but which operate on format strings and
172 * variable argument lists.
175 bool nvlist_existsf(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
176 bool nvlist_existsf_type(const nvlist_t *nvl, int type, const char *namefmt, ...) __printflike(3, 4);
178 bool nvlist_existsf_null(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
179 bool nvlist_existsf_bool(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
180 bool nvlist_existsf_number(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
181 bool nvlist_existsf_string(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
182 bool nvlist_existsf_nvlist(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
183 bool nvlist_existsf_descriptor(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
184 bool nvlist_existsf_binary(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
186 bool nvlist_existsv(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
187 bool nvlist_existsv_type(const nvlist_t *nvl, int type, const char *namefmt, va_list nameap) __printflike(3, 0);
189 bool nvlist_existsv_null(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
190 bool nvlist_existsv_bool(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
191 bool nvlist_existsv_number(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
192 bool nvlist_existsv_string(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
193 bool nvlist_existsv_nvlist(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
194 bool nvlist_existsv_descriptor(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
195 bool nvlist_existsv_binary(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
197 void nvlist_addf_null(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
198 void nvlist_addf_bool(nvlist_t *nvl, bool value, const char *namefmt, ...) __printflike(3, 4);
199 void nvlist_addf_number(nvlist_t *nvl, uint64_t value, const char *namefmt, ...) __printflike(3, 4);
200 void nvlist_addf_string(nvlist_t *nvl, const char *value, const char *namefmt, ...) __printflike(3, 4);
201 void nvlist_addf_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, ...) __printflike(3, 4);
202 void nvlist_addf_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...) __printflike(3, 4);
203 void nvlist_addf_binary(nvlist_t *nvl, const void *value, size_t size, const char *namefmt, ...) __printflike(4, 5);
205 void nvlist_addv_null(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
206 void nvlist_addv_bool(nvlist_t *nvl, bool value, const char *namefmt, va_list nameap) __printflike(3, 0);
207 void nvlist_addv_number(nvlist_t *nvl, uint64_t value, const char *namefmt, va_list nameap) __printflike(3, 0);
208 void nvlist_addv_string(nvlist_t *nvl, const char *value, const char *namefmt, va_list nameap) __printflike(3, 0);
209 void nvlist_addv_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
210 void nvlist_addv_descriptor(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) __printflike(3, 0);
211 void nvlist_addv_binary(nvlist_t *nvl, const void *value, size_t size, const char *namefmt, va_list nameap) __printflike(4, 0);
213 void nvlist_movef_string(nvlist_t *nvl, char *value, const char *namefmt, ...) __printflike(3, 4);
214 void nvlist_movef_nvlist(nvlist_t *nvl, nvlist_t *value, const char *namefmt, ...) __printflike(3, 4);
215 void nvlist_movef_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...) __printflike(3, 4);
216 void nvlist_movef_binary(nvlist_t *nvl, void *value, size_t size, const char *namefmt, ...) __printflike(4, 5);
218 void nvlist_movev_string(nvlist_t *nvl, char *value, const char *namefmt, va_list nameap) __printflike(3, 0);
219 void nvlist_movev_nvlist(nvlist_t *nvl, nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
220 void nvlist_movev_descriptor(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) __printflike(3, 0);
221 void nvlist_movev_binary(nvlist_t *nvl, void *value, size_t size, const char *namefmt, va_list nameap) __printflike(4, 0);
223 bool nvlist_getf_bool(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
224 uint64_t nvlist_getf_number(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
225 const char *nvlist_getf_string(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
226 const nvlist_t *nvlist_getf_nvlist(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
227 int nvlist_getf_descriptor(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
228 const void *nvlist_getf_binary(const nvlist_t *nvl, size_t *sizep, const char *namefmt, ...) __printflike(3, 4);
230 bool nvlist_getv_bool(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
231 uint64_t nvlist_getv_number(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
232 const char *nvlist_getv_string(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
233 const nvlist_t *nvlist_getv_nvlist(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
234 int nvlist_getv_descriptor(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
235 const void *nvlist_getv_binary(const nvlist_t *nvl, size_t *sizep, const char *namefmt, va_list nameap) __printflike(3, 0);
237 bool nvlist_takef_bool(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
238 uint64_t nvlist_takef_number(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
239 char *nvlist_takef_string(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
240 nvlist_t *nvlist_takef_nvlist(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
241 int nvlist_takef_descriptor(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
242 void *nvlist_takef_binary(nvlist_t *nvl, size_t *sizep, const char *namefmt, ...) __printflike(3, 4);
244 bool nvlist_takev_bool(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
245 uint64_t nvlist_takev_number(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
246 char *nvlist_takev_string(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
247 nvlist_t *nvlist_takev_nvlist(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
248 int nvlist_takev_descriptor(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
249 void *nvlist_takev_binary(nvlist_t *nvl, size_t *sizep, const char *namefmt, va_list nameap) __printflike(3, 0);
251 void nvlist_freef(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
252 void nvlist_freef_type(nvlist_t *nvl, int type, const char *namefmt, ...) __printflike(3, 4);
254 void nvlist_freef_null(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
255 void nvlist_freef_bool(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
256 void nvlist_freef_number(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
257 void nvlist_freef_string(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
258 void nvlist_freef_nvlist(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
259 void nvlist_freef_descriptor(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
260 void nvlist_freef_binary(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
262 void nvlist_freev(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
263 void nvlist_freev_type(nvlist_t *nvl, int type, const char *namefmt, va_list nameap) __printflike(3, 0);
265 void nvlist_freev_null(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
266 void nvlist_freev_bool(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
267 void nvlist_freev_number(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
268 void nvlist_freev_string(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
269 void nvlist_freev_nvlist(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
270 void nvlist_freev_descriptor(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
271 void nvlist_freev_binary(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);