nv.h revision 204076
14Srgrimes/*-
24Srgrimes * Copyright (c) 2009-2010 The FreeBSD Foundation
34Srgrimes * All rights reserved.
4974Sdg *
5974Sdg * This software was developed by Pawel Jakub Dawidek under sponsorship from
64Srgrimes * the FreeBSD Foundation.
74Srgrimes *
84Srgrimes * Redistribution and use in source and binary forms, with or without
94Srgrimes * modification, are permitted provided that the following conditions
104Srgrimes * are met:
114Srgrimes * 1. Redistributions of source code must retain the above copyright
124Srgrimes *    notice, this list of conditions and the following disclaimer.
134Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
144Srgrimes *    notice, this list of conditions and the following disclaimer in the
154Srgrimes *    documentation and/or other materials provided with the distribution.
164Srgrimes *
174Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
184Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
194Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
204Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
214Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
224Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
234Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
244Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
254Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
264Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
274Srgrimes * SUCH DAMAGE.
284Srgrimes *
294Srgrimes * $FreeBSD: head/sbin/hastd/nv.h 204076 2010-02-18 23:16:19Z pjd $
304Srgrimes */
314Srgrimes
324Srgrimes#ifndef	_NV_H_
334Srgrimes#define	_NV_H_
34607Srgrimes
3550477Speter#include <sys/cdefs.h>
364Srgrimes
374Srgrimes#include <stdarg.h>
384Srgrimes#include <stdbool.h>
39719Swollman#include <stdint.h>
40719Swollman#include <stdio.h>
41719Swollman
424Srgrimes#include <ebuf.h>
434Srgrimes
444Srgrimes#define	NV_TYPE_INT8		1
454Srgrimes#define	NV_TYPE_UINT8		2
464Srgrimes#define	NV_TYPE_INT16		3
474Srgrimes#define	NV_TYPE_UINT16		4
484Srgrimes#define	NV_TYPE_INT32		5
4936909Sdg#define	NV_TYPE_UINT32		6
504Srgrimes#define	NV_TYPE_INT64		7
5136909Sdg#define	NV_TYPE_UINT64		8
524Srgrimes#define	NV_TYPE_INT8_ARRAY	9
534Srgrimes#define	NV_TYPE_UINT8_ARRAY	10
5430755Sjkh#define	NV_TYPE_INT16_ARRAY	11
554Srgrimes#define	NV_TYPE_UINT16_ARRAY	12
564Srgrimes#define	NV_TYPE_INT32_ARRAY	13
571288Sdg#define	NV_TYPE_UINT32_ARRAY	14
584Srgrimes#define	NV_TYPE_INT64_ARRAY	15
594Srgrimes#define	NV_TYPE_UINT64_ARRAY	16
60926Sdg#define	NV_TYPE_STRING		17
614Srgrimes
621288Sdg#define	NV_TYPE_MASK		0x7f
631288Sdg#define	NV_TYPE_FIRST		NV_TYPE_INT8
641288Sdg#define	NV_TYPE_LAST		NV_TYPE_STRING
654Srgrimes
664Srgrimes#define	NV_ORDER_NETWORK	0x00
67169291Salc#define	NV_ORDER_HOST		0x80
68169291Salc
69169291Salc#define	NV_ORDER_MASK		0x80
70169291Salc
71169291Salcstruct nv;
72170319Salc
73170319Salcstruct nv *nv_alloc(void);
74170319Salcvoid nv_free(struct nv *nv);
75170319Salcint nv_error(const struct nv *nv);
76170319Salcint nv_set_error(struct nv *nv, int error);
77170319Salcint nv_validate(struct nv *nv, size_t *extrap);
78170319Salc
79170319Salcstruct ebuf *nv_hton(struct nv *nv);
80172317Salcstruct nv *nv_ntoh(struct ebuf *eb);
81170319Salc
82170319Salcvoid nv_add_int8(struct nv *nv, int8_t value, const char *namefmt, ...)
83170319Salc    __printflike(3, 4);
84170319Salcvoid nv_add_uint8(struct nv *nv, uint8_t value, const char *namefmt, ...)
85172317Salc    __printflike(3, 4);
86172317Salcvoid nv_add_int16(struct nv *nv, int16_t value, const char *namefmt, ...)
87170319Salc    __printflike(3, 4);
88170319Salcvoid nv_add_uint16(struct nv *nv, uint16_t value, const char *namefmt, ...)
89170319Salc    __printflike(3, 4);
90170319Salcvoid nv_add_int32(struct nv *nv, int32_t value, const char *namefmt, ...)
91170319Salc    __printflike(3, 4);
92170319Salcvoid nv_add_uint32(struct nv *nv, uint32_t value, const char *namefmt, ...)
93170319Salc    __printflike(3, 4);
94170319Salcvoid nv_add_int64(struct nv *nv, int64_t value, const char *namefmt, ...)
95170319Salc    __printflike(3, 4);
96170319Salcvoid nv_add_uint64(struct nv *nv, uint64_t value, const char *namefmt, ...)
97170319Salc    __printflike(3, 4);
98170319Salcvoid nv_add_int8_array(struct nv *nv, const int8_t *value, size_t size,
99170319Salc    const char *namefmt, ...) __printflike(4, 5);
100170319Salcvoid nv_add_uint8_array(struct nv *nv, const uint8_t *value, size_t size,
101170319Salc    const char *namefmt, ...) __printflike(4, 5);
102170319Salcvoid nv_add_int16_array(struct nv *nv, const int16_t *value, size_t size,
103170319Salc    const char *namefmt, ...) __printflike(4, 5);
104170319Salcvoid nv_add_uint16_array(struct nv *nv, const uint16_t *value, size_t size,
105170319Salc    const char *namefmt, ...) __printflike(4, 5);
106170319Salcvoid nv_add_int32_array(struct nv *nv, const int32_t *value, size_t size,
107170319Salc    const char *namefmt, ...) __printflike(4, 5);
108170319Salcvoid nv_add_uint32_array(struct nv *nv, const uint32_t *value, size_t size,
109170319Salc    const char *namefmt, ...) __printflike(4, 5);
110210550Sjhbvoid nv_add_int64_array(struct nv *nv, const int64_t *value, size_t size,
111210550Sjhb    const char *namefmt, ...) __printflike(4, 5);
112210550Sjhbvoid nv_add_uint64_array(struct nv *nv, const uint64_t *value, size_t size,
113210550Sjhb    const char *namefmt, ...) __printflike(4, 5);
114210550Sjhbvoid nv_add_string(struct nv *nv, const char *value, const char *namefmt, ...)
115210550Sjhb    __printflike(3, 4);
116210550Sjhbvoid nv_add_stringf(struct nv *nv, const char *name, const char *valuefmt, ...)
117177624Salc    __printflike(3, 4);
118174938Salcvoid nv_add_stringv(struct nv *nv, const char *name, const char *valuefmt,
119174938Salc    va_list valueap) __printflike(3, 0);
120177624Salc
121174938Salcint8_t nv_get_int8(struct nv *nv, const char *namefmt, ...)
122174938Salc    __printflike(2, 3);
123174938Salcuint8_t nv_get_uint8(struct nv *nv, const char *namefmt, ...)
124174938Salc    __printflike(2, 3);
125174938Salcint16_t nv_get_int16(struct nv *nv, const char *namefmt, ...)
126174938Salc    __printflike(2, 3);
127174938Salcuint16_t nv_get_uint16(struct nv *nv, const char *namefmt, ...)
128174938Salc    __printflike(2, 3);
129174938Salcint32_t nv_get_int32(struct nv *nv, const char *namefmt, ...)
130174938Salc    __printflike(2, 3);
131174938Salcuint32_t nv_get_uint32(struct nv *nv, const char *namefmt, ...)
132174938Salc    __printflike(2, 3);
133174938Salcint64_t nv_get_int64(struct nv *nv, const char *namefmt, ...)
134174938Salc    __printflike(2, 3);
135174938Salcuint64_t nv_get_uint64(struct nv *nv, const char *namefmt, ...)
136120654Speter    __printflike(2, 3);
137120654Speterconst int8_t *nv_get_int8_array(struct nv *nv, size_t *sizep,
138120654Speter    const char *namefmt, ...) __printflike(3, 4);
139181775Skmacyconst uint8_t *nv_get_uint8_array(struct nv *nv, size_t *sizep,
140181775Skmacy    const char *namefmt, ...) __printflike(3, 4);
141181775Skmacyconst int16_t *nv_get_int16_array(struct nv *nv, size_t *sizep,
142120654Speter    const char *namefmt, ...) __printflike(3, 4);
143120654Speterconst uint16_t *nv_get_uint16_array(struct nv *nv, size_t *sizep,
144181775Skmacy    const char *namefmt, ...) __printflike(3, 4);
145120654Speterconst int32_t *nv_get_int32_array(struct nv *nv, size_t *sizep,
146120654Speter    const char *namefmt, ...) __printflike(3, 4);
14715472Sphkconst uint32_t *nv_get_uint32_array(struct nv *nv, size_t *sizep,
14815472Sphk    const char *namefmt, ...) __printflike(3, 4);
14915472Sphkconst int64_t *nv_get_int64_array(struct nv *nv, size_t *sizep,
15015472Sphk    const char *namefmt, ...) __printflike(3, 4);
1514Srgrimesconst uint64_t *nv_get_uint64_array(struct nv *nv, size_t *sizep,
1524Srgrimes    const char *namefmt, ...) __printflike(3, 4);
153181775Skmacyconst char *nv_get_string(struct nv *nv, const char *namefmt, ...)
154181775Skmacy    __printflike(2, 3);
155181775Skmacy
156113225Sjakevoid nv_dump(struct nv *nv);
157181775Skmacy
158181775Skmacy#endif	/* !_NV_H_ */
15915472Sphk