]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/nv.h
Remove defunct SSLv2 support from fetch(1) and fetch(3).
[FreeBSD/FreeBSD.git] / sys / sys / nv.h
1 /*-
2  * Copyright (c) 2009-2013 The FreeBSD Foundation
3  * All rights reserved.
4  *
5  * This software was developed by Pawel Jakub Dawidek under sponsorship from
6  * the FreeBSD Foundation.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
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.
16  *
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
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31
32 #ifndef _NV_H_
33 #define _NV_H_
34
35 #include <sys/cdefs.h>
36
37 #ifndef _KERNEL
38 #include <stdarg.h>
39 #include <stdbool.h>
40 #include <stdint.h>
41 #include <stdio.h>
42 #endif
43
44 #ifndef _NVLIST_T_DECLARED
45 #define _NVLIST_T_DECLARED
46 struct nvlist;
47
48 typedef struct nvlist nvlist_t;
49 #endif
50
51 #define NV_NAME_MAX     2048
52
53 #define NV_TYPE_NONE                    0
54
55 #define NV_TYPE_NULL                    1
56 #define NV_TYPE_BOOL                    2
57 #define NV_TYPE_NUMBER                  3
58 #define NV_TYPE_STRING                  4
59 #define NV_TYPE_NVLIST                  5
60 #define NV_TYPE_DESCRIPTOR              6
61 #define NV_TYPE_BINARY                  7
62
63 /*
64  * Perform case-insensitive lookups of provided names.
65  */
66 #define NV_FLAG_IGNORE_CASE             0x01
67
68 #if defined(_KERNEL) && defined(MALLOC_DECLARE)
69 MALLOC_DECLARE(M_NVLIST);
70 #endif
71
72 __BEGIN_DECLS
73
74 nvlist_t        *nvlist_create(int flags);
75 void             nvlist_destroy(nvlist_t *nvl);
76 int              nvlist_error(const nvlist_t *nvl);
77 bool             nvlist_empty(const nvlist_t *nvl);
78 void             nvlist_set_error(nvlist_t *nvl, int error);
79
80 nvlist_t *nvlist_clone(const nvlist_t *nvl);
81
82 #ifndef _KERNEL
83 void nvlist_dump(const nvlist_t *nvl, int fd);
84 void nvlist_fdump(const nvlist_t *nvl, FILE *fp);
85 #endif
86
87 size_t           nvlist_size(const nvlist_t *nvl);
88 void            *nvlist_pack(const nvlist_t *nvl, size_t *sizep);
89 nvlist_t        *nvlist_unpack(const void *buf, size_t size);
90
91 int nvlist_send(int sock, const nvlist_t *nvl);
92 nvlist_t *nvlist_recv(int sock);
93 nvlist_t *nvlist_xfer(int sock, nvlist_t *nvl);
94
95 const char *nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep);
96
97 const nvlist_t *nvlist_get_parent(const nvlist_t *nvl, void **cookiep);
98
99 /*
100  * The nvlist_exists functions check if the given name (optionally of the given
101  * type) exists on nvlist.
102  */
103
104 bool nvlist_exists(const nvlist_t *nvl, const char *name);
105 bool nvlist_exists_type(const nvlist_t *nvl, const char *name, int type);
106
107 bool nvlist_exists_null(const nvlist_t *nvl, const char *name);
108 bool nvlist_exists_bool(const nvlist_t *nvl, const char *name);
109 bool nvlist_exists_number(const nvlist_t *nvl, const char *name);
110 bool nvlist_exists_string(const nvlist_t *nvl, const char *name);
111 bool nvlist_exists_nvlist(const nvlist_t *nvl, const char *name);
112 #ifndef _KERNEL
113 bool nvlist_exists_descriptor(const nvlist_t *nvl, const char *name);
114 #endif
115 bool nvlist_exists_binary(const nvlist_t *nvl, const char *name);
116
117 /*
118  * The nvlist_add functions add the given name/value pair.
119  * If a pointer is provided, nvlist_add will internally allocate memory for the
120  * given data (in other words it won't consume provided buffer).
121  */
122
123 void nvlist_add_null(nvlist_t *nvl, const char *name);
124 void nvlist_add_bool(nvlist_t *nvl, const char *name, bool value);
125 void nvlist_add_number(nvlist_t *nvl, const char *name, uint64_t value);
126 void nvlist_add_string(nvlist_t *nvl, const char *name, const char *value);
127 void nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...) __printflike(3, 4);
128 #ifdef _VA_LIST_DECLARED
129 void nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt, va_list valueap) __printflike(3, 0);
130 #endif
131 void nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *value);
132 #ifndef _KERNEL
133 void nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value);
134 #endif
135 void nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value, size_t size);
136
137 /*
138  * The nvlist_move functions add the given name/value pair.
139  * The functions consumes provided buffer.
140  */
141
142 void nvlist_move_string(nvlist_t *nvl, const char *name, char *value);
143 void nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value);
144 #ifndef _KERNEL
145 void nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value);
146 #endif
147 void nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size);
148
149 /*
150  * The nvlist_get functions returns value associated with the given name.
151  * If it returns a pointer, the pointer represents internal buffer and should
152  * not be freed by the caller.
153  */
154
155 bool             nvlist_get_bool(const nvlist_t *nvl, const char *name);
156 uint64_t         nvlist_get_number(const nvlist_t *nvl, const char *name);
157 const char      *nvlist_get_string(const nvlist_t *nvl, const char *name);
158 const nvlist_t  *nvlist_get_nvlist(const nvlist_t *nvl, const char *name);
159 #ifndef _KERNEL
160 int              nvlist_get_descriptor(const nvlist_t *nvl, const char *name);
161 #endif
162 const void      *nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep);
163
164 /*
165  * The nvlist_take functions returns value associated with the given name and
166  * remove the given entry from the nvlist.
167  * The caller is responsible for freeing received data.
168  */
169
170 bool             nvlist_take_bool(nvlist_t *nvl, const char *name);
171 uint64_t         nvlist_take_number(nvlist_t *nvl, const char *name);
172 char            *nvlist_take_string(nvlist_t *nvl, const char *name);
173 nvlist_t        *nvlist_take_nvlist(nvlist_t *nvl, const char *name);
174 #ifndef _KERNEL
175 int              nvlist_take_descriptor(nvlist_t *nvl, const char *name);
176 #endif
177 void            *nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep);
178
179 /*
180  * The nvlist_free functions removes the given name/value pair from the nvlist
181  * and frees memory associated with it.
182  */
183
184 void nvlist_free(nvlist_t *nvl, const char *name);
185 void nvlist_free_type(nvlist_t *nvl, const char *name, int type);
186
187 void nvlist_free_null(nvlist_t *nvl, const char *name);
188 void nvlist_free_bool(nvlist_t *nvl, const char *name);
189 void nvlist_free_number(nvlist_t *nvl, const char *name);
190 void nvlist_free_string(nvlist_t *nvl, const char *name);
191 void nvlist_free_nvlist(nvlist_t *nvl, const char *name);
192 #ifndef _KERNEL
193 void nvlist_free_descriptor(nvlist_t *nvl, const char *name);
194 #endif
195 void nvlist_free_binary(nvlist_t *nvl, const char *name);
196
197 /*
198  * Below are the same functions, but which operate on format strings and
199  * variable argument lists.
200  *
201  * Functions that are not inserting a new pair into the nvlist cannot handle
202  * a failure to allocate the memory to hold the new name.  Therefore these
203  * functions are not provided in the kernel.
204  */
205
206 #ifndef _KERNEL
207 bool nvlist_existsf(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
208 bool nvlist_existsf_type(const nvlist_t *nvl, int type, const char *namefmt, ...) __printflike(3, 4);
209
210 bool nvlist_existsf_null(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
211 bool nvlist_existsf_bool(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
212 bool nvlist_existsf_number(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
213 bool nvlist_existsf_string(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
214 bool nvlist_existsf_nvlist(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
215 bool nvlist_existsf_descriptor(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
216 bool nvlist_existsf_binary(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
217
218 bool nvlist_existsv(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
219 bool nvlist_existsv_type(const nvlist_t *nvl, int type, const char *namefmt, va_list nameap) __printflike(3, 0);
220
221 bool nvlist_existsv_null(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
222 bool nvlist_existsv_bool(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
223 bool nvlist_existsv_number(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
224 bool nvlist_existsv_string(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
225 bool nvlist_existsv_nvlist(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
226 bool nvlist_existsv_descriptor(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
227 bool nvlist_existsv_binary(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
228 #endif
229
230 void nvlist_addf_null(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
231 void nvlist_addf_bool(nvlist_t *nvl, bool value, const char *namefmt, ...) __printflike(3, 4);
232 void nvlist_addf_number(nvlist_t *nvl, uint64_t value, const char *namefmt, ...) __printflike(3, 4);
233 void nvlist_addf_string(nvlist_t *nvl, const char *value, const char *namefmt, ...) __printflike(3, 4);
234 void nvlist_addf_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, ...) __printflike(3, 4);
235 #ifndef _KERNEL
236 void nvlist_addf_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...) __printflike(3, 4);
237 #endif
238 void nvlist_addf_binary(nvlist_t *nvl, const void *value, size_t size, const char *namefmt, ...) __printflike(4, 5);
239
240 #if !defined(_KERNEL) || defined(_VA_LIST_DECLARED)
241 void nvlist_addv_null(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
242 void nvlist_addv_bool(nvlist_t *nvl, bool value, const char *namefmt, va_list nameap) __printflike(3, 0);
243 void nvlist_addv_number(nvlist_t *nvl, uint64_t value, const char *namefmt, va_list nameap) __printflike(3, 0);
244 void nvlist_addv_string(nvlist_t *nvl, const char *value, const char *namefmt, va_list nameap) __printflike(3, 0);
245 void nvlist_addv_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
246 #ifndef _KERNEL
247 void nvlist_addv_descriptor(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) __printflike(3, 0);
248 #endif
249 void nvlist_addv_binary(nvlist_t *nvl, const void *value, size_t size, const char *namefmt, va_list nameap) __printflike(4, 0);
250 #endif
251
252 void nvlist_movef_string(nvlist_t *nvl, char *value, const char *namefmt, ...) __printflike(3, 4);
253 void nvlist_movef_nvlist(nvlist_t *nvl, nvlist_t *value, const char *namefmt, ...) __printflike(3, 4);
254 #ifndef _KERNEL
255 void nvlist_movef_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...) __printflike(3, 4);
256 #endif
257 void nvlist_movef_binary(nvlist_t *nvl, void *value, size_t size, const char *namefmt, ...) __printflike(4, 5);
258
259 #if !defined(_KERNEL) || defined(_VA_LIST_DECLARED)
260 void nvlist_movev_string(nvlist_t *nvl, char *value, const char *namefmt, va_list nameap) __printflike(3, 0);
261 void nvlist_movev_nvlist(nvlist_t *nvl, nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
262 #ifndef _KERNEL
263 void nvlist_movev_descriptor(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) __printflike(3, 0);
264 #endif
265 void nvlist_movev_binary(nvlist_t *nvl, void *value, size_t size, const char *namefmt, va_list nameap) __printflike(4, 0);
266 #endif
267
268 #ifndef _KERNEL
269 bool             nvlist_getf_bool(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
270 uint64_t         nvlist_getf_number(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
271 const char      *nvlist_getf_string(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
272 const nvlist_t  *nvlist_getf_nvlist(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
273 int              nvlist_getf_descriptor(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
274 const void      *nvlist_getf_binary(const nvlist_t *nvl, size_t *sizep, const char *namefmt, ...) __printflike(3, 4);
275
276 bool             nvlist_getv_bool(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
277 uint64_t         nvlist_getv_number(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
278 const char      *nvlist_getv_string(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
279 const nvlist_t  *nvlist_getv_nvlist(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
280 int              nvlist_getv_descriptor(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
281 const void      *nvlist_getv_binary(const nvlist_t *nvl, size_t *sizep, const char *namefmt, va_list nameap) __printflike(3, 0);
282
283 bool             nvlist_takef_bool(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
284 uint64_t         nvlist_takef_number(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
285 char            *nvlist_takef_string(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
286 nvlist_t        *nvlist_takef_nvlist(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
287 int              nvlist_takef_descriptor(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
288 void            *nvlist_takef_binary(nvlist_t *nvl, size_t *sizep, const char *namefmt, ...) __printflike(3, 4);
289
290 bool             nvlist_takev_bool(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
291 uint64_t         nvlist_takev_number(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
292 char            *nvlist_takev_string(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
293 nvlist_t        *nvlist_takev_nvlist(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
294 int              nvlist_takev_descriptor(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
295 void            *nvlist_takev_binary(nvlist_t *nvl, size_t *sizep, const char *namefmt, va_list nameap) __printflike(3, 0);
296
297 void nvlist_freef(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
298 void nvlist_freef_type(nvlist_t *nvl, int type, const char *namefmt, ...) __printflike(3, 4);
299
300 void nvlist_freef_null(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
301 void nvlist_freef_bool(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
302 void nvlist_freef_number(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
303 void nvlist_freef_string(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
304 void nvlist_freef_nvlist(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
305 void nvlist_freef_descriptor(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
306 void nvlist_freef_binary(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
307
308 void nvlist_freev(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
309 void nvlist_freev_type(nvlist_t *nvl, int type, const char *namefmt, va_list nameap) __printflike(3, 0);
310
311 void nvlist_freev_null(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
312 void nvlist_freev_bool(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
313 void nvlist_freev_number(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
314 void nvlist_freev_string(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
315 void nvlist_freev_nvlist(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
316 void nvlist_freev_descriptor(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
317 void nvlist_freev_binary(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
318 #endif /* _KERNEL */
319
320 __END_DECLS
321
322 #endif  /* !_NV_H_ */