blob: 382f681e384892898bb0773018865c1c1c0904b8 [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
Michal Vaskob55f6c12018-09-12 11:13:15 +020050#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_ANYDATA 0x0120 /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020060
61/**
62 * @brief YANG import-stmt
63 */
64struct lysp_import {
Michal Vaskod5927ca2018-09-07 15:05:32 +020065 const char *name; /**< name of the module to import (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020066 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020067 const char *dsc; /**< description */
68 const char *ref; /**< reference */
Michal Vaskobc2559f2018-09-07 10:17:50 +020069 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020070 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
71};
72
73/**
74 * @brief YANG include-stmt
75 */
76struct lysp_include {
Michal Vaskod5927ca2018-09-07 15:05:32 +020077 const char *name; /**< name of the submodule to include (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020078 const char *dsc; /**< description */
79 const char *ref; /**< reference */
Michal Vaskobc2559f2018-09-07 10:17:50 +020080 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020081 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
82};
83
84/**
85 * @brief YANG extension-stmt
86 */
87struct lysp_ext {
88 const char *name; /**< extension name */
89 const char *argument; /**< argument name, NULL if not specified */
90 const char *dsc; /**< description statement */
91 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +020092 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020093 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
94};
95
96/**
97 * @brief Helper structure for generic storage of the extension instances content.
98 */
99struct lysp_stmt {
100 const char *stmt; /**< identifier of the statement */
101 const char *arg; /**< statement's argument */
102 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200103 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200104};
105
106/**
Michal Vaskod92e42a2018-09-07 08:35:02 +0200107 * @brief Enum of substatements in which extension instances can appear.
108 */
109typedef enum {
110 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
111 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
112 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
113 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
114 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
115 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
116 lys_node_choice and lys_deviate */
117 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
118 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
119 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
120 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
121 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
122 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
123 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
124 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
125 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
126 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
127 belongs-to's prefix) and lys_import */
128 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
129 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
130 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
131 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
132 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
133 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
134 lys_node_leaflist and lys_deviate */
135 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
136 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
137 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
138 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
139 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
140 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
141 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
142 lys_node_anydata and lys_deviate */
143 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
144 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
145 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200146 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200147 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
148 lys_node_leaflist and lys_deviate */
149 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
150 lys_node_leaflist and lys_deviate */
151 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
152 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200153 LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200154} 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
Michal Vasko71e64ca2018-09-07 16:30:29 +0200193/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200194 * @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/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200208 * @brief YANG revision-stmt
209 */
210struct lysp_revision {
211 char rev[LY_REV_SIZE]; /**< revision date (madatory) */
212 const char *dsc; /**< description statement */
213 const char *ref; /**< reference statement */
214 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
215};
216
217/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200218 * @brief Enumeration/Bit value definition
219 */
220struct lysp_type_enum {
221 const char *name; /**< name (mandatory) */
222 const char *dsc; /**< description statement */
223 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200224 int64_t value; /**< enum's value or bit's position */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200225 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200226 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200227 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
228 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200229};
230
231/**
232 * @brief YANG type-stmt
233 *
234 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
235 */
236struct lysp_type {
237 const char *name; /**< name of the type (mandatory) */
238 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
239 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200240 struct lysp_restr *patterns; /**< list of patterns (0-terminated) - string */
241 struct lysp_type_enum *enums; /**< list of enum-stmts (0-terminated) - enum */
242 struct lysp_type_enum *bits; /**< list of bit-stmts (0-terminated) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200243 const char *path; /**< path - leafref */
244 const char **bases; /**< list of base identifiers (NULL-terminated) - identityref */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200245 struct lysp_type *types; /**< list of sub-types (0-terminated) - union */
246 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200247
248 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
249 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200250 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_SET_REQINST allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200251};
252
253/**
254 * @brief YANG typedef-stmt
255 */
256struct lysp_tpdf {
257 const char *name; /**< name of the newly defined type (mandatory) */
258 const char *units; /**< units of the newly defined type */
259 const char *dflt; /**< default value of the newly defined type */
260 const char *dsc; /**< description statement */
261 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200262 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200263 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
264 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
265};
266
267/**
268 * @brief YANG grouping-stmt
269 */
270struct lysp_grp {
271 const char *name; /**< grouping name (mandatory) */
272 const char *dsc; /**< description statement */
273 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200274 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
275 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200276 struct lysp_node *data; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200277 struct lysp_action *actions; /**< list of actions (0-terminated) */
278 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
279 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200280 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
281};
282
283/**
284 * @brief YANG when-stmt
285 */
286struct lysp_when {
287 const char *cond; /**< specified condition (mandatory) */
288 const char *dsc; /**< description statement */
289 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200290 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200291};
292
293/**
294 * @brief YANG refine-stmt
295 */
296struct lysp_refine {
297 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
298 const char *dsc; /**< description statement */
299 const char *ref; /**< reference statement */
300 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200301 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200302 const char *presence; /**< presence description */
303 const char **dflts; /**< list of default values (NULL-terminated) */
304 uint32_t min; /**< min-elements constraint */
305 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200306 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200307 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
308};
309
310/**
311 * @brief YANG uses-augment-stmt and augment-stmt
312 */
313struct lysp_augment {
314 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
315 const char *dsc; /**< description statement */
316 const char *ref; /**< reference statement */
317 struct lysp_when *when; /**< when statement */
318 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
319 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200320 struct lysp_action *actions; /**< list of actions (0-terminated) */
321 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
322 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200323 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
324};
325
326/**
327 * @defgroup deviatetypes Deviate types
328 * @{
329 */
330#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
331#define LYS_DEV_ADD 2 /**< deviate type add */
332#define LYS_DEV_DELETE 3 /**< deviate type delete */
333#define LYS_DEV_REPLACE 4 /**< deviate type replace */
334/** @} */
335
336/**
337 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
338 */
339struct lysp_deviate {
340 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
341 struct lysp_deviate *next; /**< next deviate structure in the list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200342 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200343};
344
345struct lysp_deviate_add {
346 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
347 struct lysp_deviate *next; /**< next deviate structure in the list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200348 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
349 const char *units; /**< units of the values */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200350 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200351 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
352 const char **dflts; /**< list of default values (NULL-terminated) */
353 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
354 uint32_t min; /**< min-elements constraint */
355 uint32_t max; /**< max-elements constraint, 0 means unbounded */
356};
357
358struct lysp_deviate_del {
359 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
360 struct lysp_deviate *next; /**< next deviate structure in the list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200361 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
362 const char *units; /**< units of the values */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200363 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200364 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
365 const char **dflts; /**< list of default values (NULL-terminated) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200366 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200367};
368
369struct lysp_deviate_rpl {
370 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
371 struct lysp_deviate *next; /**< next deviate structure in the list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200372 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
373 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200374 const char *units; /**< units of the values */
375 const char *dflt; /**< default value */
376 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
377 uint32_t min; /**< min-elements constraint */
378 uint32_t max; /**< max-elements constraint, 0 means unbounded */
379};
380
381struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200382 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200383 const char *dsc; /**< description statement */
384 const char *ref; /**< reference statement */
385 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
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
Michal Vaskob55f6c12018-09-12 11:13:15 +0200389#define LYS_CONFIG_W 0x01 /**< config true; */
390#define LYS_CONFIG_R 0x02 /**< config false; */
391#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
392#define LYS_STATUS_CURR 0x08 /**< status current; */
393#define LYS_STATUS_DEPRC 0x10 /**< status deprecated; */
394#define LYS_STATUS_OBSLT 0x20 /**< status obsolete; */
395#define LYS_STATUS_MASK 0x38 /**< mask for status value */
396#define LYS_MAND_TRUE 0x40 /**< mandatory true; applicable only to
397 ::lys_node_choice, ::lys_node_leaf and ::lys_node_anydata */
398#define LYS_MAND_FALSE 0x80 /**< mandatory false; applicable only to
399 ::lys_node_choice, ::lys_node_leaf and ::lys_node_anydata */
400#define LYS_MAND_MASK 0xc0 /**< mask for mandatory values */
401#define LYS_ORDBY_SYSTEM 0x100 /**< ordered-by system lists, applicable only to
402 ::lys_node_list and ::lys_node_leaflist */
403#define LYS_ORDBY_USER 0x200 /**< ordered-by user lists, applicable only to
404 ::lys_node_list and ::lys_node_leaflist */
405#define LYS_ORDBY_MASK 0x300 /**< mask for ordered-by flags */
406#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lys_feature */
407#define LYS_AUTOASSIGNED 0x01 /**< value was auto-assigned, applicable only to
408 ::lys_type enum and bits flags */
409#define LYS_YINELEM_TRUE 0x01 /**< yin-element true for extension's argument */
410#define LYS_YINELEM_FALSE 0x02 /**< yin-element false for extension's argument */
411#define LYS_YINELEM_MASK 0x03 /**< mask for yin-element value */
412#define LYS_SET_VALUE 0x01 /**< value attribute is set */
413#define LYS_SET_MAX 0x400 /**< max attribute is set */
414#define LYS_SET_MIN 0x800 /**< min attribute is set */
415#define LYS_SET_REQINST 0x01 /**< require_instance attribute is set */
416
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200417/**
418 * @brief Generic YANG data node
419 */
420struct lysp_node {
421 uint16_t nodetype; /**< type of the node (mandatory) */
422 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
423 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
424 const char *name; /**< node name (mandatory) */
425 const char *dsc; /**< description statement */
426 const char *ref; /**< reference statement */
427 struct lysp_when *when; /**< when statement */
428 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200429 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200430};
431
432/**
433 * @brief Extension structure of the lysp_node for YANG container
434 */
435struct lysp_node_container {
436 uint16_t nodetype; /**< LYS_CONTAINER */
437 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
438 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
439 const char *name; /**< node name (mandatory) */
440 const char *dsc; /**< description statement */
441 const char *ref; /**< reference statement */
442 struct lysp_when *when; /**< when statement */
443 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200444 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200445
446 /* container */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200447 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200448 const char *presence; /**< presence description */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200449 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
450 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200451 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200452 struct lysp_action *actions; /**< list of actions (0-terminated) */
453 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200454};
455
456struct lysp_node_leaf {
457 uint16_t nodetype; /**< LYS_LEAF */
458 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
459 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
460 const char *name; /**< node name (mandatory) */
461 const char *dsc; /**< description statement */
462 const char *ref; /**< reference statement */
463 struct lysp_when *when; /**< when statement */
464 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200465 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200466
467 /* leaf */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200468 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200469 struct lysp_type type; /**< type of the leaf node (mandatory) */
470 const char *units; /**< units of the leaf's type */
471 const char *dflt; /**< default value */
472};
473
474struct lysp_node_leaflist {
475 uint16_t nodetype; /**< LYS_LEAFLIST */
476 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
477 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
478 const char *name; /**< node name (mandatory) */
479 const char *dsc; /**< description statement */
480 const char *ref; /**< reference statement */
481 struct lysp_when *when; /**< when statement */
482 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200483 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200484
485 /* leaf-list */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200486 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200487 struct lysp_type type; /**< type of the leaf node (mandatory) */
488 const char *units; /**< units of the leaf's type */
489 const char **dflts; /**< list of default values (NULL-terminated) */
490 uint32_t min; /**< min-elements constraint */
491 uint32_t max; /**< max-elements constraint, 0 means unbounded */
492};
493
494struct lysp_node_list {
495 uint16_t nodetype; /**< LYS_LIST */
496 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
497 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
498 const char *name; /**< node name (mandatory) */
499 const char *dsc; /**< description statement */
500 const char *ref; /**< reference statement */
501 struct lysp_when *when; /**< when statement */
502 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200503 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200504
505 /* list */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200506 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200507 const char *key; /**< keys specification */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200508 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
509 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200510 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200511 struct lysp_action *actions; /**< list of actions (0-terminated) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200512 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200513 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
514 uint32_t min; /**< min-elements constraint */
515 uint32_t max; /**< max-elements constraint, 0 means unbounded */
516};
517
518struct lysp_node_choice {
519 uint16_t nodetype; /**< LYS_CHOICE */
520 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
521 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
522 const char *name; /**< node name (mandatory) */
523 const char *dsc; /**< description statement */
524 const char *ref; /**< reference statement */
525 struct lysp_when *when; /**< when statement */
526 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200527 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200528
529 /* choice */
530 struct lysp_node *child; /**< list of data nodes (linked list) */
531 const char* dflt; /**< default case */
532};
533
534struct lysp_node_case {
535 uint16_t nodetype; /**< LYS_CASE */
536 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
537 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
538 const char *name; /**< node name (mandatory) */
539 const char *dsc; /**< description statement */
540 const char *ref; /**< reference statement */
541 struct lysp_when *when; /**< when statement */
542 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200543 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200544
545 /* case */
546 struct lysp_node *child; /**< list of data nodes (linked list) */
547};
548
549struct lysp_node_anydata {
550 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
551 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
552 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
553 const char *name; /**< node name (mandatory) */
554 const char *dsc; /**< description statement */
555 const char *ref; /**< reference statement */
556 struct lysp_when *when; /**< when statement */
557 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200558 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200559
560 /* anyxml/anydata */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200561 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200562};
563
564struct lysp_node_uses {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200565 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200566 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
567 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
568 const char *name; /**< grouping name reference (mandatory) */
569 const char *dsc; /**< description statement */
570 const char *ref; /**< reference statement */
571 struct lysp_when *when; /**< when statement */
572 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200573 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200574
575 /* uses */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200576 struct lysp_refine *refines; /**< list of uses's refines (0-terminated) */
577 struct lysp_augment *augments; /**< list of uses's augment (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200578};
579
580/**
581 * @brief YANG input-stmt and output-stmt
582 */
583struct lysp_action_inout {
Michal Vaskobc2559f2018-09-07 10:17:50 +0200584 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
585 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
586 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200587 struct lysp_node *data; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200588 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200589};
590
591/**
592 * @brief YANG rpc-stmt and action-stmt
593 */
594struct lysp_action {
595 const char *name; /**< grouping name reference (mandatory) */
596 const char *dsc; /**< description statement */
597 const char *ref; /**< reference statement */
598 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200599 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
600 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200601 struct lysp_action_inout *input; /**< RPC's/Action's input */
602 struct lysp_action_inout *output;/**< RPC's/Action's output */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200603 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200604 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
605};
606
607/**
608 * @brief YANG notification-stmt
609 */
610struct lysp_notif {
611 const char *name; /**< grouping name reference (mandatory) */
612 const char *dsc; /**< description statement */
613 const char *ref; /**< reference statement */
614 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200615 struct lysp_restr *musts; /**< list of must restrictions (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 data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200619 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200620 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
621};
622
623/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200624 * @brief supported YANG schema version values
625 */
626typedef enum LYS_VERSION {
627 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
628 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
629 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
630} LYS_VERSION;
631
632/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200633 * @brief Printable YANG schema tree structure representing YANG module.
634 *
635 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
636 */
637struct lysp_module {
638 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
639 const char *name; /**< name of the module (mandatory) */
640 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
641 union {
642 /* module */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200643 const char *ns; /**< namespace of the module (module - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200644 /* submodule */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200645 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200646 };
Michal Vaskod5927ca2018-09-07 15:05:32 +0200647 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200648 struct lysp_import *imports; /**< list of imported modules (0-terminated) */
649 struct lysp_include *includes; /**< list of included submodules (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200650 const char *org; /**< party/company responsible for the module */
651 const char *contact; /**< contact information for the module */
652 const char *dsc; /**< description of the module */
653 const char *ref; /**< cross-reference for the module */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200654 struct lysp_revision *revs; /**< list of the module revisions (0-terminated), the first revision
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200655 in the list is always the last (newest) revision of the module */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200656 struct lysp_ext *extensions; /**< list of extension statements (0-terminated) */
657 struct lysp_feature *features; /**< list of feature definitions (0-terminated) */
658 struct lysp_ident *identities; /**< list of identities (0-terminated) */
659 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
660 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200661 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200662 struct lysp_augment *augments; /**< list of augments (0-terminated) */
663 struct lysp_action *rpcs; /**< list of RPCs (0-terminated) */
664 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
665 struct lysp_deviation *deviations; /**< list of deviations (0-terminated) */
666 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200667
Radek Krejcif0fceb62018-09-05 14:58:45 +0200668 uint8_t submodule:1; /**< flag to distinguish main modules and submodules */
669 uint8_t deviated:1; /**< flag if the module is deviated by another module */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200670 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
671 uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is
672 the latest revision found */
Radek Krejcif0fceb62018-09-05 14:58:45 +0200673 uint8_t version:4; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200674};
675
676/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200677 * @brief Free the printable YANG schema tree structure.
678 *
679 * @param[in] module Printable YANG schema tree structure to free.
680 */
681void lysp_module_free(struct lysp_module *module);
682
683/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200684 * @brief Compiled YANG schema tree structure representing YANG module.
685 *
686 * Semantically validated YANG schema tree for data tree parsing.
687 * Contains only the necessary information for the data validation.
688 */
689struct lysc_module {
690};
691
692/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200693 * @brief Compiled YANG data node
694 */
695struct lysc_node {
696};
697
698/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200699 * @brief Available YANG schema tree structures representing YANG module.
700 */
701struct lys_module {
702 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
703 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing */
704};
705
706/** @} */
707
708#endif /* LY_TREE_SCHEMA_H_ */