blob: 6dc23ed6d822d071e91df2a49ec748484a741ef7 [file] [log] [blame]
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001/**
2 * @file tree_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief libyang representation of YANG schema trees.
5 *
6 * Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_TREE_SCHEMA_H_
16#define LY_TREE_SCHEMA_H_
17
18#include <stdint.h>
19
20/**
21 * @defgroup schematree Schema Tree
22 * @{
23 *
24 * Data structures and functions to manipulate and access schema tree.
25 */
26
Radek Krejci0af5f5d2018-09-07 15:00:30 +020027/**
28 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
29 */
30typedef enum {
31 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
32 LYS_IN_YANG = 1, /**< YANG schema input format */
33 LYS_IN_YIN = 2 /**< YIN schema input format */
34} LYS_INFORMAT;
35
36/**
37 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
38 */
39typedef enum {
40 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
41 LYS_OUT_YANG = 1, /**< YANG schema output format */
42 LYS_OUT_YIN = 2, /**< YIN schema output format */
43 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
44 LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
45 LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */
46} LYS_OUTFORMAT;
47
Radek Krejci5aeea3a2018-09-05 13:29:36 +020048#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
49
50#define LYS_UNKNOWN 0x0000, /**< uninitalized unknown statement node */
51#define LYS_CONTAINER 0x0001, /**< container statement node */
52#define LYS_CHOICE 0x0002, /**< choice statement node */
53#define LYS_LEAF 0x0004, /**< leaf statement node */
54#define LYS_LEAFLIST 0x0008, /**< leaf-list statement node */
55#define LYS_LIST 0x0010, /**< list statement node */
56#define LYS_ANYXML 0x0020, /**< anyxml statement node */
57#define LYS_CASE 0x0040, /**< case statement node */
58#define LYS_USES 0x0080, /**< uses statement node */
59#define LYS_AUGMENT 0x0100, /**< augment statement node */
60#define LYS_ANYDATA 0x0220, /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
61
62/**
63 * @brief YANG import-stmt
64 */
65struct lysp_import {
66 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
67 struct lysp_module *module; /**< link to the imported module (mandatory) */
68 const char *dsc; /**< description */
69 const char *ref; /**< reference */
Michal Vaskobc2559f2018-09-07 10:17:50 +020070 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020071 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
72};
73
74/**
75 * @brief YANG include-stmt
76 */
77struct lysp_include {
78 struct lysp_module *submodule; /**< link to the included submodule (mandatory) */
79 const char *dsc; /**< description */
80 const char *ref; /**< reference */
Michal Vaskobc2559f2018-09-07 10:17:50 +020081 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020082 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
83};
84
85/**
86 * @brief YANG extension-stmt
87 */
88struct lysp_ext {
89 const char *name; /**< extension name */
90 const char *argument; /**< argument name, NULL if not specified */
91 const char *dsc; /**< description statement */
92 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +020093 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020094 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
95};
96
97/**
98 * @brief Helper structure for generic storage of the extension instances content.
99 */
100struct lysp_stmt {
101 const char *stmt; /**< identifier of the statement */
102 const char *arg; /**< statement's argument */
103 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200104 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200105};
106
107/**
Michal Vaskod92e42a2018-09-07 08:35:02 +0200108 * @brief Enum of substatements in which extension instances can appear.
109 */
110typedef enum {
111 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
112 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
113 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
114 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
115 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
116 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
117 lys_node_choice and lys_deviate */
118 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
119 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
120 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
121 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
122 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
123 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
124 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
125 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
126 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
127 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
128 belongs-to's prefix) and lys_import */
129 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
130 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
131 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
132 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
133 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
134 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
135 lys_node_leaflist and lys_deviate */
136 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
137 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
138 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
139 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
140 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
141 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
142 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
143 lys_node_anydata and lys_deviate */
144 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
145 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
146 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
147 LYEXT_SUBSTMT_DIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
148 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
149 lys_node_leaflist and lys_deviate */
150 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
151 lys_node_leaflist and lys_deviate */
152 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
153 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
154} LYEXT_SUBSTMT;
155
156/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200157 * @brief YANG extension instance
158 */
159struct lysp_ext_instance {
160 const char *name; /**< extension identifier, including possible prefix */
161 const char *argument; /**< optional value of the extension's argument */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200162 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
163 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
164 the index of that substatement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200165 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200166};
167
168/**
169 * @brief YANG feature-stmt
170 */
171struct lysp_feature {
172 const char *name; /**< feature name (mandatory) */
173 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
174 const char *dsc; /**< description statement */
175 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200176 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200177 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
178};
179
180/**
181 * @brief YANG identity-stmt
182 */
183struct lysp_ident {
184 const char *name; /**< identity name (mandatory), including possible prefix */
185 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
186 const char **bases; /**< list of base identifiers (NULL-terminated) */
187 const char *dsc; /**< description statement */
188 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200189 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200190 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
191};
192
193/*
194 * @brief Covers restrictions: range, length, pattern, must
195 */
196struct lysp_restr {
197 const char *arg; /**< The restriction expression/value (mandatory);
198 in case of pattern restriction, the first byte has a special meaning:
199 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
200 const char *emsg; /**< error-message */
201 const char *eapptag; /**< error-app-tag value */
202 const char *dsc; /**< description */
203 const char *ref; /**< reference */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200204 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200205};
206
207/**
208 * @brief Enumeration/Bit value definition
209 */
210struct lysp_type_enum {
211 const char *name; /**< name (mandatory) */
212 const char *dsc; /**< description statement */
213 const char *ref; /**< reference statement */
214 const char *value; /**< enum's value or bit's position */
215 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200216 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200217 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
218};
219
220/**
221 * @brief YANG type-stmt
222 *
223 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
224 */
225struct lysp_type {
226 const char *name; /**< name of the type (mandatory) */
227 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
228 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200229 struct lysp_restr *patterns; /**< list of patterns (0-terminated) - string */
230 struct lysp_type_enum *enums; /**< list of enum-stmts (0-terminated) - enum */
231 struct lysp_type_enum *bits; /**< list of bit-stmts (0-terminated) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200232 const char *path; /**< path - leafref */
233 const char **bases; /**< list of base identifiers (NULL-terminated) - identityref */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200234 struct lysp_type *types; /**< list of sub-types (0-terminated) - union */
235 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200236
237 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
238 uint8_t require_instance; /**< require-instance flag - leafref, instance */
239};
240
241/**
242 * @brief YANG typedef-stmt
243 */
244struct lysp_tpdf {
245 const char *name; /**< name of the newly defined type (mandatory) */
246 const char *units; /**< units of the newly defined type */
247 const char *dflt; /**< default value of the newly defined type */
248 const char *dsc; /**< description statement */
249 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200250 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200251 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
252 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
253};
254
255/**
256 * @brief YANG grouping-stmt
257 */
258struct lysp_grp {
259 const char *name; /**< grouping name (mandatory) */
260 const char *dsc; /**< description statement */
261 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200262 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
263 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200264 struct lysp_node *data; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200265 struct lysp_action *actions; /**< list of actions (0-terminated) */
266 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
267 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200268 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
269};
270
271/**
272 * @brief YANG when-stmt
273 */
274struct lysp_when {
275 const char *cond; /**< specified condition (mandatory) */
276 const char *dsc; /**< description statement */
277 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200278 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200279};
280
281/**
282 * @brief YANG refine-stmt
283 */
284struct lysp_refine {
285 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
286 const char *dsc; /**< description statement */
287 const char *ref; /**< reference statement */
288 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200289 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200290 const char *presence; /**< presence description */
291 const char **dflts; /**< list of default values (NULL-terminated) */
292 uint32_t min; /**< min-elements constraint */
293 uint32_t max; /**< max-elements constraint, 0 means unbounded */
294 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
295};
296
297/**
298 * @brief YANG uses-augment-stmt and augment-stmt
299 */
300struct lysp_augment {
301 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
302 const char *dsc; /**< description statement */
303 const char *ref; /**< reference statement */
304 struct lysp_when *when; /**< when statement */
305 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
306 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200307 struct lysp_action *actions; /**< list of actions (0-terminated) */
308 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
309 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200310 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
311};
312
313/**
314 * @defgroup deviatetypes Deviate types
315 * @{
316 */
317#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
318#define LYS_DEV_ADD 2 /**< deviate type add */
319#define LYS_DEV_DELETE 3 /**< deviate type delete */
320#define LYS_DEV_REPLACE 4 /**< deviate type replace */
321/** @} */
322
323/**
324 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
325 */
326struct lysp_deviate {
327 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
328 struct lysp_deviate *next; /**< next deviate structure in the list */
329};
330
331struct lysp_deviate_add {
332 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
333 struct lysp_deviate *next; /**< next deviate structure in the list */
334 const char *units; /**< units of the leaf's type */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200335 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200336 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
337 const char **dflts; /**< list of default values (NULL-terminated) */
338 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
339 uint32_t min; /**< min-elements constraint */
340 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200341 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200342};
343
344struct lysp_deviate_del {
345 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
346 struct lysp_deviate *next; /**< next deviate structure in the list */
347 const char *units; /**< units of the leaf's type */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200348 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200349 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
350 const char **dflts; /**< list of default values (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200351 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200352};
353
354struct lysp_deviate_rpl {
355 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
356 struct lysp_deviate *next; /**< next deviate structure in the list */
357 struct lysp_type *type; /**< type of the node (mandatory) */
358 const char *units; /**< units of the values */
359 const char *dflt; /**< default value */
360 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
361 uint32_t min; /**< min-elements constraint */
362 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200363 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200364};
365
366struct lysp_deviation {
367 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
368 const char *dsc; /**< description statement */
369 const char *ref; /**< reference statement */
370 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200371 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200372};
373
374/**
375 * @brief Generic YANG data node
376 */
377struct lysp_node {
378 uint16_t nodetype; /**< type of the node (mandatory) */
379 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
380 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
381 const char *name; /**< node name (mandatory) */
382 const char *dsc; /**< description statement */
383 const char *ref; /**< reference statement */
384 struct lysp_when *when; /**< when statement */
385 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200386 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200387};
388
389/**
390 * @brief Extension structure of the lysp_node for YANG container
391 */
392struct lysp_node_container {
393 uint16_t nodetype; /**< LYS_CONTAINER */
394 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
395 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
396 const char *name; /**< node name (mandatory) */
397 const char *dsc; /**< description statement */
398 const char *ref; /**< reference statement */
399 struct lysp_when *when; /**< when statement */
400 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200401 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200402
403 /* container */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200404 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200405 const char *presence; /**< presence description */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200406 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
407 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200408 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200409 struct lysp_action *actions; /**< list of actions (0-terminated) */
410 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200411};
412
413struct lysp_node_leaf {
414 uint16_t nodetype; /**< LYS_LEAF */
415 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
416 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
417 const char *name; /**< node name (mandatory) */
418 const char *dsc; /**< description statement */
419 const char *ref; /**< reference statement */
420 struct lysp_when *when; /**< when statement */
421 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200422 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200423
424 /* leaf */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200425 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200426 struct lysp_type type; /**< type of the leaf node (mandatory) */
427 const char *units; /**< units of the leaf's type */
428 const char *dflt; /**< default value */
429};
430
431struct lysp_node_leaflist {
432 uint16_t nodetype; /**< LYS_LEAFLIST */
433 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
434 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
435 const char *name; /**< node name (mandatory) */
436 const char *dsc; /**< description statement */
437 const char *ref; /**< reference statement */
438 struct lysp_when *when; /**< when statement */
439 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200440 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200441
442 /* leaf-list */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200443 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200444 struct lysp_type type; /**< type of the leaf node (mandatory) */
445 const char *units; /**< units of the leaf's type */
446 const char **dflts; /**< list of default values (NULL-terminated) */
447 uint32_t min; /**< min-elements constraint */
448 uint32_t max; /**< max-elements constraint, 0 means unbounded */
449};
450
451struct lysp_node_list {
452 uint16_t nodetype; /**< LYS_LIST */
453 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
454 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
455 const char *name; /**< node name (mandatory) */
456 const char *dsc; /**< description statement */
457 const char *ref; /**< reference statement */
458 struct lysp_when *when; /**< when statement */
459 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200460 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200461
462 /* list */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200463 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200464 const char *key; /**< keys specification */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200465 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
466 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200467 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200468 struct lysp_action *actions; /**< list of actions (0-terminated) */
469 struct lysp_notif *notifications;/**< list of notifications (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200470 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
471 uint32_t min; /**< min-elements constraint */
472 uint32_t max; /**< max-elements constraint, 0 means unbounded */
473};
474
475struct lysp_node_choice {
476 uint16_t nodetype; /**< LYS_CHOICE */
477 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
478 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
479 const char *name; /**< node name (mandatory) */
480 const char *dsc; /**< description statement */
481 const char *ref; /**< reference statement */
482 struct lysp_when *when; /**< when statement */
483 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200484 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200485
486 /* choice */
487 struct lysp_node *child; /**< list of data nodes (linked list) */
488 const char* dflt; /**< default case */
489};
490
491struct lysp_node_case {
492 uint16_t nodetype; /**< LYS_CASE */
493 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
494 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
495 const char *name; /**< node name (mandatory) */
496 const char *dsc; /**< description statement */
497 const char *ref; /**< reference statement */
498 struct lysp_when *when; /**< when statement */
499 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200500 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200501
502 /* case */
503 struct lysp_node *child; /**< list of data nodes (linked list) */
504};
505
506struct lysp_node_anydata {
507 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
508 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
509 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
510 const char *name; /**< node name (mandatory) */
511 const char *dsc; /**< description statement */
512 const char *ref; /**< reference statement */
513 struct lysp_when *when; /**< when statement */
514 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200515 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200516
517 /* anyxml/anydata */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200518 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200519};
520
521struct lysp_node_uses {
522 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
523 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
524 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
525 const char *name; /**< grouping name reference (mandatory) */
526 const char *dsc; /**< description statement */
527 const char *ref; /**< reference statement */
528 struct lysp_when *when; /**< when statement */
529 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200530 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200531
532 /* uses */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200533 struct lysp_refine *refines; /**< list of uses's refines (0-terminated) */
534 struct lysp_augment *augments; /**< list of uses's augment (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200535};
536
537/**
538 * @brief YANG input-stmt and output-stmt
539 */
540struct lysp_action_inout {
Michal Vaskobc2559f2018-09-07 10:17:50 +0200541 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
542 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
543 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200544 struct lysp_node *data; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200545 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200546};
547
548/**
549 * @brief YANG rpc-stmt and action-stmt
550 */
551struct lysp_action {
552 const char *name; /**< grouping name reference (mandatory) */
553 const char *dsc; /**< description statement */
554 const char *ref; /**< reference statement */
555 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200556 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
557 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200558 struct lysp_action_inout input; /**< RPC's/Action's input */
559 struct lysp_action_inout output; /**< RPC's/Action's output */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200560 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200561 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
562};
563
564/**
565 * @brief YANG notification-stmt
566 */
567struct lysp_notif {
568 const char *name; /**< grouping name reference (mandatory) */
569 const char *dsc; /**< description statement */
570 const char *ref; /**< reference statement */
571 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200572 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
573 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
574 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200575 struct lysp_node *data; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200576 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200577 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
578};
579
580/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200581 * @brief supported YANG schema version values
582 */
583typedef enum LYS_VERSION {
584 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
585 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
586 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
587} LYS_VERSION;
588
589/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200590 * @brief Printable YANG schema tree structure representing YANG module.
591 *
592 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
593 */
594struct lysp_module {
595 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
596 const char *name; /**< name of the module (mandatory) */
597 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
598 union {
599 /* module */
600 const char *ns; /**< namespace of the module (module - type 0, mandatory) */
601 /* submodule */
602 struct lysp_module *belongsto; /**< belongs to parent module (submodule - type 1, mandatory) */
603 };
604 const char *prefix; /**< prefix of the module (module - type 0, mandatory) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200605 struct lysp_import *imports; /**< list of imported modules (0-terminated) */
606 struct lysp_include *includes; /**< list of included submodules (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200607 const char *org; /**< party/company responsible for the module */
608 const char *contact; /**< contact information for the module */
609 const char *dsc; /**< description of the module */
610 const char *ref; /**< cross-reference for the module */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200611 struct lysp_revision *revs; /**< list of the module revisions (0-terminated), the first revision
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200612 in the list is always the last (newest) revision of the module */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200613 struct lysp_ext *extensions; /**< list of extension statements (0-terminated) */
614 struct lysp_feature *features; /**< list of feature definitions (0-terminated) */
615 struct lysp_ident *identities; /**< list of identities (0-terminated) */
616 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
617 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200618 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200619 struct lysp_augment *augments; /**< list of augments (0-terminated) */
620 struct lysp_action *rpcs; /**< list of RPCs (0-terminated) */
621 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
622 struct lysp_deviation *deviations; /**< list of deviations (0-terminated) */
623 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200624
Radek Krejcif0fceb62018-09-05 14:58:45 +0200625 uint8_t submodule:1; /**< flag to distinguish main modules and submodules */
626 uint8_t deviated:1; /**< flag if the module is deviated by another module */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200627 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
628 uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is
629 the latest revision found */
Radek Krejcif0fceb62018-09-05 14:58:45 +0200630 uint8_t version:4; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200631};
632
633/**
634 * @brief Compiled YANG schema tree structure representing YANG module.
635 *
636 * Semantically validated YANG schema tree for data tree parsing.
637 * Contains only the necessary information for the data validation.
638 */
639struct lysc_module {
640};
641
642/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200643 * @brief Compiled YANG data node
644 */
645struct lysc_node {
646};
647
648/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200649 * @brief Available YANG schema tree structures representing YANG module.
650 */
651struct lys_module {
652 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
653 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing */
654};
655
656/** @} */
657
658#endif /* LY_TREE_SCHEMA_H_ */