xref: /freebsd/share/man/man9/cnv.9 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
17dcd0f0eSMariusz Zaborski.\"
27dcd0f0eSMariusz Zaborski.\" Copyright (c) 2016 Adam Starak <starak.adam@gmail.com>
37dcd0f0eSMariusz Zaborski.\" All rights reserved.
47dcd0f0eSMariusz Zaborski.\"
57dcd0f0eSMariusz Zaborski.\" Redistribution and use in source and binary forms, with or without
67dcd0f0eSMariusz Zaborski.\" modification, are permitted provided that the following conditions
77dcd0f0eSMariusz Zaborski.\" are met:
87dcd0f0eSMariusz Zaborski.\" 1. Redistributions of source code must retain the above copyright
97dcd0f0eSMariusz Zaborski.\"    notice, this list of conditions and the following disclaimer.
107dcd0f0eSMariusz Zaborski.\" 2. Redistributions in binary form must reproduce the above copyright
117dcd0f0eSMariusz Zaborski.\"    notice, this list of conditions and the following disclaimer in the
127dcd0f0eSMariusz Zaborski.\"    documentation and/or other materials provided with the distribution.
137dcd0f0eSMariusz Zaborski.\"
147dcd0f0eSMariusz Zaborski.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
157dcd0f0eSMariusz Zaborski.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
167dcd0f0eSMariusz Zaborski.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
177dcd0f0eSMariusz Zaborski.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
187dcd0f0eSMariusz Zaborski.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
197dcd0f0eSMariusz Zaborski.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
207dcd0f0eSMariusz Zaborski.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
217dcd0f0eSMariusz Zaborski.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
227dcd0f0eSMariusz Zaborski.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
237dcd0f0eSMariusz Zaborski.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
247dcd0f0eSMariusz Zaborski.\" SUCH DAMAGE.
257dcd0f0eSMariusz Zaborski.\"
260db44d55SMariusz Zaborski.Dd June 18, 2018
277dcd0f0eSMariusz Zaborski.Dt CNV 9
287dcd0f0eSMariusz Zaborski.Os
297dcd0f0eSMariusz Zaborski.Sh NAME
307dcd0f0eSMariusz Zaborski.Nm cnvlist_get ,
317dcd0f0eSMariusz Zaborski.Nm cnvlist_take ,
327651c3afSEdward Tomasz Napierala.Nm cnvlist_free
337dcd0f0eSMariusz Zaborski.Nd "API for managing name/value pairs by cookie."
347dcd0f0eSMariusz Zaborski.Sh LIBRARY
357dcd0f0eSMariusz Zaborski.Lb libnv
367dcd0f0eSMariusz Zaborski.Sh SYNOPSIS
377dcd0f0eSMariusz Zaborski.In sys/cnv.h
3823c5a51eSMariusz Zaborski.Ft const char *
3930665f3cSMariusz Zaborski.Fn cnvlist_name "const void *cookie"
4023c5a51eSMariusz Zaborski.Ft int
4130665f3cSMariusz Zaborski.Fn cnvlist_type "const void *cookie"
4223c5a51eSMariusz Zaborski.\"
437dcd0f0eSMariusz Zaborski.Ft bool
4430665f3cSMariusz Zaborski.Fn cnvlist_get_bool "const void *cookie"
457dcd0f0eSMariusz Zaborski.Ft uint64_t
4630665f3cSMariusz Zaborski.Fn cnvlist_get_number "const void *cookie"
477dcd0f0eSMariusz Zaborski.Ft "const char *"
4830665f3cSMariusz Zaborski.Fn cnvlist_get_string "const void *cookie"
497dcd0f0eSMariusz Zaborski.Ft "const nvlist_t *"
5030665f3cSMariusz Zaborski.Fn cnvlist_get_nvlist "const void *cookie"
517dcd0f0eSMariusz Zaborski.Ft "const void *"
5230665f3cSMariusz Zaborski.Fn cnvlist_get_binary "const void *cookie" "size_t *sizep"
537dcd0f0eSMariusz Zaborski.Ft "const bool *"
5430665f3cSMariusz Zaborski.Fn cnvlist_get_bool_array "const void *cookie" "size_t *nitemsp"
557dcd0f0eSMariusz Zaborski.Ft "const uint64_t *"
5630665f3cSMariusz Zaborski.Fn cnvlist_get_number_array "const void *cookie" "size_t *nitemsp"
577dcd0f0eSMariusz Zaborski.Ft "const char * const *"
5830665f3cSMariusz Zaborski.Fn cnvlist_get_string_array "const void *cookie" "size_t *nitemsp"
597dcd0f0eSMariusz Zaborski.Ft "const nvlist_t * const *"
6030665f3cSMariusz Zaborski.Fn cnvlist_get_nvlist_array "const void *cookie" "size_t *nitemsp"
617dcd0f0eSMariusz Zaborski.Ft int
6230665f3cSMariusz Zaborski.Fn cnvlist_get_descriptor "const void *cookie"
637dcd0f0eSMariusz Zaborski.Ft "const int *"
6430665f3cSMariusz Zaborski.Fn cnvlist_get_descriptor_array "const void *cookie" "size_t *nitemsp"
657dcd0f0eSMariusz Zaborski.\"
667dcd0f0eSMariusz Zaborski.Ft bool
67d82e41b6SMariusz Zaborski.Fn cnvlist_take_bool "void *cookie"
687dcd0f0eSMariusz Zaborski.Ft uint64_t
69d82e41b6SMariusz Zaborski.Fn cnvlist_take_number "void *cookie"
707dcd0f0eSMariusz Zaborski.Ft "const char *"
71d82e41b6SMariusz Zaborski.Fn cnvlist_take_string "void *cookie"
727dcd0f0eSMariusz Zaborski.Ft "const nvlist_t *"
73d82e41b6SMariusz Zaborski.Fn cnvlist_take_nvlist "void *cookie"
747dcd0f0eSMariusz Zaborski.Ft "const void *"
75d82e41b6SMariusz Zaborski.Fn cnvlist_take_binary "void *cookie" "size_t *sizep"
767dcd0f0eSMariusz Zaborski.Ft "const bool *"
77d82e41b6SMariusz Zaborski.Fn cnvlist_take_bool_array "void *cookie" "size_t *nitemsp"
787dcd0f0eSMariusz Zaborski.Ft "const uint64_t *"
79d82e41b6SMariusz Zaborski.Fn cnvlist_take_number_array "void *cookie" "size_t *nitemsp"
807dcd0f0eSMariusz Zaborski.Ft "const char * const *"
81d82e41b6SMariusz Zaborski.Fn cnvlist_take_string_array "void *cookie" "size_t *nitemsp"
827dcd0f0eSMariusz Zaborski.Ft "const nvlist_t * const *"
83d82e41b6SMariusz Zaborski.Fn cnvlist_take_nvlist_array "void *cookie" "size_t *nitemsp"
847dcd0f0eSMariusz Zaborski.Ft int
85d82e41b6SMariusz Zaborski.Fn cnvlist_take_descriptor "void *cookie"
86c85d7166SChristian Brueffer.Ft "const int *"
87d82e41b6SMariusz Zaborski.Fn cnvlist_take_descriptor_array "void *cookie" "size_t *nitemsp"
887dcd0f0eSMariusz Zaborski.\"
897dcd0f0eSMariusz Zaborski.Ft void
90d82e41b6SMariusz Zaborski.Fn cnvlist_free_null "void *cookie"
917dcd0f0eSMariusz Zaborski.Ft void
92d82e41b6SMariusz Zaborski.Fn cnvlist_free_bool "void *cookie"
937dcd0f0eSMariusz Zaborski.Ft void
94d82e41b6SMariusz Zaborski.Fn cnvlist_free_number "void *cookie"
957dcd0f0eSMariusz Zaborski.Ft void
96d82e41b6SMariusz Zaborski.Fn cnvlist_free_string "void *cookie"
977dcd0f0eSMariusz Zaborski.Ft void
98d82e41b6SMariusz Zaborski.Fn cnvlist_free_nvlist "void *cookie"
997dcd0f0eSMariusz Zaborski.Ft void
100d82e41b6SMariusz Zaborski.Fn cnvlist_free_descriptor "void *cookie"
1017dcd0f0eSMariusz Zaborski.Ft void
102d82e41b6SMariusz Zaborski.Fn cnvlist_free_binary "void *cookie"
1037dcd0f0eSMariusz Zaborski.Ft void
104d82e41b6SMariusz Zaborski.Fn cnvlist_free_bool_array "void *cookie"
1057dcd0f0eSMariusz Zaborski.Ft void
106d82e41b6SMariusz Zaborski.Fn cnvlist_free_number_array "void *cookie"
1077dcd0f0eSMariusz Zaborski.Ft void
108d82e41b6SMariusz Zaborski.Fn cnvlist_free_string_array "void *cookie"
1097dcd0f0eSMariusz Zaborski.Ft void
110d82e41b6SMariusz Zaborski.Fn cnvlist_free_nvlist_array "void *cookie"
1117dcd0f0eSMariusz Zaborski.Ft void
112d82e41b6SMariusz Zaborski.Fn cnvlist_free_descriptor_array "void *cookie"
1137dcd0f0eSMariusz Zaborski.Sh DESCRIPTION
1147dcd0f0eSMariusz ZaborskiThe
1157dcd0f0eSMariusz Zaborski.Nm libnv
1167dcd0f0eSMariusz Zaborskilibrary permits easy management of name/value pairs and can send and receive
1177dcd0f0eSMariusz Zaborskithem over sockets.
1187dcd0f0eSMariusz ZaborskiFor more information, also see
1197dcd0f0eSMariusz Zaborski.Xr nv 9 .
1207dcd0f0eSMariusz Zaborski.Pp
1217dcd0f0eSMariusz ZaborskiThe concept of cookies is explained in
1227dcd0f0eSMariusz Zaborski.Fn nvlist_next ,
1237dcd0f0eSMariusz Zaborski.Fn nvlist_get_parent ,
1247dcd0f0eSMariusz Zaborskiand
1257dcd0f0eSMariusz Zaborski.Fn nvlist_get_pararr
1267dcd0f0eSMariusz Zaborskifrom
1277dcd0f0eSMariusz Zaborski.Xr nv 9 .
1287dcd0f0eSMariusz Zaborski.Pp
1297dcd0f0eSMariusz ZaborskiThe
13023c5a51eSMariusz Zaborski.Fn cnvlist_name
13123c5a51eSMariusz Zaborskifunction returns the name of an element associated with the given cookie.
13223c5a51eSMariusz Zaborski.Pp
13323c5a51eSMariusz ZaborskiThe
13423c5a51eSMariusz Zaborski.Fn cnvlist_type
13523c5a51eSMariusz Zaborskifunction returns the type of an element associated with the given cookie.
13623c5a51eSMariusz ZaborskiTypes which can be returned are described in
13723c5a51eSMariusz Zaborski.Xr nv 9 .
13823c5a51eSMariusz Zaborski.Pp
13923c5a51eSMariusz ZaborskiThe
1407dcd0f0eSMariusz Zaborski.Nm cnvlist_get
1417dcd0f0eSMariusz Zaborskifamily of functions obtains the value associated with the given cookie.
1427dcd0f0eSMariusz ZaborskiReturned strings, nvlists, descriptors, binaries, or arrays must not be modified
1437dcd0f0eSMariusz Zaborskiby the user, since they still belong to the nvlist.
1447dcd0f0eSMariusz ZaborskiThe nvlist must not be in an error state.
1457dcd0f0eSMariusz Zaborski.Pp
1467dcd0f0eSMariusz ZaborskiThe
1477dcd0f0eSMariusz Zaborski.Nm cnvlist_take
1487dcd0f0eSMariusz Zaborskifamily of functions returns the value associated with the given cookie and
1497dcd0f0eSMariusz Zaborskiremoves the element from the nvlist.
1507dcd0f0eSMariusz ZaborskiWhen the value is a string, binary, or array value, the caller is responsible
1517dcd0f0eSMariusz Zaborskifor freeing the returned memory with
1527dcd0f0eSMariusz Zaborski.Fn free 3 .
1537dcd0f0eSMariusz ZaborskiWhen the value is an nvlist, the caller is responsible for destroying the
1547dcd0f0eSMariusz Zaborskireturned nvlist with
1557dcd0f0eSMariusz Zaborski.Fn nvlist_destroy .
1567dcd0f0eSMariusz ZaborskiWhen the value is a descriptor, the caller is responsible for closing the
1577dcd0f0eSMariusz Zaborskireturned descriptor with the
1587dcd0f0eSMariusz Zaborski.Fn close 2 .
1597dcd0f0eSMariusz Zaborski.Pp
1607dcd0f0eSMariusz ZaborskiThe
1617dcd0f0eSMariusz Zaborski.Nm cnvlist_free
1627dcd0f0eSMariusz Zaborskifamily of functions removes an element of the supplied cookie and frees all
1637dcd0f0eSMariusz Zaborskiresources.
1647dcd0f0eSMariusz ZaborskiIf an element of the given cookie has the wrong type or does not exist, the
1657dcd0f0eSMariusz Zaborskiprogram
1667dcd0f0eSMariusz Zaborskiis aborted.
167*8dba3dd8SGordon Bergling.Sh EXAMPLES
1687dcd0f0eSMariusz ZaborskiThe following example demonstrates how to deal with cnvlist API.
1697dcd0f0eSMariusz Zaborski.Bd -literal
1707dcd0f0eSMariusz Zaborskiint type;
1717dcd0f0eSMariusz Zaborskivoid *cookie, *scookie, *bcookie;
1727dcd0f0eSMariusz Zaborskinvlist_t *nvl;
1737dcd0f0eSMariusz Zaborskichar *name;
1747dcd0f0eSMariusz Zaborski
1757dcd0f0eSMariusz Zaborskinvl = nvlist_create(0);
1767dcd0f0eSMariusz Zaborskinvlist_add_bool(nvl, "test", 1 == 2);
1777dcd0f0eSMariusz Zaborskinvlist_add_string(nvl, "test2", "cnvlist");
1787dcd0f0eSMariusz Zaborskicookie = NULL;
1797dcd0f0eSMariusz Zaborski
1807dcd0f0eSMariusz Zaborskiwhile (nvlist_next(nvl, &type, &cookie) != NULL) {
1817dcd0f0eSMariusz Zaborski        switch (type) {
1827dcd0f0eSMariusz Zaborski        case NV_TYPE_BOOL:
1837dcd0f0eSMariusz Zaborski                printf("test: %d\\n", cnvlist_get_bool(cookie));
1847dcd0f0eSMariusz Zaborski                bcookie = cookie;
1857dcd0f0eSMariusz Zaborski                break;
1867dcd0f0eSMariusz Zaborski        case NV_TYPE_STRING:
1877dcd0f0eSMariusz Zaborski                printf("test2: %s\\n", cnvlist_get_string(cookie));
1887dcd0f0eSMariusz Zaborski                scookie = cookie;
1897dcd0f0eSMariusz Zaborski                break;
1907dcd0f0eSMariusz Zaborski        }
1917dcd0f0eSMariusz Zaborski}
1927dcd0f0eSMariusz Zaborski
193d82e41b6SMariusz Zaborskiname = cnvlist_take_string(scookie);
194d82e41b6SMariusz Zaborskicnvlist_free_bool(bcookie);
1957dcd0f0eSMariusz Zaborski
1967dcd0f0eSMariusz Zaborskiprintf("test2: %s\\n", name);
1977dcd0f0eSMariusz Zaborskifree(name);
1987dcd0f0eSMariusz Zaborski
1997dcd0f0eSMariusz Zaborskiprintf("nvlist_empty = %d\\n", nvlist_empty(nvl));
2007dcd0f0eSMariusz Zaborskinvlist_destroy(nvl);
2017dcd0f0eSMariusz Zaborski
2027dcd0f0eSMariusz Zaborskireturn (0);
2037dcd0f0eSMariusz Zaborski.Ed
2047dcd0f0eSMariusz Zaborski.Sh SEE ALSO
2057dcd0f0eSMariusz Zaborski.Xr close 2 ,
206c85d7166SChristian Brueffer.Xr free 3 ,
207c85d7166SChristian Brueffer.Xr nv 9
2087dcd0f0eSMariusz Zaborski.Sh AUTHORS
2097dcd0f0eSMariusz ZaborskiThe
2107dcd0f0eSMariusz Zaborski.Nm cnv
2117dcd0f0eSMariusz ZaborskiAPI was created during the Google Summer Of Code 2016 by
212c85d7166SChristian Brueffer.An Adam Starak .
213