1258065Spjd/*- 2258065Spjd * Copyright (c) 2013 The FreeBSD Foundation 3258065Spjd * All rights reserved. 4258065Spjd * 5258065Spjd * This software was developed by Pawel Jakub Dawidek under sponsorship from 6258065Spjd * the FreeBSD Foundation. 7258065Spjd * 8258065Spjd * Redistribution and use in source and binary forms, with or without 9258065Spjd * modification, are permitted provided that the following conditions 10258065Spjd * are met: 11258065Spjd * 1. Redistributions of source code must retain the above copyright 12258065Spjd * notice, this list of conditions and the following disclaimer. 13258065Spjd * 2. Redistributions in binary form must reproduce the above copyright 14258065Spjd * notice, this list of conditions and the following disclaimer in the 15258065Spjd * documentation and/or other materials provided with the distribution. 16258065Spjd * 17258065Spjd * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 18258065Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19258065Spjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20258065Spjd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 21258065Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22258065Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23258065Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24258065Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25258065Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26258065Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27258065Spjd * SUCH DAMAGE. 28258065Spjd * 29258065Spjd * $FreeBSD$ 30258065Spjd */ 31258065Spjd 32258065Spjd#ifndef _DNV_H_ 33258065Spjd#define _DNV_H_ 34258065Spjd 35258065Spjd#include <sys/cdefs.h> 36258065Spjd 37279438Srstone#ifndef _KERNEL 38258065Spjd#include <stdarg.h> 39258065Spjd#include <stdbool.h> 40258065Spjd#include <stdint.h> 41279438Srstone#endif 42258065Spjd 43258065Spjd#ifndef _NVLIST_T_DECLARED 44258065Spjd#define _NVLIST_T_DECLARED 45258065Spjdstruct nvlist; 46258065Spjd 47258065Spjdtypedef struct nvlist nvlist_t; 48258065Spjd#endif 49258065Spjd 50279421Srstone__BEGIN_DECLS 51279421Srstone 52258065Spjd/* 53258065Spjd * The dnvlist_get functions returns value associated with the given name. 54258065Spjd * If it returns a pointer, the pointer represents internal buffer and should 55258065Spjd * not be freed by the caller. 56258065Spjd * If no element of the given name and type exists, the function will return 57258065Spjd * provided default value. 58258065Spjd */ 59258065Spjd 60258065Spjdbool dnvlist_get_bool(const nvlist_t *nvl, const char *name, bool defval); 61258065Spjduint64_t dnvlist_get_number(const nvlist_t *nvl, const char *name, uint64_t defval); 62258065Spjdconst char *dnvlist_get_string(const nvlist_t *nvl, const char *name, const char *defval); 63258065Spjdconst nvlist_t *dnvlist_get_nvlist(const nvlist_t *nvl, const char *name, const nvlist_t *defval); 64258065Spjdint dnvlist_get_descriptor(const nvlist_t *nvl, const char *name, int defval); 65258065Spjdconst void *dnvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep, const void *defval, size_t defsize); 66258065Spjd 67279438Srstone#ifndef _KERNEL 68258065Spjdbool dnvlist_getf_bool(const nvlist_t *nvl, bool defval, const char *namefmt, ...) __printflike(3, 4); 69258065Spjduint64_t dnvlist_getf_number(const nvlist_t *nvl, uint64_t defval, const char *namefmt, ...) __printflike(3, 4); 70258065Spjdconst char *dnvlist_getf_string(const nvlist_t *nvl, const char *defval, const char *namefmt, ...) __printflike(3, 4); 71258065Spjdconst nvlist_t *dnvlist_getf_nvlist(const nvlist_t *nvl, const nvlist_t *defval, const char *namefmt, ...) __printflike(3, 4); 72258065Spjdint dnvlist_getf_descriptor(const nvlist_t *nvl, int defval, const char *namefmt, ...) __printflike(3, 4); 73258065Spjdconst void *dnvlist_getf_binary(const nvlist_t *nvl, size_t *sizep, const void *defval, size_t defsize, const char *namefmt, ...) __printflike(5, 6); 74258065Spjd 75258065Spjdbool dnvlist_getv_bool(const nvlist_t *nvl, bool defval, const char *namefmt, va_list nameap) __printflike(3, 0); 76258065Spjduint64_t dnvlist_getv_number(const nvlist_t *nvl, uint64_t defval, const char *namefmt, va_list nameap) __printflike(3, 0); 77258065Spjdconst char *dnvlist_getv_string(const nvlist_t *nvl, const char *defval, const char *namefmt, va_list nameap) __printflike(3, 0); 78258065Spjdconst nvlist_t *dnvlist_getv_nvlist(const nvlist_t *nvl, const nvlist_t *defval, const char *namefmt, va_list nameap) __printflike(3, 0); 79258065Spjdint dnvlist_getv_descriptor(const nvlist_t *nvl, int defval, const char *namefmt, va_list nameap) __printflike(3, 0); 80258065Spjdconst void *dnvlist_getv_binary(const nvlist_t *nvl, size_t *sizep, const void *defval, size_t defsize, const char *namefmt, va_list nameap) __printflike(5, 0); 81279438Srstone#endif 82258065Spjd 83258065Spjd/* 84258065Spjd * The dnvlist_take functions returns value associated with the given name and 85258065Spjd * remove corresponding nvpair. 86258065Spjd * If it returns a pointer, the caller has to free it. 87258065Spjd * If no element of the given name and type exists, the function will return 88258065Spjd * provided default value. 89258065Spjd */ 90258065Spjd 91258065Spjdbool dnvlist_take_bool(nvlist_t *nvl, const char *name, bool defval); 92258065Spjduint64_t dnvlist_take_number(nvlist_t *nvl, const char *name, uint64_t defval); 93258065Spjdchar *dnvlist_take_string(nvlist_t *nvl, const char *name, char *defval); 94258065Spjdnvlist_t *dnvlist_take_nvlist(nvlist_t *nvl, const char *name, nvlist_t *defval); 95258065Spjdint dnvlist_take_descriptor(nvlist_t *nvl, const char *name, int defval); 96258065Spjdvoid *dnvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep, void *defval, size_t defsize); 97258065Spjd 98279438Srstone#ifndef _KERNEL 99258065Spjdbool dnvlist_takef_bool(nvlist_t *nvl, bool defval, const char *namefmt, ...) __printflike(3, 4); 100258065Spjduint64_t dnvlist_takef_number(nvlist_t *nvl, uint64_t defval, const char *namefmt, ...) __printflike(3, 4); 101258065Spjdchar *dnvlist_takef_string(nvlist_t *nvl, char *defval, const char *namefmt, ...) __printflike(3, 4); 102258065Spjdnvlist_t *dnvlist_takef_nvlist(nvlist_t *nvl, nvlist_t *defval, const char *namefmt, ...) __printflike(3, 4); 103258065Spjdint dnvlist_takef_descriptor(nvlist_t *nvl, int defval, const char *namefmt, ...) __printflike(3, 4); 104258065Spjdvoid *dnvlist_takef_binary(nvlist_t *nvl, size_t *sizep, void *defval, size_t defsize, const char *namefmt, ...) __printflike(5, 6); 105258065Spjd 106258065Spjdbool dnvlist_takev_bool(nvlist_t *nvl, bool defval, const char *namefmt, va_list nameap) __printflike(3, 0); 107258065Spjduint64_t dnvlist_takev_number(nvlist_t *nvl, uint64_t defval, const char *namefmt, va_list nameap) __printflike(3, 0); 108258065Spjdchar *dnvlist_takev_string(nvlist_t *nvl, char *defval, const char *namefmt, va_list nameap) __printflike(3, 0); 109258065Spjdnvlist_t *dnvlist_takev_nvlist(nvlist_t *nvl, nvlist_t *defval, const char *namefmt, va_list nameap) __printflike(3, 0); 110258065Spjdint dnvlist_takev_descriptor(nvlist_t *nvl, int defval, const char *namefmt, va_list nameap) __printflike(3, 0); 111258065Spjdvoid *dnvlist_takev_binary(nvlist_t *nvl, size_t *sizep, void *defval, size_t defsize, const char *namefmt, va_list nameap) __printflike(5, 0); 112279438Srstone#endif 113258065Spjd 114279421Srstone__END_DECLS 115279421Srstone 116258065Spjd#endif /* !_DNV_H_ */ 117