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
68 nvlist_t *nvlist_create(int flags);
69 void nvlist_destroy(nvlist_t *nvl);
70 int nvlist_error(const nvlist_t *nvl);
71 bool nvlist_empty(const nvlist_t *nvl);
73 nvlist_t *nvlist_clone(const nvlist_t *nvl);
75 void nvlist_dump(const nvlist_t *nvl, int fd);
76 void nvlist_fdump(const nvlist_t *nvl, FILE *fp);
78 size_t nvlist_size(const nvlist_t *nvl);
79 void *nvlist_pack(const nvlist_t *nvl, size_t *sizep);
80 nvlist_t *nvlist_unpack(const void *buf, size_t size);
82 int nvlist_send(int sock, const nvlist_t *nvl);
83 nvlist_t *nvlist_recv(int sock);
84 nvlist_t *nvlist_xfer(int sock, nvlist_t *nvl);
86 const char *nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep);
88 const nvlist_t *nvlist_get_parent(const nvlist_t *nvl, void **cookiep);
91 * The nvlist_exists functions check if the given name (optionally of the given
92 * type) exists on nvlist.
95 bool nvlist_exists(const nvlist_t *nvl, const char *name);
96 bool nvlist_exists_type(const nvlist_t *nvl, const char *name, int type);
98 bool nvlist_exists_null(const nvlist_t *nvl, const char *name);
99 bool nvlist_exists_bool(const nvlist_t *nvl, const char *name);
100 bool nvlist_exists_number(const nvlist_t *nvl, const char *name);
101 bool nvlist_exists_string(const nvlist_t *nvl, const char *name);
102 bool nvlist_exists_nvlist(const nvlist_t *nvl, const char *name);
103 bool nvlist_exists_descriptor(const nvlist_t *nvl, const char *name);
104 bool nvlist_exists_binary(const nvlist_t *nvl, const char *name);
107 * The nvlist_add functions add the given name/value pair.
108 * If a pointer is provided, nvlist_add will internally allocate memory for the
109 * given data (in other words it won't consume provided buffer).
112 void nvlist_add_null(nvlist_t *nvl, const char *name);
113 void nvlist_add_bool(nvlist_t *nvl, const char *name, bool value);
114 void nvlist_add_number(nvlist_t *nvl, const char *name, uint64_t value);
115 void nvlist_add_string(nvlist_t *nvl, const char *name, const char *value);
116 void nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...) __printflike(3, 4);
117 void nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt, va_list valueap) __printflike(3, 0);
118 void nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *value);
119 void nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value);
120 void nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value, size_t size);
123 * The nvlist_move functions add the given name/value pair.
124 * The functions consumes provided buffer.
127 void nvlist_move_string(nvlist_t *nvl, const char *name, char *value);
128 void nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value);
129 void nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value);
130 void nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size);
133 * The nvlist_get functions returns value associated with the given name.
134 * If it returns a pointer, the pointer represents internal buffer and should
135 * not be freed by the caller.
138 bool nvlist_get_bool(const nvlist_t *nvl, const char *name);
139 uint64_t nvlist_get_number(const nvlist_t *nvl, const char *name);
140 const char *nvlist_get_string(const nvlist_t *nvl, const char *name);
141 const nvlist_t *nvlist_get_nvlist(const nvlist_t *nvl, const char *name);
142 int nvlist_get_descriptor(const nvlist_t *nvl, const char *name);
143 const void *nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep);
146 * The nvlist_take functions returns value associated with the given name and
147 * remove the given entry from the nvlist.
148 * The caller is responsible for freeing received data.
151 bool nvlist_take_bool(nvlist_t *nvl, const char *name);
152 uint64_t nvlist_take_number(nvlist_t *nvl, const char *name);
153 char *nvlist_take_string(nvlist_t *nvl, const char *name);
154 nvlist_t *nvlist_take_nvlist(nvlist_t *nvl, const char *name);
155 int nvlist_take_descriptor(nvlist_t *nvl, const char *name);
156 void *nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep);
159 * The nvlist_free functions removes the given name/value pair from the nvlist
160 * and frees memory associated with it.
163 void nvlist_free(nvlist_t *nvl, const char *name);
164 void nvlist_free_type(nvlist_t *nvl, const char *name, int type);
166 void nvlist_free_null(nvlist_t *nvl, const char *name);
167 void nvlist_free_bool(nvlist_t *nvl, const char *name);
168 void nvlist_free_number(nvlist_t *nvl, const char *name);
169 void nvlist_free_string(nvlist_t *nvl, const char *name);
170 void nvlist_free_nvlist(nvlist_t *nvl, const char *name);
171 void nvlist_free_descriptor(nvlist_t *nvl, const char *name);
172 void nvlist_free_binary(nvlist_t *nvl, const char *name);
175 * Below are the same functions, but which operate on format strings and
176 * variable argument lists.
179 bool nvlist_existsf(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
180 bool nvlist_existsf_type(const nvlist_t *nvl, int type, const char *namefmt, ...) __printflike(3, 4);
182 bool nvlist_existsf_null(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
183 bool nvlist_existsf_bool(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
184 bool nvlist_existsf_number(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
185 bool nvlist_existsf_string(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
186 bool nvlist_existsf_nvlist(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
187 bool nvlist_existsf_descriptor(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
188 bool nvlist_existsf_binary(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
190 bool nvlist_existsv(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
191 bool nvlist_existsv_type(const nvlist_t *nvl, int type, const char *namefmt, va_list nameap) __printflike(3, 0);
193 bool nvlist_existsv_null(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
194 bool nvlist_existsv_bool(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
195 bool nvlist_existsv_number(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
196 bool nvlist_existsv_string(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
197 bool nvlist_existsv_nvlist(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
198 bool nvlist_existsv_descriptor(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
199 bool nvlist_existsv_binary(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
201 void nvlist_addf_null(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
202 void nvlist_addf_bool(nvlist_t *nvl, bool value, const char *namefmt, ...) __printflike(3, 4);
203 void nvlist_addf_number(nvlist_t *nvl, uint64_t value, const char *namefmt, ...) __printflike(3, 4);
204 void nvlist_addf_string(nvlist_t *nvl, const char *value, const char *namefmt, ...) __printflike(3, 4);
205 void nvlist_addf_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, ...) __printflike(3, 4);
206 void nvlist_addf_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...) __printflike(3, 4);
207 void nvlist_addf_binary(nvlist_t *nvl, const void *value, size_t size, const char *namefmt, ...) __printflike(4, 5);
209 void nvlist_addv_null(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
210 void nvlist_addv_bool(nvlist_t *nvl, bool value, const char *namefmt, va_list nameap) __printflike(3, 0);
211 void nvlist_addv_number(nvlist_t *nvl, uint64_t value, const char *namefmt, va_list nameap) __printflike(3, 0);
212 void nvlist_addv_string(nvlist_t *nvl, const char *value, const char *namefmt, va_list nameap) __printflike(3, 0);
213 void nvlist_addv_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
214 void nvlist_addv_descriptor(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) __printflike(3, 0);
215 void nvlist_addv_binary(nvlist_t *nvl, const void *value, size_t size, const char *namefmt, va_list nameap) __printflike(4, 0);
217 void nvlist_movef_string(nvlist_t *nvl, char *value, const char *namefmt, ...) __printflike(3, 4);
218 void nvlist_movef_nvlist(nvlist_t *nvl, nvlist_t *value, const char *namefmt, ...) __printflike(3, 4);
219 void nvlist_movef_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...) __printflike(3, 4);
220 void nvlist_movef_binary(nvlist_t *nvl, void *value, size_t size, const char *namefmt, ...) __printflike(4, 5);
222 void nvlist_movev_string(nvlist_t *nvl, char *value, const char *namefmt, va_list nameap) __printflike(3, 0);
223 void nvlist_movev_nvlist(nvlist_t *nvl, nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
224 void nvlist_movev_descriptor(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) __printflike(3, 0);
225 void nvlist_movev_binary(nvlist_t *nvl, void *value, size_t size, const char *namefmt, va_list nameap) __printflike(4, 0);
227 bool nvlist_getf_bool(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
228 uint64_t nvlist_getf_number(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
229 const char *nvlist_getf_string(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
230 const nvlist_t *nvlist_getf_nvlist(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
231 int nvlist_getf_descriptor(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
232 const void *nvlist_getf_binary(const nvlist_t *nvl, size_t *sizep, const char *namefmt, ...) __printflike(3, 4);
234 bool nvlist_getv_bool(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
235 uint64_t nvlist_getv_number(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
236 const char *nvlist_getv_string(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
237 const nvlist_t *nvlist_getv_nvlist(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
238 int nvlist_getv_descriptor(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
239 const void *nvlist_getv_binary(const nvlist_t *nvl, size_t *sizep, const char *namefmt, va_list nameap) __printflike(3, 0);
241 bool nvlist_takef_bool(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
242 uint64_t nvlist_takef_number(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
243 char *nvlist_takef_string(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
244 nvlist_t *nvlist_takef_nvlist(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
245 int nvlist_takef_descriptor(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
246 void *nvlist_takef_binary(nvlist_t *nvl, size_t *sizep, const char *namefmt, ...) __printflike(3, 4);
248 bool nvlist_takev_bool(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
249 uint64_t nvlist_takev_number(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
250 char *nvlist_takev_string(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
251 nvlist_t *nvlist_takev_nvlist(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
252 int nvlist_takev_descriptor(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
253 void *nvlist_takev_binary(nvlist_t *nvl, size_t *sizep, const char *namefmt, va_list nameap) __printflike(3, 0);
255 void nvlist_freef(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
256 void nvlist_freef_type(nvlist_t *nvl, int type, const char *namefmt, ...) __printflike(3, 4);
258 void nvlist_freef_null(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
259 void nvlist_freef_bool(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
260 void nvlist_freef_number(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
261 void nvlist_freef_string(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
262 void nvlist_freef_nvlist(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
263 void nvlist_freef_descriptor(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
264 void nvlist_freef_binary(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
266 void nvlist_freev(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
267 void nvlist_freev_type(nvlist_t *nvl, int type, const char *namefmt, va_list nameap) __printflike(3, 0);
269 void nvlist_freev_null(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
270 void nvlist_freev_bool(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
271 void nvlist_freev_number(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
272 void nvlist_freev_string(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
273 void nvlist_freev_nvlist(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
274 void nvlist_freev_descriptor(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
275 void nvlist_freev_binary(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);