1204076Spjd/*-
2204076Spjd * Copyright (c) 2009-2010 The FreeBSD Foundation
3204076Spjd * All rights reserved.
4204076Spjd *
5204076Spjd * This software was developed by Pawel Jakub Dawidek under sponsorship from
6204076Spjd * the FreeBSD Foundation.
7204076Spjd *
8204076Spjd * Redistribution and use in source and binary forms, with or without
9204076Spjd * modification, are permitted provided that the following conditions
10204076Spjd * are met:
11204076Spjd * 1. Redistributions of source code must retain the above copyright
12204076Spjd *    notice, this list of conditions and the following disclaimer.
13204076Spjd * 2. Redistributions in binary form must reproduce the above copyright
14204076Spjd *    notice, this list of conditions and the following disclaimer in the
15204076Spjd *    documentation and/or other materials provided with the distribution.
16204076Spjd *
17204076Spjd * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18204076Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19204076Spjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20204076Spjd * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21204076Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22204076Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23204076Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24204076Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25204076Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26204076Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27204076Spjd * SUCH DAMAGE.
28204076Spjd *
29204076Spjd * $FreeBSD$
30204076Spjd */
31204076Spjd
32204076Spjd#ifndef	_NV_H_
33204076Spjd#define	_NV_H_
34204076Spjd
35204076Spjd#include <sys/cdefs.h>
36204076Spjd
37204076Spjd#include <stdarg.h>
38204076Spjd#include <stdbool.h>
39204076Spjd#include <stdint.h>
40204076Spjd#include <stdio.h>
41204076Spjd
42204076Spjd#include <ebuf.h>
43204076Spjd
44204076Spjdstruct nv;
45204076Spjd
46204076Spjdstruct nv *nv_alloc(void);
47204076Spjdvoid nv_free(struct nv *nv);
48204076Spjdint nv_error(const struct nv *nv);
49204076Spjdint nv_set_error(struct nv *nv, int error);
50204076Spjdint nv_validate(struct nv *nv, size_t *extrap);
51204076Spjd
52204076Spjdstruct ebuf *nv_hton(struct nv *nv);
53204076Spjdstruct nv *nv_ntoh(struct ebuf *eb);
54204076Spjd
55204076Spjdvoid nv_add_int8(struct nv *nv, int8_t value, const char *namefmt, ...)
56204076Spjd    __printflike(3, 4);
57204076Spjdvoid nv_add_uint8(struct nv *nv, uint8_t value, const char *namefmt, ...)
58204076Spjd    __printflike(3, 4);
59204076Spjdvoid nv_add_int16(struct nv *nv, int16_t value, const char *namefmt, ...)
60204076Spjd    __printflike(3, 4);
61204076Spjdvoid nv_add_uint16(struct nv *nv, uint16_t value, const char *namefmt, ...)
62204076Spjd    __printflike(3, 4);
63204076Spjdvoid nv_add_int32(struct nv *nv, int32_t value, const char *namefmt, ...)
64204076Spjd    __printflike(3, 4);
65204076Spjdvoid nv_add_uint32(struct nv *nv, uint32_t value, const char *namefmt, ...)
66204076Spjd    __printflike(3, 4);
67204076Spjdvoid nv_add_int64(struct nv *nv, int64_t value, const char *namefmt, ...)
68204076Spjd    __printflike(3, 4);
69204076Spjdvoid nv_add_uint64(struct nv *nv, uint64_t value, const char *namefmt, ...)
70204076Spjd    __printflike(3, 4);
71204076Spjdvoid nv_add_int8_array(struct nv *nv, const int8_t *value, size_t size,
72204076Spjd    const char *namefmt, ...) __printflike(4, 5);
73204076Spjdvoid nv_add_uint8_array(struct nv *nv, const uint8_t *value, size_t size,
74204076Spjd    const char *namefmt, ...) __printflike(4, 5);
75204076Spjdvoid nv_add_int16_array(struct nv *nv, const int16_t *value, size_t size,
76204076Spjd    const char *namefmt, ...) __printflike(4, 5);
77204076Spjdvoid nv_add_uint16_array(struct nv *nv, const uint16_t *value, size_t size,
78204076Spjd    const char *namefmt, ...) __printflike(4, 5);
79204076Spjdvoid nv_add_int32_array(struct nv *nv, const int32_t *value, size_t size,
80204076Spjd    const char *namefmt, ...) __printflike(4, 5);
81204076Spjdvoid nv_add_uint32_array(struct nv *nv, const uint32_t *value, size_t size,
82204076Spjd    const char *namefmt, ...) __printflike(4, 5);
83204076Spjdvoid nv_add_int64_array(struct nv *nv, const int64_t *value, size_t size,
84204076Spjd    const char *namefmt, ...) __printflike(4, 5);
85204076Spjdvoid nv_add_uint64_array(struct nv *nv, const uint64_t *value, size_t size,
86204076Spjd    const char *namefmt, ...) __printflike(4, 5);
87204076Spjdvoid nv_add_string(struct nv *nv, const char *value, const char *namefmt, ...)
88204076Spjd    __printflike(3, 4);
89204076Spjdvoid nv_add_stringf(struct nv *nv, const char *name, const char *valuefmt, ...)
90204076Spjd    __printflike(3, 4);
91204076Spjdvoid nv_add_stringv(struct nv *nv, const char *name, const char *valuefmt,
92204076Spjd    va_list valueap) __printflike(3, 0);
93204076Spjd
94204076Spjdint8_t nv_get_int8(struct nv *nv, const char *namefmt, ...)
95204076Spjd    __printflike(2, 3);
96204076Spjduint8_t nv_get_uint8(struct nv *nv, const char *namefmt, ...)
97204076Spjd    __printflike(2, 3);
98204076Spjdint16_t nv_get_int16(struct nv *nv, const char *namefmt, ...)
99204076Spjd    __printflike(2, 3);
100204076Spjduint16_t nv_get_uint16(struct nv *nv, const char *namefmt, ...)
101204076Spjd    __printflike(2, 3);
102204076Spjdint32_t nv_get_int32(struct nv *nv, const char *namefmt, ...)
103204076Spjd    __printflike(2, 3);
104204076Spjduint32_t nv_get_uint32(struct nv *nv, const char *namefmt, ...)
105204076Spjd    __printflike(2, 3);
106204076Spjdint64_t nv_get_int64(struct nv *nv, const char *namefmt, ...)
107204076Spjd    __printflike(2, 3);
108204076Spjduint64_t nv_get_uint64(struct nv *nv, const char *namefmt, ...)
109204076Spjd    __printflike(2, 3);
110204076Spjdconst int8_t *nv_get_int8_array(struct nv *nv, size_t *sizep,
111204076Spjd    const char *namefmt, ...) __printflike(3, 4);
112204076Spjdconst uint8_t *nv_get_uint8_array(struct nv *nv, size_t *sizep,
113204076Spjd    const char *namefmt, ...) __printflike(3, 4);
114204076Spjdconst int16_t *nv_get_int16_array(struct nv *nv, size_t *sizep,
115204076Spjd    const char *namefmt, ...) __printflike(3, 4);
116204076Spjdconst uint16_t *nv_get_uint16_array(struct nv *nv, size_t *sizep,
117204076Spjd    const char *namefmt, ...) __printflike(3, 4);
118204076Spjdconst int32_t *nv_get_int32_array(struct nv *nv, size_t *sizep,
119204076Spjd    const char *namefmt, ...) __printflike(3, 4);
120204076Spjdconst uint32_t *nv_get_uint32_array(struct nv *nv, size_t *sizep,
121204076Spjd    const char *namefmt, ...) __printflike(3, 4);
122204076Spjdconst int64_t *nv_get_int64_array(struct nv *nv, size_t *sizep,
123204076Spjd    const char *namefmt, ...) __printflike(3, 4);
124204076Spjdconst uint64_t *nv_get_uint64_array(struct nv *nv, size_t *sizep,
125204076Spjd    const char *namefmt, ...) __printflike(3, 4);
126204076Spjdconst char *nv_get_string(struct nv *nv, const char *namefmt, ...)
127204076Spjd    __printflike(2, 3);
128204076Spjd
129214283Spjdbool nv_exists(struct nv *nv, const char *namefmt, ...) __printflike(2, 3);
130217732Spjdvoid nv_assert(struct nv *nv, const char *namefmt, ...) __printflike(2, 3);
131204076Spjdvoid nv_dump(struct nv *nv);
132204076Spjd
133204076Spjd#endif	/* !_NV_H_ */
134