blob: e503d527b35eb12df3d2833e0b5ea18d71618302 [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
Radek Krejci70853c52018-10-15 14:46:16 +020020#ifdef __cplusplus
21extern "C" {
22#endif
23
Radek Krejci5aeea3a2018-09-05 13:29:36 +020024/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +020025 * @brief XPath representation.
26 */
27struct lyxp_expr;
28
29/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020030 * @brief Macro selector for other LY_ARRAY_* macros, do not use directly!
31 */
32#define LY_ARRAY_SELECT(_1, _2, NAME, ...) NAME
33
34/**
35 * @brief Get void pointer to the item on the INDEX in the ARRAY
36 */
37#define LY_ARRAY_INDEX1(ARRAY, INDEX) ((void*)((uint32_t*)((ARRAY) + INDEX) + 1))
38
39/**
40 * @brief Get the TYPE pointer to the item on the INDEX in the ARRAY
41 */
42#define LY_ARRAY_INDEX2(ARRAY, INDEX, TYPE) ((TYPE*)((uint32_t*)((ARRAY) + INDEX) + 1))
43
44/**
45 * @brief Helper macro to go through sized-arrays with a pointer iterator.
46 *
47 * Use with opening curly bracket (`{`).
48 *
49 * @param[in] ARRAY Array to go through
50 * @param[in] TYPE Type of the records in the ARRAY
51 * @param[out] ITER Iterating pointer to the item being processed in each loop
52 */
53#define LY_ARRAY_FOR_ITER(ARRAY, TYPE, ITER) \
54 for (ITER = LY_ARRAY_INDEX1(ARRAY, 0); \
55 (ARRAY) && ((void*)ITER - (void*)ARRAY - sizeof(uint32_t))/(sizeof(TYPE)) < (*(uint32_t*)(ARRAY)); \
56 ITER = (void*)((TYPE*)ITER + 1))
57
58/**
59 * @brief Helper macro to go through sized-arrays with a numeric iterator.
60 *
61 * Use with opening curly bracket (`{`).
62 *
63 * To access an item with the INDEX value, use always LY_ARRAY_INDEX macro!
64 *
65 * @param[in] ARRAY Array to go through
66 * @param[out] INDEX Iterating index of the item being processed in each loop
67 */
68#define LY_ARRAY_FOR_INDEX(ARRAY, INDEX) \
69 for (INDEX = 0; \
70 ARRAY && INDEX < (*((uint32_t*)(ARRAY))); \
71 ++INDEX)
72
73/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +020074 * @defgroup schematree Schema Tree
75 * @{
76 *
77 * Data structures and functions to manipulate and access schema tree.
78 */
79
Radek Krejci0af5f5d2018-09-07 15:00:30 +020080/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020081 * @brief Get (optionally TYPEd) pointer to the item on the INDEX in the ARRAY
Radek Krejci5fac3592018-10-12 15:23:45 +020082 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +020083 * LY_ARRAY_INDEX(ARRAY, INDEX [, TYPE])
Radek Krejci5fac3592018-10-12 15:23:45 +020084 */
Radek Krejcie53a8dc2018-10-17 12:52:40 +020085#define LY_ARRAY_INDEX(ARRAY, ...) LY_ARRAY_SELECT(__VA_ARGS__, LY_ARRAY_INDEX2, LY_ARRAY_INDEX1)(ARRAY, __VA_ARGS__)
86
87/**
88 * @brief Get a number of records in the ARRAY.
89 */
90#define LY_ARRAY_SIZE(ARRAY) (*((uint32_t*)(ARRAY)))
91
92/**
93 * @brief Sized-array iterator (for-loop).
94 *
95 * Use with opening curly bracket (`{`).
96 *
97 * There are 2 variants:
98 *
99 * LY_ARRAY_FOR(ARRAY, TYPE, ITER)
100 *
101 * Where ARRAY is a sized-array to go through, TYPE is the type of the items in the ARRAY and ITER is a pointer variable
102 * providing the items of the ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_ITER macro
103 *
104 * LY_ARRAY_FOR(ARRAY, INDEX)
105 *
106 * The ARRAY is again a sized-array to go through, the INDEX is a variable (unsigned integer) for storing iterating ARRAY's index
107 * to access the items of ARRAY in the loops. The INDEX is supposed to be used via LY_ARRAY_INDEX macro which can provide the item
108 * in the loop body. This functionality is provided by LY_ARRAY_FOR_INDEX macro.
109 */
110#define LY_ARRAY_FOR(ARRAY, ...) LY_ARRAY_SELECT(__VA_ARGS__, LY_ARRAY_FOR_ITER, LY_ARRAY_FOR_INDEX)(ARRAY, __VA_ARGS__)
Radek Krejci5fac3592018-10-12 15:23:45 +0200111
112/**
113 * @brief Macro to iterate via all sibling elements without affecting the list itself
114 *
115 * Works for all types of nodes despite it is data or schema tree, but all the
116 * parameters must be pointers to the same type.
117 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200118 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200119 *
120 * @param START Pointer to the starting element.
121 * @param ELEM Iterator.
122 */
123#define LY_LIST_FOR(START, ELEM) \
124 for ((ELEM) = (START); \
125 (ELEM); \
126 (ELEM) = (ELEM)->next)
127
128/**
129 * @ingroup datatree
130 * @brief Macro to iterate via all sibling elements allowing to modify the list itself (e.g. removing elements)
131 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200132 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200133 *
134 * @param START Pointer to the starting element.
135 * @param NEXT Temporary storage to allow removing of the current iterator content.
136 * @param ELEM Iterator.
137 */
138#define LY_LIST_FOR_SAFE(START, NEXT, ELEM) \
139 for ((ELEM) = (START); \
140 (ELEM) ? (NEXT = (ELEM)->next, 1) : 0; \
141 (ELEM) = (NEXT))
142
143/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200144 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
145 */
146typedef enum {
147 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
148 LYS_IN_YANG = 1, /**< YANG schema input format */
149 LYS_IN_YIN = 2 /**< YIN schema input format */
150} LYS_INFORMAT;
151
152/**
153 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
154 */
155typedef enum {
156 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
157 LYS_OUT_YANG = 1, /**< YANG schema output format */
158 LYS_OUT_YIN = 2, /**< YIN schema output format */
159 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
160 LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
161 LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */
162} LYS_OUTFORMAT;
163
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200164#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
165
Michal Vaskob55f6c12018-09-12 11:13:15 +0200166#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
167#define LYS_CONTAINER 0x0001 /**< container statement node */
168#define LYS_CHOICE 0x0002 /**< choice statement node */
169#define LYS_LEAF 0x0004 /**< leaf statement node */
170#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
171#define LYS_LIST 0x0010 /**< list statement node */
172#define LYS_ANYXML 0x0020 /**< anyxml statement node */
173#define LYS_CASE 0x0040 /**< case statement node */
174#define LYS_USES 0x0080 /**< uses statement node */
175#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 +0200176
177/**
178 * @brief YANG import-stmt
179 */
180struct lysp_import {
Michal Vaskod5927ca2018-09-07 15:05:32 +0200181 const char *name; /**< name of the module to import (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200182 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200183 const char *dsc; /**< description */
184 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200185 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200186 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
187};
188
189/**
190 * @brief YANG include-stmt
191 */
192struct lysp_include {
Michal Vaskod5927ca2018-09-07 15:05:32 +0200193 const char *name; /**< name of the submodule to include (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200194 const char *dsc; /**< description */
195 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200196 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200197 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
198};
199
200/**
201 * @brief YANG extension-stmt
202 */
203struct lysp_ext {
204 const char *name; /**< extension name */
205 const char *argument; /**< argument name, NULL if not specified */
206 const char *dsc; /**< description statement */
207 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200208 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200209 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
210};
211
212/**
213 * @brief Helper structure for generic storage of the extension instances content.
214 */
215struct lysp_stmt {
216 const char *stmt; /**< identifier of the statement */
217 const char *arg; /**< statement's argument */
218 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200219 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200220};
221
222/**
Michal Vaskod92e42a2018-09-07 08:35:02 +0200223 * @brief Enum of substatements in which extension instances can appear.
224 */
225typedef enum {
226 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
227 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
228 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
229 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
230 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
231 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
232 lys_node_choice and lys_deviate */
233 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
234 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
235 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
236 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
237 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
238 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
239 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
240 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
241 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
242 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
243 belongs-to's prefix) and lys_import */
244 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
245 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
246 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
247 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
248 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
249 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
250 lys_node_leaflist and lys_deviate */
251 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
252 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
253 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
254 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
255 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
256 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
257 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
258 lys_node_anydata and lys_deviate */
259 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
260 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
261 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200262 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200263 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
264 lys_node_leaflist and lys_deviate */
265 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
266 lys_node_leaflist and lys_deviate */
267 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
268 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200269 LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200270} LYEXT_SUBSTMT;
271
272/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200273 * @brief YANG extension instance
274 */
275struct lysp_ext_instance {
276 const char *name; /**< extension identifier, including possible prefix */
277 const char *argument; /**< optional value of the extension's argument */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200278 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
279 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
280 the index of that substatement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200281 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200282};
283
284/**
285 * @brief YANG feature-stmt
286 */
287struct lysp_feature {
288 const char *name; /**< feature name (mandatory) */
289 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
290 const char *dsc; /**< description statement */
291 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200292 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200293 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
294};
295
296/**
297 * @brief YANG identity-stmt
298 */
299struct lysp_ident {
300 const char *name; /**< identity name (mandatory), including possible prefix */
301 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
302 const char **bases; /**< list of base identifiers (NULL-terminated) */
303 const char *dsc; /**< description statement */
304 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200305 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200306 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
307};
308
Michal Vasko71e64ca2018-09-07 16:30:29 +0200309/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200310 * @brief Covers restrictions: range, length, pattern, must
311 */
312struct lysp_restr {
313 const char *arg; /**< The restriction expression/value (mandatory);
314 in case of pattern restriction, the first byte has a special meaning:
315 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
316 const char *emsg; /**< error-message */
317 const char *eapptag; /**< error-app-tag value */
318 const char *dsc; /**< description */
319 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200320 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200321};
322
323/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200324 * @brief YANG revision-stmt
325 */
326struct lysp_revision {
327 char rev[LY_REV_SIZE]; /**< revision date (madatory) */
328 const char *dsc; /**< description statement */
329 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200330 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200331};
332
333/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200334 * @brief Enumeration/Bit value definition
335 */
336struct lysp_type_enum {
337 const char *name; /**< name (mandatory) */
338 const char *dsc; /**< description statement */
339 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200340 int64_t value; /**< enum's value or bit's position */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200341 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200342 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200343 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
344 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200345};
346
347/**
348 * @brief YANG type-stmt
349 *
350 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
351 */
352struct lysp_type {
353 const char *name; /**< name of the type (mandatory) */
354 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
355 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200356 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
357 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
358 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200359 const char *path; /**< path - leafref */
360 const char **bases; /**< list of base identifiers (NULL-terminated) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200361 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
362 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200363
364 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
365 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200366 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_SET_REQINST allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200367};
368
369/**
370 * @brief YANG typedef-stmt
371 */
372struct lysp_tpdf {
373 const char *name; /**< name of the newly defined type (mandatory) */
374 const char *units; /**< units of the newly defined type */
375 const char *dflt; /**< default value of the newly defined type */
376 const char *dsc; /**< description statement */
377 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200378 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200379 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
380 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
381};
382
383/**
384 * @brief YANG grouping-stmt
385 */
386struct lysp_grp {
387 const char *name; /**< grouping name (mandatory) */
388 const char *dsc; /**< description statement */
389 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200390 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
391 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200392 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200393 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
394 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
395 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200396 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
397};
398
399/**
400 * @brief YANG when-stmt
401 */
402struct lysp_when {
403 const char *cond; /**< specified condition (mandatory) */
404 const char *dsc; /**< description statement */
405 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200406 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200407};
408
409/**
410 * @brief YANG refine-stmt
411 */
412struct lysp_refine {
413 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
414 const char *dsc; /**< description statement */
415 const char *ref; /**< reference statement */
416 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200417 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200418 const char *presence; /**< presence description */
419 const char **dflts; /**< list of default values (NULL-terminated) */
420 uint32_t min; /**< min-elements constraint */
421 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200422 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200423 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
424};
425
426/**
427 * @brief YANG uses-augment-stmt and augment-stmt
428 */
429struct lysp_augment {
430 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
431 const char *dsc; /**< description statement */
432 const char *ref; /**< reference statement */
433 struct lysp_when *when; /**< when statement */
434 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
435 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200436 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
437 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
438 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200439 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
440};
441
442/**
443 * @defgroup deviatetypes Deviate types
444 * @{
445 */
446#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
447#define LYS_DEV_ADD 2 /**< deviate type add */
448#define LYS_DEV_DELETE 3 /**< deviate type delete */
449#define LYS_DEV_REPLACE 4 /**< deviate type replace */
450/** @} */
451
452/**
453 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
454 */
455struct lysp_deviate {
456 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
457 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200458 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200459};
460
461struct lysp_deviate_add {
462 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
463 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200464 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200465 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200466 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200467 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
468 const char **dflts; /**< list of default values (NULL-terminated) */
469 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
470 uint32_t min; /**< min-elements constraint */
471 uint32_t max; /**< max-elements constraint, 0 means unbounded */
472};
473
474struct lysp_deviate_del {
475 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
476 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200477 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200478 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200479 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200480 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
481 const char **dflts; /**< list of default values (NULL-terminated) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200482 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200483};
484
485struct lysp_deviate_rpl {
486 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
487 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200488 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200489 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200490 const char *units; /**< units of the values */
491 const char *dflt; /**< default value */
492 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
493 uint32_t min; /**< min-elements constraint */
494 uint32_t max; /**< max-elements constraint, 0 means unbounded */
495};
496
497struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200498 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200499 const char *dsc; /**< description statement */
500 const char *ref; /**< reference statement */
501 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200502 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200503};
504
Michal Vaskob55f6c12018-09-12 11:13:15 +0200505#define LYS_CONFIG_W 0x01 /**< config true; */
506#define LYS_CONFIG_R 0x02 /**< config false; */
507#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
508#define LYS_STATUS_CURR 0x08 /**< status current; */
509#define LYS_STATUS_DEPRC 0x10 /**< status deprecated; */
510#define LYS_STATUS_OBSLT 0x20 /**< status obsolete; */
511#define LYS_STATUS_MASK 0x38 /**< mask for status value */
512#define LYS_MAND_TRUE 0x40 /**< mandatory true; applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200513 ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf
514 and ::lysp_node_anydata/::lysc_node_anydata */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200515#define LYS_MAND_FALSE 0x80 /**< mandatory false; applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200516 ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf
517 and ::lysp_node_anydata/::lysc_node_anydata */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200518#define LYS_MAND_MASK 0xc0 /**< mask for mandatory values */
519#define LYS_ORDBY_SYSTEM 0x100 /**< ordered-by system lists, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200520 ::lysp_node_list/lysc_node_list and ::lysp_node_leaflist/::lysc_node_list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200521#define LYS_ORDBY_USER 0x200 /**< ordered-by user lists, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200522 ::lysp_node_list/lysc_node_list and ::lysp_node_leaflist/::lysc_node_list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200523#define LYS_ORDBY_MASK 0x300 /**< mask for ordered-by flags */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200524#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysp_feature/::lysc_feature */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200525#define LYS_AUTOASSIGNED 0x01 /**< value was auto-assigned, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200526 ::lysp_type/::lysc_type enum and bits flags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200527#define LYS_YINELEM_TRUE 0x01 /**< yin-element true for extension's argument */
528#define LYS_YINELEM_FALSE 0x02 /**< yin-element false for extension's argument */
529#define LYS_YINELEM_MASK 0x03 /**< mask for yin-element value */
530#define LYS_SET_VALUE 0x01 /**< value attribute is set */
531#define LYS_SET_MAX 0x400 /**< max attribute is set */
532#define LYS_SET_MIN 0x800 /**< min attribute is set */
533#define LYS_SET_REQINST 0x01 /**< require_instance attribute is set */
534
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200535/**
536 * @brief Generic YANG data node
537 */
538struct lysp_node {
539 uint16_t nodetype; /**< type of the node (mandatory) */
540 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
541 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
542 const char *name; /**< node name (mandatory) */
543 const char *dsc; /**< description statement */
544 const char *ref; /**< reference statement */
545 struct lysp_when *when; /**< when statement */
546 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200547 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200548};
549
550/**
551 * @brief Extension structure of the lysp_node for YANG container
552 */
553struct lysp_node_container {
554 uint16_t nodetype; /**< LYS_CONTAINER */
555 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
556 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
557 const char *name; /**< node name (mandatory) */
558 const char *dsc; /**< description statement */
559 const char *ref; /**< reference statement */
560 struct lysp_when *when; /**< when statement */
561 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200562 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200563
564 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200565 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200566 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200567 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
568 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200569 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200570 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
571 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200572};
573
574struct lysp_node_leaf {
575 uint16_t nodetype; /**< LYS_LEAF */
576 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
577 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
578 const char *name; /**< node name (mandatory) */
579 const char *dsc; /**< description statement */
580 const char *ref; /**< reference statement */
581 struct lysp_when *when; /**< when statement */
582 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200583 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200584
585 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200586 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200587 struct lysp_type type; /**< type of the leaf node (mandatory) */
588 const char *units; /**< units of the leaf's type */
589 const char *dflt; /**< default value */
590};
591
592struct lysp_node_leaflist {
593 uint16_t nodetype; /**< LYS_LEAFLIST */
594 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
595 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
596 const char *name; /**< node name (mandatory) */
597 const char *dsc; /**< description statement */
598 const char *ref; /**< reference statement */
599 struct lysp_when *when; /**< when statement */
600 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200601 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200602
603 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200604 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200605 struct lysp_type type; /**< type of the leaf node (mandatory) */
606 const char *units; /**< units of the leaf's type */
607 const char **dflts; /**< list of default values (NULL-terminated) */
608 uint32_t min; /**< min-elements constraint */
609 uint32_t max; /**< max-elements constraint, 0 means unbounded */
610};
611
612struct lysp_node_list {
613 uint16_t nodetype; /**< LYS_LIST */
614 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
615 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
616 const char *name; /**< node name (mandatory) */
617 const char *dsc; /**< description statement */
618 const char *ref; /**< reference statement */
619 struct lysp_when *when; /**< when statement */
620 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200621 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200622
623 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200624 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200625 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200626 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
627 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200628 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200629 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
630 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200631 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
632 uint32_t min; /**< min-elements constraint */
633 uint32_t max; /**< max-elements constraint, 0 means unbounded */
634};
635
636struct lysp_node_choice {
637 uint16_t nodetype; /**< LYS_CHOICE */
638 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
639 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
640 const char *name; /**< node name (mandatory) */
641 const char *dsc; /**< description statement */
642 const char *ref; /**< reference statement */
643 struct lysp_when *when; /**< when statement */
644 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200645 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200646
647 /* choice */
648 struct lysp_node *child; /**< list of data nodes (linked list) */
649 const char* dflt; /**< default case */
650};
651
652struct lysp_node_case {
653 uint16_t nodetype; /**< LYS_CASE */
654 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
655 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
656 const char *name; /**< node name (mandatory) */
657 const char *dsc; /**< description statement */
658 const char *ref; /**< reference statement */
659 struct lysp_when *when; /**< when statement */
660 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200661 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200662
663 /* case */
664 struct lysp_node *child; /**< list of data nodes (linked list) */
665};
666
667struct lysp_node_anydata {
668 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
669 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
670 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
671 const char *name; /**< node name (mandatory) */
672 const char *dsc; /**< description statement */
673 const char *ref; /**< reference statement */
674 struct lysp_when *when; /**< when statement */
675 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200676 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200677
678 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200679 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200680};
681
682struct lysp_node_uses {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200683 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200684 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
685 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
686 const char *name; /**< grouping name reference (mandatory) */
687 const char *dsc; /**< description statement */
688 const char *ref; /**< reference statement */
689 struct lysp_when *when; /**< when statement */
690 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200691 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200692
693 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200694 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
695 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200696};
697
698/**
699 * @brief YANG input-stmt and output-stmt
700 */
701struct lysp_action_inout {
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200702 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
703 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
704 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200705 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200706 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200707};
708
709/**
710 * @brief YANG rpc-stmt and action-stmt
711 */
712struct lysp_action {
713 const char *name; /**< grouping name reference (mandatory) */
714 const char *dsc; /**< description statement */
715 const char *ref; /**< reference statement */
716 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200717 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
718 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200719 struct lysp_action_inout *input; /**< RPC's/Action's input */
720 struct lysp_action_inout *output;/**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200721 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200722 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
723};
724
725/**
726 * @brief YANG notification-stmt
727 */
728struct lysp_notif {
729 const char *name; /**< grouping name reference (mandatory) */
730 const char *dsc; /**< description statement */
731 const char *ref; /**< reference statement */
732 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200733 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
734 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
735 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200736 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200737 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200738 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
739};
740
741/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200742 * @brief supported YANG schema version values
743 */
744typedef enum LYS_VERSION {
745 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
746 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
747 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
748} LYS_VERSION;
749
750/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200751 * @brief Printable YANG schema tree structure representing YANG module.
752 *
753 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
754 */
755struct lysp_module {
756 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
757 const char *name; /**< name of the module (mandatory) */
758 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
759 union {
760 /* module */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200761 const char *ns; /**< namespace of the module (module - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200762 /* submodule */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200763 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200764 };
Michal Vaskod5927ca2018-09-07 15:05:32 +0200765 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200766 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
767 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200768 const char *org; /**< party/company responsible for the module */
769 const char *contact; /**< contact information for the module */
770 const char *dsc; /**< description of the module */
771 const char *ref; /**< cross-reference for the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200772 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200773 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200774 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
775 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
776 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
777 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
778 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200779 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200780 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
781 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
782 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
783 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
784 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200785
Radek Krejcif0fceb62018-09-05 14:58:45 +0200786 uint8_t submodule:1; /**< flag to distinguish main modules and submodules */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200787 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
788 uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is
789 the latest revision found */
Radek Krejcif0fceb62018-09-05 14:58:45 +0200790 uint8_t version:4; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200791};
792
793/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200794 * @brief Free the printable YANG schema tree structure.
795 *
796 * @param[in] module Printable YANG schema tree structure to free.
797 */
798void lysp_module_free(struct lysp_module *module);
799
800/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200801 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200802 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200803struct lysc_when {
804 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200805 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200806};
807
808/**
809 * @brief YANG feature-stmt
810 */
811struct lysc_feature {
812 const char *name; /**< feature name (mandatory) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200813 struct lysc_feature *depfeatures;/**< list of other features depending on this one ([sized array](@ref sizedarrays)) */
814 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
815 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200816 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
817 #LYS_FENABLED values allowed */
818};
819
820struct lysc_iffeature {
821 struct lysc_feature *features; /**< array of pointers to the features used in expression, size depends on content of expr */
822 uint32_t expr[]; /**< 2bits array describing the if-feature expression in prefix format */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200823};
824
825/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200826 * @brief Compiled YANG data node
827 */
828struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200829 uint16_t nodetype; /**< type of the node (mandatory) */
830 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
831 struct lysp_node *sp; /**< link to the simply parsed (SP) original of the node, NULL if the SP schema was removed. */
832 struct lysc_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
833 const char *name; /**< node name (mandatory) */
834 struct lysc_when *when; /**< when statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200835 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
836 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200837};
838
839/**
840 * @brief Compiled YANG schema tree structure representing YANG module.
841 *
842 * Semantically validated YANG schema tree for data tree parsing.
843 * Contains only the necessary information for the data validation.
844 */
845struct lysc_module {
846 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
847 const char *name; /**< name of the module (mandatory) */
848 const char *ns; /**< namespace of the module (mandatory) */
849 const char *prefix; /**< module prefix (mandatory) */
850
851
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200852 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200853
854
855 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
856 uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is
857 the latest revision found */
858 uint8_t version:4; /**< yang-version (LYS_VERSION values) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200859};
860
861/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200862 * @brief Available YANG schema tree structures representing YANG module.
863 */
864struct lys_module {
865 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
866 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing */
867};
868
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200869
870/**
871 * @defgroup scflags Schema compile flags
872 * @ingroup schematree
873 *
874 * @{
875 */
876#define LYSC_OPT_FREE_SP 1 /**< Free the input printable schema */
877
878/**
879 * @}
880 */
881
882/**
883 * @brief Compile printable schema into a validated schema linking all the references.
884 *
885 * @param[in] sp Simple parsed printable schema to compile. Can be changed according to the provided options.
886 * @param[in] options Various options to modify compiler behavior, see [compile flags](@ref scflags).
887 * @param[out] sc Resulting compiled schema structure.
888 * @return LY_ERR value.
889 */
890LY_ERR lys_compile(struct lysp_module *sp, int options, struct lysc_module **sc);
891
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200892/** @} */
893
Radek Krejci70853c52018-10-15 14:46:16 +0200894#ifdef __cplusplus
895}
896#endif
897
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200898#endif /* LY_TREE_SCHEMA_H_ */