2 .\" Copyright (c) 2016 Adam Starak <starak.adam@gmail.com>
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .Nd "API for managing name/value pairs by cookie."
41 .Fn cnvlist_name "const void *cookie"
43 .Fn cnvlist_type "const void *cookie"
46 .Fn cnvlist_get_bool "const void *cookie"
48 .Fn cnvlist_get_number "const void *cookie"
50 .Fn cnvlist_get_string "const void *cookie"
51 .Ft "const nvlist_t *"
52 .Fn cnvlist_get_nvlist "const void *cookie"
54 .Fn cnvlist_get_binary "const void *cookie" "size_t *sizep"
56 .Fn cnvlist_get_bool_array "const void *cookie" "size_t *nitemsp"
57 .Ft "const uint64_t *"
58 .Fn cnvlist_get_number_array "const void *cookie" "size_t *nitemsp"
59 .Ft "const char * const *"
60 .Fn cnvlist_get_string_array "const void *cookie" "size_t *nitemsp"
61 .Ft "const nvlist_t * const *"
62 .Fn cnvlist_get_nvlist_array "const void *cookie" "size_t *nitemsp"
64 .Fn cnvlist_get_descriptor "const void *cookie"
66 .Fn cnvlist_get_descriptor_array "const void *cookie" "size_t *nitemsp"
69 .Fn cnvlist_take_bool "void *cookie"
71 .Fn cnvlist_take_number "void *cookie"
73 .Fn cnvlist_take_string "void *cookie"
74 .Ft "const nvlist_t *"
75 .Fn cnvlist_take_nvlist "void *cookie"
77 .Fn cnvlist_take_binary "void *cookie" "size_t *sizep"
79 .Fn cnvlist_take_bool_array "void *cookie" "size_t *nitemsp"
80 .Ft "const uint64_t *"
81 .Fn cnvlist_take_number_array "void *cookie" "size_t *nitemsp"
82 .Ft "const char * const *"
83 .Fn cnvlist_take_string_array "void *cookie" "size_t *nitemsp"
84 .Ft "const nvlist_t * const *"
85 .Fn cnvlist_take_nvlist_array "void *cookie" "size_t *nitemsp"
87 .Fn cnvlist_take_descriptor "void *cookie"
89 .Fn cnvlist_take_descriptor_array "void *cookie" "size_t *nitemsp"
92 .Fn cnvlist_free_null "void *cookie"
94 .Fn cnvlist_free_bool "void *cookie"
96 .Fn cnvlist_free_number "void *cookie"
98 .Fn cnvlist_free_string "void *cookie"
100 .Fn cnvlist_free_nvlist "void *cookie"
102 .Fn cnvlist_free_descriptor "void *cookie"
104 .Fn cnvlist_free_binary "void *cookie"
106 .Fn cnvlist_free_bool_array "void *cookie"
108 .Fn cnvlist_free_number_array "void *cookie"
110 .Fn cnvlist_free_string_array "void *cookie"
112 .Fn cnvlist_free_nvlist_array "void *cookie"
114 .Fn cnvlist_free_descriptor_array "void *cookie"
118 library permits easy management of name/value pairs and can send and receive
120 For more information, also see
123 The concept of cookies is explained in
125 .Fn nvlist_get_parent ,
127 .Fn nvlist_get_pararr
133 function returns the name of an element associated with the given cookie.
137 function returns the type of an element associated with the given cookie.
138 Types which can be returned are described in
143 family of functions obtains the value associated with the given cookie.
144 Returned strings, nvlists, descriptors, binaries, or arrays must not be modified
145 by the user, since they still belong to the nvlist.
146 The nvlist must not be in an error state.
150 family of functions returns the value associated with the given cookie and
151 removes the element from the nvlist.
152 When the value is a string, binary, or array value, the caller is responsible
153 for freeing the returned memory with
155 When the value is an nvlist, the caller is responsible for destroying the
158 When the value is a descriptor, the caller is responsible for closing the
159 returned descriptor with the
164 family of functions removes an element of the supplied cookie and frees all
166 If an element of the given cookie has the wrong type or does not exist, the
170 The following example demonstrates how to deal with cnvlist API.
173 void *cookie, *scookie, *bcookie;
177 nvl = nvlist_create(0);
178 nvlist_add_bool(nvl, "test", 1 == 2);
179 nvlist_add_string(nvl, "test2", "cnvlist");
182 while (nvlist_next(nvl, &type, &cookie) != NULL) {
185 printf("test: %d\\n", cnvlist_get_bool(cookie));
189 printf("test2: %s\\n", cnvlist_get_string(cookie));
195 name = cnvlist_take_string(scookie);
196 cnvlist_free_bool(bcookie);
198 printf("test2: %s\\n", name);
201 printf("nvlist_empty = %d\\n", nvlist_empty(nvl));
213 API was created during the Google Summer Of Code 2016 by