Print this page
OS-1840 fmdump shall emit JSON
Reviewed by: Robert Mustacchi <rm@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libnvpair/libnvpair.h
+++ new/usr/src/lib/libnvpair/libnvpair.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
23 + * Copyright (c) 2013, Joyent, Inc. All rights reserved.
23 24 */
24 25
25 26 #ifndef _LIBNVPAIR_H
26 27 #define _LIBNVPAIR_H
27 28
28 29 #include <sys/nvpair.h>
29 30 #include <stdlib.h>
30 31 #include <stdio.h>
31 32 #include <regex.h>
32 33
33 34 #ifdef __cplusplus
34 35 extern "C" {
35 36 #endif
36 37
37 38 /*
38 39 * All interfaces described in this file are private to Solaris, and
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
39 40 * are subject to change at any time and without notice. The public
40 41 * nvlist/nvpair interfaces, as documented in manpage sections 3NVPAIR,
41 42 * are all imported from <sys/nvpair.h> included above.
42 43 */
43 44
44 45 extern int nvpair_value_match(nvpair_t *, int, char *, char **);
45 46 extern int nvpair_value_match_regex(nvpair_t *, int, char *, regex_t *,
46 47 char **);
47 48
48 49 extern void nvlist_print(FILE *, nvlist_t *);
50 +extern int nvlist_print_json(FILE *, nvlist_t *);
49 51 extern void dump_nvlist(nvlist_t *, int);
50 52
51 53 /*
52 54 * Private nvlist printing interface that allows the caller some control
53 55 * over output rendering (as opposed to nvlist_print and dump_nvlist).
54 56 *
55 57 * Obtain an opaque nvlist_prtctl_t cookie using nvlist_prtctl_alloc
56 58 * (NULL on failure); on return the cookie is set up for default formatting
57 59 * and rendering. Quote the cookie in subsequent customisation functions and
58 60 * then pass the cookie to nvlist_prt to render the nvlist. Finally,
59 61 * use nvlist_prtctl_free to release the cookie.
60 62 *
61 63 * For all nvlist_lookup_xxx and nvlist_lookup_xxx_array functions
62 64 * we have a corresponding brace of functions that appoint replacement
63 65 * rendering functions:
64 66 *
65 67 * extern void nvlist_prtctl_xxx(nvlist_prtctl_t,
66 68 * void (*)(nvlist_prtctl_t ctl, void *private, const char *name,
67 69 * xxxtype value))
68 70 *
69 71 * and
70 72 *
71 73 * extern void nvlist_prtctl_xxx_array(nvlist_prtctl_t,
72 74 * void (*)(nvlist_prtctl_t ctl, void *private, const char *name,
73 75 * xxxtype value, uint_t count))
74 76 *
75 77 * where xxxtype is the C datatype corresponding to xxx, eg int8_t for "int8"
76 78 * and char * for "string". The function that is appointed to render the
77 79 * specified datatype receives as arguments the cookie, the nvlist
78 80 * member name, the value of that member (or a pointer for array function),
79 81 * and (for array rendering functions) a count of the number of elements.
80 82 */
81 83
82 84 typedef struct nvlist_prtctl *nvlist_prtctl_t; /* opaque */
83 85
84 86 enum nvlist_indent_mode {
85 87 NVLIST_INDENT_ABS, /* Absolute indentation */
86 88 NVLIST_INDENT_TABBED /* Indent with tabstops */
87 89 };
88 90
89 91 extern nvlist_prtctl_t nvlist_prtctl_alloc(void);
90 92 extern void nvlist_prtctl_free(nvlist_prtctl_t);
91 93 extern void nvlist_prt(nvlist_t *, nvlist_prtctl_t);
92 94
93 95 /* Output stream */
94 96 extern void nvlist_prtctl_setdest(nvlist_prtctl_t, FILE *);
95 97 extern FILE *nvlist_prtctl_getdest(nvlist_prtctl_t);
96 98
97 99 /* Indentation mode, start indent, indent increment; default tabbed/0/1 */
98 100 extern void nvlist_prtctl_setindent(nvlist_prtctl_t, enum nvlist_indent_mode,
99 101 int, int);
100 102 extern void nvlist_prtctl_doindent(nvlist_prtctl_t, int);
101 103
102 104 enum nvlist_prtctl_fmt {
103 105 NVLIST_FMT_MEMBER_NAME, /* name fmt; default "%s = " */
104 106 NVLIST_FMT_MEMBER_POSTAMBLE, /* after nvlist member; default "\n" */
105 107 NVLIST_FMT_BTWN_ARRAY /* between array members; default " " */
106 108 };
107 109
108 110 extern void nvlist_prtctl_setfmt(nvlist_prtctl_t, enum nvlist_prtctl_fmt,
109 111 const char *);
110 112 extern void nvlist_prtctl_dofmt(nvlist_prtctl_t, enum nvlist_prtctl_fmt, ...);
111 113
112 114 /*
113 115 * Function prototypes for interfaces that appoint a new rendering function
114 116 * for single-valued nvlist members.
115 117 *
116 118 * A replacement function receives arguments as follows:
117 119 *
118 120 * nvlist_prtctl_t Print control structure; do not change preferences
119 121 * for this object from a print callback function.
120 122 *
121 123 * void * The function-private cookie argument registered
122 124 * when the replacement function was appointed.
123 125 *
124 126 * nvlist_t * The full nvlist that is being processed. The
125 127 * rendering function is called to render a single
126 128 * member (name and value passed as below) but it may
127 129 * want to reference or incorporate other aspects of
128 130 * the full nvlist.
129 131 *
130 132 * const char * Member name to render
131 133 *
132 134 * valtype Value of the member to render
133 135 *
134 136 * The function must return non-zero if it has rendered output for this
135 137 * member, or 0 if it wants to default to standard rendering for this
136 138 * one member.
137 139 */
138 140
139 141 #define NVLIST_PRINTCTL_SVDECL(funcname, valtype) \
140 142 extern void funcname(nvlist_prtctl_t, \
141 143 int (*)(nvlist_prtctl_t, void *, nvlist_t *, const char *, valtype), \
142 144 void *)
143 145
144 146 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_boolean, int);
145 147 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_boolean_value, boolean_t);
146 148 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_byte, uchar_t);
147 149 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int8, int8_t);
148 150 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint8, uint8_t);
149 151 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int16, int16_t);
150 152 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint16, uint16_t);
151 153 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int32, int32_t);
152 154 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint32, uint32_t);
153 155 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int64, int64_t);
154 156 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint64, uint64_t);
155 157 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_double, double);
156 158 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_string, char *);
157 159 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_hrtime, hrtime_t);
158 160 NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_nvlist, nvlist_t *);
159 161
160 162 #undef NVLIST_PRINTCTL_SVDECL /* was just for "clarity" above */
161 163
162 164 /*
163 165 * Function prototypes for interfaces that appoint a new rendering function
164 166 * for array-valued nvlist members.
165 167 *
166 168 * One additional argument is taken: uint_t for the number of array elements
167 169 *
168 170 * Return values as above.
169 171 */
170 172 #define NVLIST_PRINTCTL_AVDECL(funcname, vtype) \
171 173 extern void funcname(nvlist_prtctl_t, \
172 174 int (*)(nvlist_prtctl_t, void *, nvlist_t *, const char *, vtype, uint_t), \
173 175 void *)
174 176
175 177 NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_boolean_array, boolean_t *);
176 178 NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_byte_array, uchar_t *);
177 179 NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int8_array, int8_t *);
178 180 NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint8_array, uint8_t *);
179 181 NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int16_array, int16_t *);
180 182 NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint16_array, uint16_t *);
181 183 NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int32_array, int32_t *);
182 184 NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint32_array, uint32_t *);
183 185 NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int64_array, int64_t *);
184 186 NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint64_array, uint64_t *);
185 187 NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_string_array, char **);
186 188 NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_nvlist_array, nvlist_t **);
187 189
188 190 #undef NVLIST_PRINTCTL_AVDECL /* was just for "clarity" above */
189 191
190 192 #ifdef __cplusplus
191 193 }
192 194 #endif
193 195
194 196 #endif /* _LIBNVPAIR_H */
↓ open down ↓ |
136 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX