]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/nv.h
Merge bmake-20150505 improve detection of malformed conditionals.
[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  * Names don't have to be unique.
69  */
70 #define NV_FLAG_NO_UNIQUE               0x02
71
72 #if defined(_KERNEL) && defined(MALLOC_DECLARE)
73 MALLOC_DECLARE(M_NVLIST);
74 #endif
75
76 __BEGIN_DECLS
77
78 nvlist_t        *nvlist_create(int flags);
79 void             nvlist_destroy(nvlist_t *nvl);
80 int              nvlist_error(const nvlist_t *nvl);
81 bool             nvlist_empty(const nvlist_t *nvl);
82 int              nvlist_flags(const nvlist_t *nvl);
83 void             nvlist_set_error(nvlist_t *nvl, int error);
84
85 nvlist_t *nvlist_clone(const nvlist_t *nvl);
86
87 #ifndef _KERNEL
88 void nvlist_dump(const nvlist_t *nvl, int fd);
89 void nvlist_fdump(const nvlist_t *nvl, FILE *fp);
90 #endif
91
92 size_t           nvlist_size(const nvlist_t *nvl);
93 void            *nvlist_pack(const nvlist_t *nvl, size_t *sizep);
94 nvlist_t        *nvlist_unpack(const void *buf, size_t size, int flags);
95
96 int nvlist_send(int sock, const nvlist_t *nvl);
97 nvlist_t *nvlist_recv(int sock, int flags);
98 nvlist_t *nvlist_xfer(int sock, nvlist_t *nvl, int flags);
99
100 const char *nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep);
101
102 const nvlist_t *nvlist_get_parent(const nvlist_t *nvl, void **cookiep);
103
104 /*
105  * The nvlist_exists functions check if the given name (optionally of the given
106  * type) exists on nvlist.
107  */
108
109 bool nvlist_exists(const nvlist_t *nvl, const char *name);
110 bool nvlist_exists_type(const nvlist_t *nvl, const char *name, int type);
111
112 bool nvlist_exists_null(const nvlist_t *nvl, const char *name);
113 bool nvlist_exists_bool(const nvlist_t *nvl, const char *name);
114 bool nvlist_exists_number(const nvlist_t *nvl, const char *name);
115 bool nvlist_exists_string(const nvlist_t *nvl, const char *name);
116 bool nvlist_exists_nvlist(const nvlist_t *nvl, const char *name);
117 #ifndef _KERNEL
118 bool nvlist_exists_descriptor(const nvlist_t *nvl, const char *name);
119 #endif
120 bool nvlist_exists_binary(const nvlist_t *nvl, const char *name);
121
122 /*
123  * The nvlist_add functions add the given name/value pair.
124  * If a pointer is provided, nvlist_add will internally allocate memory for the
125  * given data (in other words it won't consume provided buffer).
126  */
127
128 void nvlist_add_null(nvlist_t *nvl, const char *name);
129 void nvlist_add_bool(nvlist_t *nvl, const char *name, bool value);
130 void nvlist_add_number(nvlist_t *nvl, const char *name, uint64_t value);
131 void nvlist_add_string(nvlist_t *nvl, const char *name, const char *value);
132 void nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...) __printflike(3, 4);
133 #ifdef _VA_LIST_DECLARED
134 void nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt, va_list valueap) __printflike(3, 0);
135 #endif
136 void nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *value);
137 #ifndef _KERNEL
138 void nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value);
139 #endif
140 void nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value, size_t size);
141
142 /*
143  * The nvlist_move functions add the given name/value pair.
144  * The functions consumes provided buffer.
145  */
146
147 void nvlist_move_string(nvlist_t *nvl, const char *name, char *value);
148 void nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value);
149 #ifndef _KERNEL
150 void nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value);
151 #endif
152 void nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size);
153
154 /*
155  * The nvlist_get functions returns value associated with the given name.
156  * If it returns a pointer, the pointer represents internal buffer and should
157  * not be freed by the caller.
158  */
159
160 bool             nvlist_get_bool(const nvlist_t *nvl, const char *name);
161 uint64_t         nvlist_get_number(const nvlist_t *nvl, const char *name);
162 const char      *nvlist_get_string(const nvlist_t *nvl, const char *name);
163 const nvlist_t  *nvlist_get_nvlist(const nvlist_t *nvl, const char *name);
164 #ifndef _KERNEL
165 int              nvlist_get_descriptor(const nvlist_t *nvl, const char *name);
166 #endif
167 const void      *nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep);
168
169 /*
170  * The nvlist_take functions returns value associated with the given name and
171  * remove the given entry from the nvlist.
172  * The caller is responsible for freeing received data.
173  */
174
175 bool             nvlist_take_bool(nvlist_t *nvl, const char *name);
176 uint64_t         nvlist_take_number(nvlist_t *nvl, const char *name);
177 char            *nvlist_take_string(nvlist_t *nvl, const char *name);
178 nvlist_t        *nvlist_take_nvlist(nvlist_t *nvl, const char *name);
179 #ifndef _KERNEL
180 int              nvlist_take_descriptor(nvlist_t *nvl, const char *name);
181 #endif
182 void            *nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep);
183
184 /*
185  * The nvlist_free functions removes the given name/value pair from the nvlist
186  * and frees memory associated with it.
187  */
188
189 void nvlist_free(nvlist_t *nvl, const char *name);
190 void nvlist_free_type(nvlist_t *nvl, const char *name, int type);
191
192 void nvlist_free_null(nvlist_t *nvl, const char *name);
193 void nvlist_free_bool(nvlist_t *nvl, const char *name);
194 void nvlist_free_number(nvlist_t *nvl, const char *name);
195 void nvlist_free_string(nvlist_t *nvl, const char *name);
196 void nvlist_free_nvlist(nvlist_t *nvl, const char *name);
197 #ifndef _KERNEL
198 void nvlist_free_descriptor(nvlist_t *nvl, const char *name);
199 #endif
200 void nvlist_free_binary(nvlist_t *nvl, const char *name);
201
202 __END_DECLS
203
204 #endif  /* !_NV_H_ */