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_get_bool "void *cookiep"
43 .Fn cnvlist_get_number "void *cookiep"
45 .Fn cnvlist_get_string "void *cookiep"
46 .Ft "const nvlist_t *"
47 .Fn cnvlist_get_nvlist "void *cookiep"
49 .Fn cnvlist_get_binary "void *cookiep" "size_t *sizep"
51 .Fn cnvlist_get_bool_array "void *cookiep" "size_t *nitemsp"
52 .Ft "const uint64_t *"
53 .Fn cnvlist_get_number_array "void *cookiep" "size_t *nitemsp"
54 .Ft "const char * const *"
55 .Fn cnvlist_get_string_array "void *cookiep" "size_t *nitemsp"
56 .Ft "const nvlist_t * const *"
57 .Fn cnvlist_get_nvlist_array "void *cookiep" "size_t *nitemsp"
59 .Fn cnvlist_get_descriptor "void *cookiep"
61 .Fn cnvlist_get_descriptor_array "void *cookiep" "size_t *nitemsp"
64 .Fn cnvlist_take_bool "void *cookiep"
66 .Fn cnvlist_take_number "void *cookiep"
68 .Fn cnvlist_take_string "void *cookiep"
69 .Ft "const nvlist_t *"
70 .Fn cnvlist_take_nvlist "void *cookiep"
72 .Fn cnvlist_take_binary "void *cookiep" "size_t *sizep"
74 .Fn cnvlist_take_bool_array "void *cookiep" "size_t *nitemsp"
75 .Ft "const uint64_t *"
76 .Fn cnvlist_take_number_array "void *cookiep" "size_t *nitemsp"
77 .Ft "const char * const *"
78 .Fn cnvlist_take_string_array "void *cookiep" "size_t *nitemsp"
79 .Ft "const nvlist_t * const *"
80 .Fn cnvlist_take_nvlist_array "void *cookiep" "size_t *nitemsp"
82 .Fn cnvlist_take_descriptor "void *cookiep"
84 .Fn cnvlist_take_descriptor_array "void *cookiep" "size_t *nitemsp"
87 .Fn cnvlist_free_null "nvlist_t *nvl" "void *cookiep"
89 .Fn cnvlist_free_bool "nvlist_t *nvl" "void *cookiep"
91 .Fn cnvlist_free_number "nvlist_t *nvl" "void *cookiep"
93 .Fn cnvlist_free_string "nvlist_t *nvl" "void *cookiep"
95 .Fn cnvlist_free_nvlist "nvlist_t *nvl" "void *cookiep"
97 .Fn cnvlist_free_descriptor "nvlist_t *nvl" "void *cookiep"
99 .Fn cnvlist_free_binary "nvlist_t *nvl" "void *cookiep"
101 .Fn cnvlist_free_bool_array "nvlist_t *nvl" "void *cookiep"
103 .Fn cnvlist_free_number_array "nvlist_t *nvl" "void *cookiep"
105 .Fn cnvlist_free_string_array "nvlist_t *nvl" "void *cookiep"
107 .Fn cnvlist_free_nvlist_array "nvlist_t *nvl" "void *cookiep"
109 .Fn cnvlist_free_descriptor_array "nvlist_t *nvl" "void *cookiep"
113 library permits easy management of name/value pairs and can send and receive
115 For more information, also see
118 The concept of cookies is explained in
120 .Fn nvlist_get_parent ,
122 .Fn nvlist_get_pararr
128 family of functions obtains the value associated with the given cookie.
129 Returned strings, nvlists, descriptors, binaries, or arrays must not be modified
130 by the user, since they still belong to the nvlist.
131 The nvlist must not be in an error state.
135 family of functions returns the value associated with the given cookie and
136 removes the element from the nvlist.
137 When the value is a string, binary, or array value, the caller is responsible
138 for freeing the returned memory with
140 When the value is an nvlist, the caller is responsible for destroying the
143 When the value is a descriptor, the caller is responsible for closing the
144 returned descriptor with the
149 family of functions removes an element of the supplied cookie and frees all
151 If an element of the given cookie has the wrong type or does not exist, the
155 The following example demonstrates how to deal with cnvlist API.
158 void *cookie, *scookie, *bcookie;
162 nvl = nvlist_create(0);
163 nvlist_add_bool(nvl, "test", 1 == 2);
164 nvlist_add_string(nvl, "test2", "cnvlist");
167 while (nvlist_next(nvl, &type, &cookie) != NULL) {
170 printf("test: %d\\n", cnvlist_get_bool(cookie));
174 printf("test2: %s\\n", cnvlist_get_string(cookie));
180 name = cnvlist_take_string(nvl, scookie);
181 cnvlist_free_bool(nvl, bcookie);
183 printf("test2: %s\\n", name);
186 printf("nvlist_empty = %d\\n", nvlist_empty(nvl));
198 API was created during the Google Summer Of Code 2016 by