2016-08-27 15:47:52 +02:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 2016 Adam Starak <starak.adam@gmail.com>
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
2018-06-18 23:18:20 +02:00
|
|
|
.Dd June 18, 2018
|
2016-08-27 15:47:52 +02:00
|
|
|
.Dt CNV 9
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
2018-03-17 12:41:06 +01:00
|
|
|
.Nm cnvlist_get ,
|
|
|
|
.Nm cnvlist_take ,
|
|
|
|
.Nm cnvlist_free
|
2016-08-27 15:47:52 +02:00
|
|
|
.Nd "API for managing name/value pairs by cookie."
|
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libnv
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In sys/cnv.h
|
2017-10-26 22:44:42 +02:00
|
|
|
.Ft const char *
|
2018-06-18 23:23:40 +02:00
|
|
|
.Fn cnvlist_name "const void *cookie"
|
2017-10-26 22:44:42 +02:00
|
|
|
.Ft int
|
2018-06-18 23:23:40 +02:00
|
|
|
.Fn cnvlist_type "const void *cookie"
|
2017-10-26 22:44:42 +02:00
|
|
|
.\"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft bool
|
2018-06-18 23:23:40 +02:00
|
|
|
.Fn cnvlist_get_bool "const void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft uint64_t
|
2018-06-18 23:23:40 +02:00
|
|
|
.Fn cnvlist_get_number "const void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const char *"
|
2018-06-18 23:23:40 +02:00
|
|
|
.Fn cnvlist_get_string "const void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const nvlist_t *"
|
2018-06-18 23:23:40 +02:00
|
|
|
.Fn cnvlist_get_nvlist "const void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const void *"
|
2018-06-18 23:23:40 +02:00
|
|
|
.Fn cnvlist_get_binary "const void *cookie" "size_t *sizep"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const bool *"
|
2018-06-18 23:23:40 +02:00
|
|
|
.Fn cnvlist_get_bool_array "const void *cookie" "size_t *nitemsp"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const uint64_t *"
|
2018-06-18 23:23:40 +02:00
|
|
|
.Fn cnvlist_get_number_array "const void *cookie" "size_t *nitemsp"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const char * const *"
|
2018-06-18 23:23:40 +02:00
|
|
|
.Fn cnvlist_get_string_array "const void *cookie" "size_t *nitemsp"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const nvlist_t * const *"
|
2018-06-18 23:23:40 +02:00
|
|
|
.Fn cnvlist_get_nvlist_array "const void *cookie" "size_t *nitemsp"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft int
|
2018-06-18 23:23:40 +02:00
|
|
|
.Fn cnvlist_get_descriptor "const void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const int *"
|
2018-06-18 23:23:40 +02:00
|
|
|
.Fn cnvlist_get_descriptor_array "const void *cookie" "size_t *nitemsp"
|
2016-08-27 15:47:52 +02:00
|
|
|
.\"
|
|
|
|
.Ft bool
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_take_bool "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft uint64_t
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_take_number "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const char *"
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_take_string "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const nvlist_t *"
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_take_nvlist "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const void *"
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_take_binary "void *cookie" "size_t *sizep"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const bool *"
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_take_bool_array "void *cookie" "size_t *nitemsp"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const uint64_t *"
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_take_number_array "void *cookie" "size_t *nitemsp"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const char * const *"
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_take_string_array "void *cookie" "size_t *nitemsp"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft "const nvlist_t * const *"
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_take_nvlist_array "void *cookie" "size_t *nitemsp"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft int
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_take_descriptor "void *cookie"
|
2016-11-23 20:19:11 +01:00
|
|
|
.Ft "const int *"
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_take_descriptor_array "void *cookie" "size_t *nitemsp"
|
2016-08-27 15:47:52 +02:00
|
|
|
.\"
|
|
|
|
.Ft void
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_free_null "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft void
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_free_bool "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft void
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_free_number "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft void
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_free_string "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft void
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_free_nvlist "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft void
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_free_descriptor "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft void
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_free_binary "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft void
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_free_bool_array "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft void
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_free_number_array "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft void
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_free_string_array "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft void
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_free_nvlist_array "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Ft void
|
2018-06-18 23:26:58 +02:00
|
|
|
.Fn cnvlist_free_descriptor_array "void *cookie"
|
2016-08-27 15:47:52 +02:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Nm libnv
|
|
|
|
library permits easy management of name/value pairs and can send and receive
|
|
|
|
them over sockets.
|
|
|
|
For more information, also see
|
|
|
|
.Xr nv 9 .
|
|
|
|
.Pp
|
|
|
|
The concept of cookies is explained in
|
|
|
|
.Fn nvlist_next ,
|
|
|
|
.Fn nvlist_get_parent ,
|
|
|
|
and
|
|
|
|
.Fn nvlist_get_pararr
|
|
|
|
from
|
|
|
|
.Xr nv 9 .
|
|
|
|
.Pp
|
|
|
|
The
|
2017-10-26 22:44:42 +02:00
|
|
|
.Fn cnvlist_name
|
|
|
|
function returns the name of an element associated with the given cookie.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn cnvlist_type
|
|
|
|
function returns the type of an element associated with the given cookie.
|
|
|
|
Types which can be returned are described in
|
|
|
|
.Xr nv 9 .
|
|
|
|
.Pp
|
|
|
|
The
|
2016-08-27 15:47:52 +02:00
|
|
|
.Nm cnvlist_get
|
|
|
|
family of functions obtains the value associated with the given cookie.
|
|
|
|
Returned strings, nvlists, descriptors, binaries, or arrays must not be modified
|
|
|
|
by the user, since they still belong to the nvlist.
|
|
|
|
The nvlist must not be in an error state.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Nm cnvlist_take
|
|
|
|
family of functions returns the value associated with the given cookie and
|
|
|
|
removes the element from the nvlist.
|
|
|
|
When the value is a string, binary, or array value, the caller is responsible
|
|
|
|
for freeing the returned memory with
|
|
|
|
.Fn free 3 .
|
|
|
|
When the value is an nvlist, the caller is responsible for destroying the
|
|
|
|
returned nvlist with
|
|
|
|
.Fn nvlist_destroy .
|
|
|
|
When the value is a descriptor, the caller is responsible for closing the
|
|
|
|
returned descriptor with the
|
|
|
|
.Fn close 2 .
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Nm cnvlist_free
|
|
|
|
family of functions removes an element of the supplied cookie and frees all
|
|
|
|
resources.
|
|
|
|
If an element of the given cookie has the wrong type or does not exist, the
|
|
|
|
program
|
|
|
|
is aborted.
|
2021-01-27 18:18:17 +01:00
|
|
|
.Sh EXAMPLES
|
2016-08-27 15:47:52 +02:00
|
|
|
The following example demonstrates how to deal with cnvlist API.
|
|
|
|
.Bd -literal
|
|
|
|
int type;
|
|
|
|
void *cookie, *scookie, *bcookie;
|
|
|
|
nvlist_t *nvl;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
nvl = nvlist_create(0);
|
|
|
|
nvlist_add_bool(nvl, "test", 1 == 2);
|
|
|
|
nvlist_add_string(nvl, "test2", "cnvlist");
|
|
|
|
cookie = NULL;
|
|
|
|
|
|
|
|
while (nvlist_next(nvl, &type, &cookie) != NULL) {
|
|
|
|
switch (type) {
|
|
|
|
case NV_TYPE_BOOL:
|
|
|
|
printf("test: %d\\n", cnvlist_get_bool(cookie));
|
|
|
|
bcookie = cookie;
|
|
|
|
break;
|
|
|
|
case NV_TYPE_STRING:
|
|
|
|
printf("test2: %s\\n", cnvlist_get_string(cookie));
|
|
|
|
scookie = cookie;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-18 23:26:58 +02:00
|
|
|
name = cnvlist_take_string(scookie);
|
|
|
|
cnvlist_free_bool(bcookie);
|
2016-08-27 15:47:52 +02:00
|
|
|
|
|
|
|
printf("test2: %s\\n", name);
|
|
|
|
free(name);
|
|
|
|
|
|
|
|
printf("nvlist_empty = %d\\n", nvlist_empty(nvl));
|
|
|
|
nvlist_destroy(nvl);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
.Ed
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr close 2 ,
|
2016-11-23 20:19:11 +01:00
|
|
|
.Xr free 3 ,
|
|
|
|
.Xr nv 9
|
2016-08-27 15:47:52 +02:00
|
|
|
.Sh AUTHORS
|
|
|
|
The
|
|
|
|
.Nm cnv
|
|
|
|
API was created during the Google Summer Of Code 2016 by
|
2016-11-23 20:19:11 +01:00
|
|
|
.An Adam Starak .
|