blob: 4e3f095dc24268ef0ec43025e3f3e0836a180758 [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
27#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
28
29#define LYS_UNKNOWN 0x0000, /**< uninitalized unknown statement node */
30#define LYS_CONTAINER 0x0001, /**< container statement node */
31#define LYS_CHOICE 0x0002, /**< choice statement node */
32#define LYS_LEAF 0x0004, /**< leaf statement node */
33#define LYS_LEAFLIST 0x0008, /**< leaf-list statement node */
34#define LYS_LIST 0x0010, /**< list statement node */
35#define LYS_ANYXML 0x0020, /**< anyxml statement node */
36#define LYS_CASE 0x0040, /**< case statement node */
37#define LYS_USES 0x0080, /**< uses statement node */
38#define LYS_AUGMENT 0x0100, /**< augment statement node */
39#define LYS_ANYDATA 0x0220, /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
40
41/**
42 * @brief YANG import-stmt
43 */
44struct lysp_import {
45 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
46 struct lysp_module *module; /**< link to the imported module (mandatory) */
47 const char *dsc; /**< description */
48 const char *ref; /**< reference */
Michal Vaskobc2559f2018-09-07 10:17:50 +020049 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020050 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
51};
52
53/**
54 * @brief YANG include-stmt
55 */
56struct lysp_include {
57 struct lysp_module *submodule; /**< link to the included submodule (mandatory) */
58 const char *dsc; /**< description */
59 const char *ref; /**< reference */
Michal Vaskobc2559f2018-09-07 10:17:50 +020060 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020061 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
62};
63
64/**
65 * @brief YANG extension-stmt
66 */
67struct lysp_ext {
68 const char *name; /**< extension name */
69 const char *argument; /**< argument name, NULL if not specified */
70 const char *dsc; /**< description statement */
71 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +020072 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020073 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
74};
75
76/**
77 * @brief Helper structure for generic storage of the extension instances content.
78 */
79struct lysp_stmt {
80 const char *stmt; /**< identifier of the statement */
81 const char *arg; /**< statement's argument */
82 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +020083 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020084};
85
86/**
Michal Vaskod92e42a2018-09-07 08:35:02 +020087 * @brief Enum of substatements in which extension instances can appear.
88 */
89typedef enum {
90 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
91 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
92 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
93 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
94 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
95 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
96 lys_node_choice and lys_deviate */
97 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
98 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
99 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
100 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
101 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
102 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
103 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
104 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
105 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
106 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
107 belongs-to's prefix) and lys_import */
108 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
109 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
110 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
111 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
112 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
113 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
114 lys_node_leaflist and lys_deviate */
115 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
116 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
117 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
118 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
119 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
120 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
121 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
122 lys_node_anydata and lys_deviate */
123 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
124 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
125 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
126 LYEXT_SUBSTMT_DIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
127 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
128 lys_node_leaflist and lys_deviate */
129 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
130 lys_node_leaflist and lys_deviate */
131 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
132 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
133} LYEXT_SUBSTMT;
134
135/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200136 * @brief YANG extension instance
137 */
138struct lysp_ext_instance {
139 const char *name; /**< extension identifier, including possible prefix */
140 const char *argument; /**< optional value of the extension's argument */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200141 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
142 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
143 the index of that substatement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200144 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200145};
146
147/**
148 * @brief YANG feature-stmt
149 */
150struct lysp_feature {
151 const char *name; /**< feature name (mandatory) */
152 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
153 const char *dsc; /**< description statement */
154 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200155 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200156 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
157};
158
159/**
160 * @brief YANG identity-stmt
161 */
162struct lysp_ident {
163 const char *name; /**< identity name (mandatory), including possible prefix */
164 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
165 const char **bases; /**< list of base identifiers (NULL-terminated) */
166 const char *dsc; /**< description statement */
167 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200168 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200169 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
170};
171
172/*
173 * @brief Covers restrictions: range, length, pattern, must
174 */
175struct lysp_restr {
176 const char *arg; /**< The restriction expression/value (mandatory);
177 in case of pattern restriction, the first byte has a special meaning:
178 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
179 const char *emsg; /**< error-message */
180 const char *eapptag; /**< error-app-tag value */
181 const char *dsc; /**< description */
182 const char *ref; /**< reference */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200183 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200184};
185
186/**
187 * @brief Enumeration/Bit value definition
188 */
189struct lysp_type_enum {
190 const char *name; /**< name (mandatory) */
191 const char *dsc; /**< description statement */
192 const char *ref; /**< reference statement */
193 const char *value; /**< enum's value or bit's position */
194 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200195 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200196 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
197};
198
199/**
200 * @brief YANG type-stmt
201 *
202 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
203 */
204struct lysp_type {
205 const char *name; /**< name of the type (mandatory) */
206 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
207 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200208 struct lysp_restr *patterns; /**< list of patterns (0-terminated) - string */
209 struct lysp_type_enum *enums; /**< list of enum-stmts (0-terminated) - enum */
210 struct lysp_type_enum *bits; /**< list of bit-stmts (0-terminated) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200211 const char *path; /**< path - leafref */
212 const char **bases; /**< list of base identifiers (NULL-terminated) - identityref */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200213 struct lysp_type *types; /**< list of sub-types (0-terminated) - union */
214 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200215
216 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
217 uint8_t require_instance; /**< require-instance flag - leafref, instance */
218};
219
220/**
221 * @brief YANG typedef-stmt
222 */
223struct lysp_tpdf {
224 const char *name; /**< name of the newly defined type (mandatory) */
225 const char *units; /**< units of the newly defined type */
226 const char *dflt; /**< default value of the newly defined type */
227 const char *dsc; /**< description statement */
228 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200229 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200230 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
231 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
232};
233
234/**
235 * @brief YANG grouping-stmt
236 */
237struct lysp_grp {
238 const char *name; /**< grouping name (mandatory) */
239 const char *dsc; /**< description statement */
240 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200241 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
242 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200243 struct lysp_node *data; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200244 struct lysp_action *actions; /**< list of actions (0-terminated) */
245 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
246 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200247 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
248};
249
250/**
251 * @brief YANG when-stmt
252 */
253struct lysp_when {
254 const char *cond; /**< specified condition (mandatory) */
255 const char *dsc; /**< description statement */
256 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200257 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200258};
259
260/**
261 * @brief YANG refine-stmt
262 */
263struct lysp_refine {
264 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
265 const char *dsc; /**< description statement */
266 const char *ref; /**< reference statement */
267 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200268 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200269 const char *presence; /**< presence description */
270 const char **dflts; /**< list of default values (NULL-terminated) */
271 uint32_t min; /**< min-elements constraint */
272 uint32_t max; /**< max-elements constraint, 0 means unbounded */
273 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
274};
275
276/**
277 * @brief YANG uses-augment-stmt and augment-stmt
278 */
279struct lysp_augment {
280 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
281 const char *dsc; /**< description statement */
282 const char *ref; /**< reference statement */
283 struct lysp_when *when; /**< when statement */
284 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
285 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200286 struct lysp_action *actions; /**< list of actions (0-terminated) */
287 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
288 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200289 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
290};
291
292/**
293 * @defgroup deviatetypes Deviate types
294 * @{
295 */
296#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
297#define LYS_DEV_ADD 2 /**< deviate type add */
298#define LYS_DEV_DELETE 3 /**< deviate type delete */
299#define LYS_DEV_REPLACE 4 /**< deviate type replace */
300/** @} */
301
302/**
303 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
304 */
305struct lysp_deviate {
306 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
307 struct lysp_deviate *next; /**< next deviate structure in the list */
308};
309
310struct lysp_deviate_add {
311 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
312 struct lysp_deviate *next; /**< next deviate structure in the list */
313 const char *units; /**< units of the leaf's type */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200314 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200315 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
316 const char **dflts; /**< list of default values (NULL-terminated) */
317 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
318 uint32_t min; /**< min-elements constraint */
319 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200320 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200321};
322
323struct lysp_deviate_del {
324 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
325 struct lysp_deviate *next; /**< next deviate structure in the list */
326 const char *units; /**< units of the leaf's type */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200327 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200328 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
329 const char **dflts; /**< list of default values (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200330 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200331};
332
333struct lysp_deviate_rpl {
334 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
335 struct lysp_deviate *next; /**< next deviate structure in the list */
336 struct lysp_type *type; /**< type of the node (mandatory) */
337 const char *units; /**< units of the values */
338 const char *dflt; /**< default value */
339 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
340 uint32_t min; /**< min-elements constraint */
341 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200342 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200343};
344
345struct lysp_deviation {
346 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
347 const char *dsc; /**< description statement */
348 const char *ref; /**< reference statement */
349 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200350 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200351};
352
353/**
354 * @brief Generic YANG data node
355 */
356struct lysp_node {
357 uint16_t nodetype; /**< type of the node (mandatory) */
358 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
359 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
360 const char *name; /**< node name (mandatory) */
361 const char *dsc; /**< description statement */
362 const char *ref; /**< reference statement */
363 struct lysp_when *when; /**< when statement */
364 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200365 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200366};
367
368/**
369 * @brief Extension structure of the lysp_node for YANG container
370 */
371struct lysp_node_container {
372 uint16_t nodetype; /**< LYS_CONTAINER */
373 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
374 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
375 const char *name; /**< node name (mandatory) */
376 const char *dsc; /**< description statement */
377 const char *ref; /**< reference statement */
378 struct lysp_when *when; /**< when statement */
379 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200380 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200381
382 /* container */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200383 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200384 const char *presence; /**< presence description */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200385 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
386 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200387 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200388 struct lysp_action *actions; /**< list of actions (0-terminated) */
389 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200390};
391
392struct lysp_node_leaf {
393 uint16_t nodetype; /**< LYS_LEAF */
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 /* leaf */
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 struct lysp_type type; /**< type of the leaf node (mandatory) */
406 const char *units; /**< units of the leaf's type */
407 const char *dflt; /**< default value */
408};
409
410struct lysp_node_leaflist {
411 uint16_t nodetype; /**< LYS_LEAFLIST */
412 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
413 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
414 const char *name; /**< node name (mandatory) */
415 const char *dsc; /**< description statement */
416 const char *ref; /**< reference statement */
417 struct lysp_when *when; /**< when statement */
418 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200419 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200420
421 /* leaf-list */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200422 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200423 struct lysp_type type; /**< type of the leaf node (mandatory) */
424 const char *units; /**< units of the leaf's type */
425 const char **dflts; /**< list of default values (NULL-terminated) */
426 uint32_t min; /**< min-elements constraint */
427 uint32_t max; /**< max-elements constraint, 0 means unbounded */
428};
429
430struct lysp_node_list {
431 uint16_t nodetype; /**< LYS_LIST */
432 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
433 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
434 const char *name; /**< node name (mandatory) */
435 const char *dsc; /**< description statement */
436 const char *ref; /**< reference statement */
437 struct lysp_when *when; /**< when statement */
438 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200439 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200440
441 /* list */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200442 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200443 const char *key; /**< keys specification */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200444 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
445 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200446 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200447 struct lysp_action *actions; /**< list of actions (0-terminated) */
448 struct lysp_notif *notifications;/**< list of notifications (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200449 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
450 uint32_t min; /**< min-elements constraint */
451 uint32_t max; /**< max-elements constraint, 0 means unbounded */
452};
453
454struct lysp_node_choice {
455 uint16_t nodetype; /**< LYS_CHOICE */
456 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
457 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
458 const char *name; /**< node name (mandatory) */
459 const char *dsc; /**< description statement */
460 const char *ref; /**< reference statement */
461 struct lysp_when *when; /**< when statement */
462 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200463 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200464
465 /* choice */
466 struct lysp_node *child; /**< list of data nodes (linked list) */
467 const char* dflt; /**< default case */
468};
469
470struct lysp_node_case {
471 uint16_t nodetype; /**< LYS_CASE */
472 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
473 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
474 const char *name; /**< node name (mandatory) */
475 const char *dsc; /**< description statement */
476 const char *ref; /**< reference statement */
477 struct lysp_when *when; /**< when statement */
478 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200479 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200480
481 /* case */
482 struct lysp_node *child; /**< list of data nodes (linked list) */
483};
484
485struct lysp_node_anydata {
486 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
487 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
488 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
489 const char *name; /**< node name (mandatory) */
490 const char *dsc; /**< description statement */
491 const char *ref; /**< reference statement */
492 struct lysp_when *when; /**< when statement */
493 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200494 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200495
496 /* anyxml/anydata */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200497 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200498};
499
500struct lysp_node_uses {
501 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
502 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
503 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
504 const char *name; /**< grouping name reference (mandatory) */
505 const char *dsc; /**< description statement */
506 const char *ref; /**< reference statement */
507 struct lysp_when *when; /**< when statement */
508 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200509 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200510
511 /* uses */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200512 struct lysp_refine *refines; /**< list of uses's refines (0-terminated) */
513 struct lysp_augment *augments; /**< list of uses's augment (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200514};
515
516/**
517 * @brief YANG input-stmt and output-stmt
518 */
519struct lysp_action_inout {
Michal Vaskobc2559f2018-09-07 10:17:50 +0200520 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
521 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
522 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200523 struct lysp_node *data; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200524 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200525};
526
527/**
528 * @brief YANG rpc-stmt and action-stmt
529 */
530struct lysp_action {
531 const char *name; /**< grouping name reference (mandatory) */
532 const char *dsc; /**< description statement */
533 const char *ref; /**< reference statement */
534 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200535 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
536 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200537 struct lysp_action_inout input; /**< RPC's/Action's input */
538 struct lysp_action_inout output; /**< RPC's/Action's output */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200539 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200540 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
541};
542
543/**
544 * @brief YANG notification-stmt
545 */
546struct lysp_notif {
547 const char *name; /**< grouping name reference (mandatory) */
548 const char *dsc; /**< description statement */
549 const char *ref; /**< reference statement */
550 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200551 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
552 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
553 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200554 struct lysp_node *data; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200555 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200556 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
557};
558
559/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200560 * @brief supported YANG schema version values
561 */
562typedef enum LYS_VERSION {
563 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
564 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
565 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
566} LYS_VERSION;
567
568/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200569 * @brief Printable YANG schema tree structure representing YANG module.
570 *
571 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
572 */
573struct lysp_module {
574 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
575 const char *name; /**< name of the module (mandatory) */
576 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
577 union {
578 /* module */
579 const char *ns; /**< namespace of the module (module - type 0, mandatory) */
580 /* submodule */
581 struct lysp_module *belongsto; /**< belongs to parent module (submodule - type 1, mandatory) */
582 };
583 const char *prefix; /**< prefix of the module (module - type 0, mandatory) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200584 struct lysp_import *imports; /**< list of imported modules (0-terminated) */
585 struct lysp_include *includes; /**< list of included submodules (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200586 const char *org; /**< party/company responsible for the module */
587 const char *contact; /**< contact information for the module */
588 const char *dsc; /**< description of the module */
589 const char *ref; /**< cross-reference for the module */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200590 struct lysp_revision *revs; /**< list of the module revisions (0-terminated), the first revision
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200591 in the list is always the last (newest) revision of the module */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200592 struct lysp_ext *extensions; /**< list of extension statements (0-terminated) */
593 struct lysp_feature *features; /**< list of feature definitions (0-terminated) */
594 struct lysp_ident *identities; /**< list of identities (0-terminated) */
595 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
596 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200597 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200598 struct lysp_augment *augments; /**< list of augments (0-terminated) */
599 struct lysp_action *rpcs; /**< list of RPCs (0-terminated) */
600 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
601 struct lysp_deviation *deviations; /**< list of deviations (0-terminated) */
602 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200603
Radek Krejcif0fceb62018-09-05 14:58:45 +0200604 uint8_t submodule:1; /**< flag to distinguish main modules and submodules */
605 uint8_t deviated:1; /**< flag if the module is deviated by another module */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200606 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
607 uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is
608 the latest revision found */
Radek Krejcif0fceb62018-09-05 14:58:45 +0200609 uint8_t version:4; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200610};
611
612/**
613 * @brief Compiled YANG schema tree structure representing YANG module.
614 *
615 * Semantically validated YANG schema tree for data tree parsing.
616 * Contains only the necessary information for the data validation.
617 */
618struct lysc_module {
619};
620
621/**
622 * @brief Available YANG schema tree structures representing YANG module.
623 */
624struct lys_module {
625 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
626 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing */
627};
628
629/** @} */
630
631#endif /* LY_TREE_SCHEMA_H_ */