1168404Spjd/* 2168404Spjd * CDDL HEADER START 3168404Spjd * 4168404Spjd * The contents of this file are subject to the terms of the 5185029Spjd * Common Development and Distribution License (the "License"). 6185029Spjd * You may not use this file except in compliance with the License. 7168404Spjd * 8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9168404Spjd * or http://www.opensolaris.org/os/licensing. 10168404Spjd * See the License for the specific language governing permissions 11168404Spjd * and limitations under the License. 12168404Spjd * 13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each 14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15168404Spjd * If applicable, add the following below this CDDL HEADER, with the 16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying 17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner] 18168404Spjd * 19168404Spjd * CDDL HEADER END 20168404Spjd */ 21168404Spjd/* 22219089Spjd * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 23277589Sdelphij * Copyright (c) 2013, Joyent, Inc. All rights reserved. 24168404Spjd */ 25168404Spjd 26168404Spjd#ifndef _LIBNVPAIR_H 27168404Spjd#define _LIBNVPAIR_H 28168404Spjd 29168404Spjd#include <sys/nvpair.h> 30168404Spjd#include <stdlib.h> 31168404Spjd#include <stdio.h> 32185029Spjd#include <regex.h> 33168404Spjd 34168404Spjd#ifdef __cplusplus 35168404Spjdextern "C" { 36168404Spjd#endif 37168404Spjd 38219089Spjd/* 39219089Spjd * All interfaces described in this file are private to Solaris, and 40219089Spjd * are subject to change at any time and without notice. The public 41219089Spjd * nvlist/nvpair interfaces, as documented in manpage sections 3NVPAIR, 42219089Spjd * are all imported from <sys/nvpair.h> included above. 43219089Spjd */ 44168404Spjd 45219089Spjdextern int nvpair_value_match(nvpair_t *, int, char *, char **); 46219089Spjdextern int nvpair_value_match_regex(nvpair_t *, int, char *, regex_t *, 47219089Spjd char **); 48219089Spjd 49219089Spjdextern void nvlist_print(FILE *, nvlist_t *); 50277589Sdelphijextern int nvlist_print_json(FILE *, nvlist_t *); 51219089Spjdextern void dump_nvlist(nvlist_t *, int); 52219089Spjd 53219089Spjd/* 54219089Spjd * Private nvlist printing interface that allows the caller some control 55219089Spjd * over output rendering (as opposed to nvlist_print and dump_nvlist). 56219089Spjd * 57219089Spjd * Obtain an opaque nvlist_prtctl_t cookie using nvlist_prtctl_alloc 58219089Spjd * (NULL on failure); on return the cookie is set up for default formatting 59219089Spjd * and rendering. Quote the cookie in subsequent customisation functions and 60219089Spjd * then pass the cookie to nvlist_prt to render the nvlist. Finally, 61219089Spjd * use nvlist_prtctl_free to release the cookie. 62219089Spjd * 63219089Spjd * For all nvlist_lookup_xxx and nvlist_lookup_xxx_array functions 64219089Spjd * we have a corresponding brace of functions that appoint replacement 65219089Spjd * rendering functions: 66219089Spjd * 67219089Spjd * extern void nvlist_prtctl_xxx(nvlist_prtctl_t, 68219089Spjd * void (*)(nvlist_prtctl_t ctl, void *private, const char *name, 69219089Spjd * xxxtype value)) 70219089Spjd * 71219089Spjd * and 72219089Spjd * 73219089Spjd * extern void nvlist_prtctl_xxx_array(nvlist_prtctl_t, 74219089Spjd * void (*)(nvlist_prtctl_t ctl, void *private, const char *name, 75219089Spjd * xxxtype value, uint_t count)) 76219089Spjd * 77219089Spjd * where xxxtype is the C datatype corresponding to xxx, eg int8_t for "int8" 78219089Spjd * and char * for "string". The function that is appointed to render the 79219089Spjd * specified datatype receives as arguments the cookie, the nvlist 80219089Spjd * member name, the value of that member (or a pointer for array function), 81219089Spjd * and (for array rendering functions) a count of the number of elements. 82219089Spjd */ 83219089Spjd 84219089Spjdtypedef struct nvlist_prtctl *nvlist_prtctl_t; /* opaque */ 85219089Spjd 86219089Spjdenum nvlist_indent_mode { 87219089Spjd NVLIST_INDENT_ABS, /* Absolute indentation */ 88219089Spjd NVLIST_INDENT_TABBED /* Indent with tabstops */ 89219089Spjd}; 90219089Spjd 91219089Spjdextern nvlist_prtctl_t nvlist_prtctl_alloc(void); 92219089Spjdextern void nvlist_prtctl_free(nvlist_prtctl_t); 93219089Spjdextern void nvlist_prt(nvlist_t *, nvlist_prtctl_t); 94219089Spjd 95219089Spjd/* Output stream */ 96219089Spjdextern void nvlist_prtctl_setdest(nvlist_prtctl_t, FILE *); 97219089Spjdextern FILE *nvlist_prtctl_getdest(nvlist_prtctl_t); 98219089Spjd 99219089Spjd/* Indentation mode, start indent, indent increment; default tabbed/0/1 */ 100219089Spjdextern void nvlist_prtctl_setindent(nvlist_prtctl_t, enum nvlist_indent_mode, 101219089Spjd int, int); 102219089Spjdextern void nvlist_prtctl_doindent(nvlist_prtctl_t, int); 103219089Spjd 104219089Spjdenum nvlist_prtctl_fmt { 105219089Spjd NVLIST_FMT_MEMBER_NAME, /* name fmt; default "%s = " */ 106219089Spjd NVLIST_FMT_MEMBER_POSTAMBLE, /* after nvlist member; default "\n" */ 107219089Spjd NVLIST_FMT_BTWN_ARRAY /* between array members; default " " */ 108219089Spjd}; 109219089Spjd 110219089Spjdextern void nvlist_prtctl_setfmt(nvlist_prtctl_t, enum nvlist_prtctl_fmt, 111219089Spjd const char *); 112219089Spjdextern void nvlist_prtctl_dofmt(nvlist_prtctl_t, enum nvlist_prtctl_fmt, ...); 113219089Spjd 114219089Spjd/* 115219089Spjd * Function prototypes for interfaces that appoint a new rendering function 116219089Spjd * for single-valued nvlist members. 117219089Spjd * 118219089Spjd * A replacement function receives arguments as follows: 119219089Spjd * 120219089Spjd * nvlist_prtctl_t Print control structure; do not change preferences 121219089Spjd * for this object from a print callback function. 122219089Spjd * 123219089Spjd * void * The function-private cookie argument registered 124219089Spjd * when the replacement function was appointed. 125219089Spjd * 126219089Spjd * nvlist_t * The full nvlist that is being processed. The 127219089Spjd * rendering function is called to render a single 128219089Spjd * member (name and value passed as below) but it may 129219089Spjd * want to reference or incorporate other aspects of 130219089Spjd * the full nvlist. 131219089Spjd * 132219089Spjd * const char * Member name to render 133219089Spjd * 134219089Spjd * valtype Value of the member to render 135219089Spjd * 136219089Spjd * The function must return non-zero if it has rendered output for this 137219089Spjd * member, or 0 if it wants to default to standard rendering for this 138219089Spjd * one member. 139219089Spjd */ 140219089Spjd 141219089Spjd#define NVLIST_PRINTCTL_SVDECL(funcname, valtype) \ 142219089Spjd extern void funcname(nvlist_prtctl_t, \ 143219089Spjd int (*)(nvlist_prtctl_t, void *, nvlist_t *, const char *, valtype), \ 144219089Spjd void *) 145219089Spjd 146219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_boolean, int); 147219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_boolean_value, boolean_t); 148219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_byte, uchar_t); 149219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int8, int8_t); 150219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint8, uint8_t); 151219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int16, int16_t); 152219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint16, uint16_t); 153219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int32, int32_t); 154219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint32, uint32_t); 155219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int64, int64_t); 156219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint64, uint64_t); 157219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_double, double); 158219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_string, char *); 159219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_hrtime, hrtime_t); 160219089SpjdNVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_nvlist, nvlist_t *); 161219089Spjd 162219089Spjd#undef NVLIST_PRINTCTL_SVDECL /* was just for "clarity" above */ 163219089Spjd 164219089Spjd/* 165219089Spjd * Function prototypes for interfaces that appoint a new rendering function 166219089Spjd * for array-valued nvlist members. 167219089Spjd * 168219089Spjd * One additional argument is taken: uint_t for the number of array elements 169219089Spjd * 170219089Spjd * Return values as above. 171219089Spjd */ 172219089Spjd#define NVLIST_PRINTCTL_AVDECL(funcname, vtype) \ 173219089Spjd extern void funcname(nvlist_prtctl_t, \ 174219089Spjd int (*)(nvlist_prtctl_t, void *, nvlist_t *, const char *, vtype, uint_t), \ 175219089Spjd void *) 176219089Spjd 177219089SpjdNVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_boolean_array, boolean_t *); 178219089SpjdNVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_byte_array, uchar_t *); 179219089SpjdNVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int8_array, int8_t *); 180219089SpjdNVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint8_array, uint8_t *); 181219089SpjdNVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int16_array, int16_t *); 182219089SpjdNVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint16_array, uint16_t *); 183219089SpjdNVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int32_array, int32_t *); 184219089SpjdNVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint32_array, uint32_t *); 185219089SpjdNVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int64_array, int64_t *); 186219089SpjdNVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint64_array, uint64_t *); 187219089SpjdNVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_string_array, char **); 188219089SpjdNVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_nvlist_array, nvlist_t **); 189219089Spjd 190219089Spjd#undef NVLIST_PRINTCTL_AVDECL /* was just for "clarity" above */ 191219089Spjd 192168404Spjd#ifdef __cplusplus 193168404Spjd} 194168404Spjd#endif 195168404Spjd 196168404Spjd#endif /* _LIBNVPAIR_H */ 197