blob: 12394ebad16fecb20b3597eca664e60c41ae39d4 [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/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020035 * @brief Helper macro to go through sized-arrays with a pointer iterator.
36 *
37 * Use with opening curly bracket (`{`).
38 *
39 * @param[in] ARRAY Array to go through
40 * @param[in] TYPE Type of the records in the ARRAY
41 * @param[out] ITER Iterating pointer to the item being processed in each loop
42 */
43#define LY_ARRAY_FOR_ITER(ARRAY, TYPE, ITER) \
Radek Krejci2c4e7172018-10-19 15:56:26 +020044 for (ITER = ARRAY; \
45 (ARRAY) && ((void*)ITER - (void*)ARRAY)/(sizeof(TYPE)) < (*((uint32_t*)(ARRAY) - 1)); \
Radek Krejcie53a8dc2018-10-17 12:52:40 +020046 ITER = (void*)((TYPE*)ITER + 1))
47
48/**
49 * @brief Helper macro to go through sized-arrays with a numeric iterator.
50 *
51 * Use with opening curly bracket (`{`).
52 *
53 * To access an item with the INDEX value, use always LY_ARRAY_INDEX macro!
54 *
55 * @param[in] ARRAY Array to go through
56 * @param[out] INDEX Iterating index of the item being processed in each loop
57 */
58#define LY_ARRAY_FOR_INDEX(ARRAY, INDEX) \
59 for (INDEX = 0; \
Radek Krejci2c4e7172018-10-19 15:56:26 +020060 ARRAY && INDEX < (*((uint32_t*)(ARRAY) - 1)); \
Radek Krejcie53a8dc2018-10-17 12:52:40 +020061 ++INDEX)
62
63/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +020064 * @defgroup schematree Schema Tree
65 * @{
66 *
67 * Data structures and functions to manipulate and access schema tree.
68 */
69
Radek Krejci0af5f5d2018-09-07 15:00:30 +020070/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020071 * @brief Get a number of records in the ARRAY.
Radek Krejci86d106e2018-10-18 09:53:19 +020072 *
73 * Does not check if array exists!
Radek Krejcie53a8dc2018-10-17 12:52:40 +020074 */
Radek Krejci2c4e7172018-10-19 15:56:26 +020075#define LY_ARRAY_SIZE(ARRAY) (*((uint32_t*)(ARRAY) - 1))
Radek Krejcie53a8dc2018-10-17 12:52:40 +020076
77/**
78 * @brief Sized-array iterator (for-loop).
79 *
80 * Use with opening curly bracket (`{`).
81 *
82 * There are 2 variants:
83 *
84 * LY_ARRAY_FOR(ARRAY, TYPE, ITER)
85 *
86 * 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
87 * providing the items of the ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_ITER macro
88 *
89 * LY_ARRAY_FOR(ARRAY, INDEX)
90 *
91 * The ARRAY is again a sized-array to go through, the INDEX is a variable (unsigned integer) for storing iterating ARRAY's index
Radek Krejci2c4e7172018-10-19 15:56:26 +020092 * to access the items of ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_INDEX macro.
Radek Krejcie53a8dc2018-10-17 12:52:40 +020093 */
94#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 +020095
96/**
97 * @brief Macro to iterate via all sibling elements without affecting the list itself
98 *
99 * Works for all types of nodes despite it is data or schema tree, but all the
100 * parameters must be pointers to the same type.
101 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200102 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200103 *
104 * @param START Pointer to the starting element.
105 * @param ELEM Iterator.
106 */
107#define LY_LIST_FOR(START, ELEM) \
108 for ((ELEM) = (START); \
109 (ELEM); \
110 (ELEM) = (ELEM)->next)
111
112/**
113 * @ingroup datatree
114 * @brief Macro to iterate via all sibling elements allowing to modify the list itself (e.g. removing elements)
115 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200116 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200117 *
118 * @param START Pointer to the starting element.
119 * @param NEXT Temporary storage to allow removing of the current iterator content.
120 * @param ELEM Iterator.
121 */
122#define LY_LIST_FOR_SAFE(START, NEXT, ELEM) \
123 for ((ELEM) = (START); \
124 (ELEM) ? (NEXT = (ELEM)->next, 1) : 0; \
125 (ELEM) = (NEXT))
126
127/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200128 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
129 */
130typedef enum {
131 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
132 LYS_IN_YANG = 1, /**< YANG schema input format */
133 LYS_IN_YIN = 2 /**< YIN schema input format */
134} LYS_INFORMAT;
135
136/**
137 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
138 */
139typedef enum {
140 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
141 LYS_OUT_YANG = 1, /**< YANG schema output format */
142 LYS_OUT_YIN = 2, /**< YIN schema output format */
143 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
144 LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
145 LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */
146} LYS_OUTFORMAT;
147
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200148#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
149
Michal Vaskob55f6c12018-09-12 11:13:15 +0200150#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
151#define LYS_CONTAINER 0x0001 /**< container statement node */
152#define LYS_CHOICE 0x0002 /**< choice statement node */
153#define LYS_LEAF 0x0004 /**< leaf statement node */
154#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
155#define LYS_LIST 0x0010 /**< list statement node */
156#define LYS_ANYXML 0x0020 /**< anyxml statement node */
157#define LYS_CASE 0x0040 /**< case statement node */
158#define LYS_USES 0x0080 /**< uses statement node */
159#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 +0200160
161/**
162 * @brief YANG import-stmt
163 */
164struct lysp_import {
Michal Vaskod5927ca2018-09-07 15:05:32 +0200165 const char *name; /**< name of the module to import (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200166 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200167 const char *dsc; /**< description */
168 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200169 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200170 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
171};
172
173/**
174 * @brief YANG include-stmt
175 */
176struct lysp_include {
Michal Vaskod5927ca2018-09-07 15:05:32 +0200177 const char *name; /**< name of the submodule to include (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200178 const char *dsc; /**< description */
179 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200180 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200181 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
182};
183
184/**
185 * @brief YANG extension-stmt
186 */
187struct lysp_ext {
188 const char *name; /**< extension name */
189 const char *argument; /**< argument name, NULL if not specified */
190 const char *dsc; /**< description statement */
191 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200192 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200193 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
194};
195
196/**
197 * @brief Helper structure for generic storage of the extension instances content.
198 */
199struct lysp_stmt {
200 const char *stmt; /**< identifier of the statement */
201 const char *arg; /**< statement's argument */
202 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200203 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200204};
205
206/**
Michal Vaskod92e42a2018-09-07 08:35:02 +0200207 * @brief Enum of substatements in which extension instances can appear.
208 */
209typedef enum {
210 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
211 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
212 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
213 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
214 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
215 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
216 lys_node_choice and lys_deviate */
217 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
218 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
219 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
220 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
221 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
222 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
223 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
224 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
225 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
226 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
227 belongs-to's prefix) and lys_import */
228 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
229 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
230 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
231 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
232 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
233 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
234 lys_node_leaflist and lys_deviate */
235 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
236 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
237 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
238 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
239 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
240 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
241 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
242 lys_node_anydata and lys_deviate */
243 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
244 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
245 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200246 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200247 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
248 lys_node_leaflist and lys_deviate */
249 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
250 lys_node_leaflist and lys_deviate */
251 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
252 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200253 LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200254} LYEXT_SUBSTMT;
255
256/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200257 * @brief YANG extension instance
258 */
259struct lysp_ext_instance {
260 const char *name; /**< extension identifier, including possible prefix */
261 const char *argument; /**< optional value of the extension's argument */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200262 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
263 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
264 the index of that substatement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200265 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200266};
267
268/**
269 * @brief YANG feature-stmt
270 */
271struct lysp_feature {
272 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200273 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200274 const char *dsc; /**< description statement */
275 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200276 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200277 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
278};
279
280/**
281 * @brief YANG identity-stmt
282 */
283struct lysp_ident {
284 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200285 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
286 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200287 const char *dsc; /**< description statement */
288 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200289 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200290 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
291};
292
Michal Vasko71e64ca2018-09-07 16:30:29 +0200293/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200294 * @brief Covers restrictions: range, length, pattern, must
295 */
296struct lysp_restr {
297 const char *arg; /**< The restriction expression/value (mandatory);
298 in case of pattern restriction, the first byte has a special meaning:
299 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
300 const char *emsg; /**< error-message */
301 const char *eapptag; /**< error-app-tag value */
302 const char *dsc; /**< description */
303 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200304 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200305};
306
307/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200308 * @brief YANG revision-stmt
309 */
310struct lysp_revision {
311 char rev[LY_REV_SIZE]; /**< revision date (madatory) */
312 const char *dsc; /**< description statement */
313 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200314 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200315};
316
317/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200318 * @brief Enumeration/Bit value definition
319 */
320struct lysp_type_enum {
321 const char *name; /**< name (mandatory) */
322 const char *dsc; /**< description statement */
323 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200324 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200325 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200326 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200327 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
328 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200329};
330
331/**
332 * @brief YANG type-stmt
333 *
334 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
335 */
336struct lysp_type {
337 const char *name; /**< name of the type (mandatory) */
338 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
339 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200340 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
341 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
342 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200343 const char *path; /**< path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200344 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200345 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
346 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200347
348 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
349 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200350 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_SET_REQINST allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200351};
352
353/**
354 * @brief YANG typedef-stmt
355 */
356struct lysp_tpdf {
357 const char *name; /**< name of the newly defined type (mandatory) */
358 const char *units; /**< units of the newly defined type */
359 const char *dflt; /**< default value of the newly defined type */
360 const char *dsc; /**< description statement */
361 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200362 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200363 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
364 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
365};
366
367/**
368 * @brief YANG grouping-stmt
369 */
370struct lysp_grp {
371 const char *name; /**< grouping name (mandatory) */
372 const char *dsc; /**< description statement */
373 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200374 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
375 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200376 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200377 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
378 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
379 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200380 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
381};
382
383/**
384 * @brief YANG when-stmt
385 */
386struct lysp_when {
387 const char *cond; /**< specified condition (mandatory) */
388 const char *dsc; /**< description statement */
389 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200390 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200391};
392
393/**
394 * @brief YANG refine-stmt
395 */
396struct lysp_refine {
397 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
398 const char *dsc; /**< description statement */
399 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200400 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200401 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200402 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200403 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200404 uint32_t min; /**< min-elements constraint */
405 uint32_t max; /**< max-elements constraint, 0 means unbounded */
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 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
408};
409
410/**
411 * @brief YANG uses-augment-stmt and augment-stmt
412 */
413struct lysp_augment {
414 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
415 const char *dsc; /**< description statement */
416 const char *ref; /**< reference statement */
417 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200418 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200419 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200420 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
421 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
422 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) - only LYS_STATUS_* values are allowed */
424};
425
426/**
427 * @defgroup deviatetypes Deviate types
428 * @{
429 */
430#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
431#define LYS_DEV_ADD 2 /**< deviate type add */
432#define LYS_DEV_DELETE 3 /**< deviate type delete */
433#define LYS_DEV_REPLACE 4 /**< deviate type replace */
434/** @} */
435
436/**
437 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
438 */
439struct lysp_deviate {
440 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
441 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200442 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200443};
444
445struct lysp_deviate_add {
446 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
447 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200448 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200449 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200450 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200451 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
452 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200453 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
454 uint32_t min; /**< min-elements constraint */
455 uint32_t max; /**< max-elements constraint, 0 means unbounded */
456};
457
458struct lysp_deviate_del {
459 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
460 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200461 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200462 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200463 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200464 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
465 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200466 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200467};
468
469struct lysp_deviate_rpl {
470 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
471 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200472 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200473 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200474 const char *units; /**< units of the values */
475 const char *dflt; /**< default value */
476 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
477 uint32_t min; /**< min-elements constraint */
478 uint32_t max; /**< max-elements constraint, 0 means unbounded */
479};
480
481struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200482 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200483 const char *dsc; /**< description statement */
484 const char *ref; /**< reference statement */
485 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200486 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200487};
488
Michal Vaskob55f6c12018-09-12 11:13:15 +0200489#define LYS_CONFIG_W 0x01 /**< config true; */
490#define LYS_CONFIG_R 0x02 /**< config false; */
491#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
492#define LYS_STATUS_CURR 0x08 /**< status current; */
493#define LYS_STATUS_DEPRC 0x10 /**< status deprecated; */
494#define LYS_STATUS_OBSLT 0x20 /**< status obsolete; */
495#define LYS_STATUS_MASK 0x38 /**< mask for status value */
496#define LYS_MAND_TRUE 0x40 /**< mandatory true; applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200497 ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf
498 and ::lysp_node_anydata/::lysc_node_anydata */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200499#define LYS_MAND_FALSE 0x80 /**< mandatory false; applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200500 ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf
501 and ::lysp_node_anydata/::lysc_node_anydata */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200502#define LYS_MAND_MASK 0xc0 /**< mask for mandatory values */
503#define LYS_ORDBY_SYSTEM 0x100 /**< ordered-by system lists, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200504 ::lysp_node_list/lysc_node_list and ::lysp_node_leaflist/::lysc_node_list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200505#define LYS_ORDBY_USER 0x200 /**< ordered-by user lists, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200506 ::lysp_node_list/lysc_node_list and ::lysp_node_leaflist/::lysc_node_list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200507#define LYS_ORDBY_MASK 0x300 /**< mask for ordered-by flags */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200508#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysp_feature/::lysc_feature */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200509#define LYS_AUTOASSIGNED 0x01 /**< value was auto-assigned, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200510 ::lysp_type/::lysc_type enum and bits flags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200511#define LYS_YINELEM_TRUE 0x01 /**< yin-element true for extension's argument */
512#define LYS_YINELEM_FALSE 0x02 /**< yin-element false for extension's argument */
513#define LYS_YINELEM_MASK 0x03 /**< mask for yin-element value */
514#define LYS_SET_VALUE 0x01 /**< value attribute is set */
515#define LYS_SET_MAX 0x400 /**< max attribute is set */
516#define LYS_SET_MIN 0x800 /**< min attribute is set */
517#define LYS_SET_REQINST 0x01 /**< require_instance attribute is set */
518
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200519/**
520 * @brief Generic YANG data node
521 */
522struct lysp_node {
523 uint16_t nodetype; /**< type of the node (mandatory) */
524 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
525 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
526 const char *name; /**< node name (mandatory) */
527 const char *dsc; /**< description statement */
528 const char *ref; /**< reference statement */
529 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200530 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200531 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200532};
533
534/**
535 * @brief Extension structure of the lysp_node for YANG container
536 */
537struct lysp_node_container {
538 uint16_t nodetype; /**< LYS_CONTAINER */
539 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
540 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
541 const char *name; /**< node name (mandatory) */
542 const char *dsc; /**< description statement */
543 const char *ref; /**< reference statement */
544 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200545 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200546 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200547
548 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200549 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200550 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200551 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
552 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200553 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200554 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
555 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200556};
557
558struct lysp_node_leaf {
559 uint16_t nodetype; /**< LYS_LEAF */
560 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
561 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
562 const char *name; /**< node name (mandatory) */
563 const char *dsc; /**< description statement */
564 const char *ref; /**< reference statement */
565 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200566 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200567 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200568
569 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200570 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200571 struct lysp_type type; /**< type of the leaf node (mandatory) */
572 const char *units; /**< units of the leaf's type */
573 const char *dflt; /**< default value */
574};
575
576struct lysp_node_leaflist {
577 uint16_t nodetype; /**< LYS_LEAFLIST */
578 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
579 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
580 const char *name; /**< node name (mandatory) */
581 const char *dsc; /**< description statement */
582 const char *ref; /**< reference statement */
583 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200584 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200585 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200586
587 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200588 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200589 struct lysp_type type; /**< type of the leaf node (mandatory) */
590 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200591 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200592 uint32_t min; /**< min-elements constraint */
593 uint32_t max; /**< max-elements constraint, 0 means unbounded */
594};
595
596struct lysp_node_list {
597 uint16_t nodetype; /**< LYS_LIST */
598 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
599 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
600 const char *name; /**< node name (mandatory) */
601 const char *dsc; /**< description statement */
602 const char *ref; /**< reference statement */
603 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200604 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200605 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200606
607 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200608 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200609 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200610 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
611 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200612 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200613 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
614 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200615 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200616 uint32_t min; /**< min-elements constraint */
617 uint32_t max; /**< max-elements constraint, 0 means unbounded */
618};
619
620struct lysp_node_choice {
621 uint16_t nodetype; /**< LYS_CHOICE */
622 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
623 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
624 const char *name; /**< node name (mandatory) */
625 const char *dsc; /**< description statement */
626 const char *ref; /**< reference statement */
627 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200628 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200629 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200630
631 /* choice */
632 struct lysp_node *child; /**< list of data nodes (linked list) */
633 const char* dflt; /**< default case */
634};
635
636struct lysp_node_case {
637 uint16_t nodetype; /**< LYS_CASE */
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 */
Radek Krejci151a5b72018-10-19 14:21:44 +0200644 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
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 /* case */
648 struct lysp_node *child; /**< list of data nodes (linked list) */
649};
650
651struct lysp_node_anydata {
652 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
653 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
654 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
655 const char *name; /**< node name (mandatory) */
656 const char *dsc; /**< description statement */
657 const char *ref; /**< reference statement */
658 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200659 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200660 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200661
662 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200663 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200664};
665
666struct lysp_node_uses {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200667 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200668 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
669 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
670 const char *name; /**< grouping name reference (mandatory) */
671 const char *dsc; /**< description statement */
672 const char *ref; /**< reference statement */
673 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200674 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200675 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200676
677 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200678 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
679 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200680};
681
682/**
683 * @brief YANG input-stmt and output-stmt
684 */
685struct lysp_action_inout {
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200686 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
687 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
688 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200689 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200690 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200691};
692
693/**
694 * @brief YANG rpc-stmt and action-stmt
695 */
696struct lysp_action {
697 const char *name; /**< grouping name reference (mandatory) */
698 const char *dsc; /**< description statement */
699 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200700 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200701 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
702 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200703 struct lysp_action_inout *input; /**< RPC's/Action's input */
704 struct lysp_action_inout *output;/**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200705 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200706 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
707};
708
709/**
710 * @brief YANG notification-stmt
711 */
712struct lysp_notif {
713 const char *name; /**< grouping name reference (mandatory) */
714 const char *dsc; /**< description statement */
715 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200716 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200717 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
718 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
719 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200720 struct lysp_node *data; /**< list of data nodes (linked list) */
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) - only LYS_STATUS_* values are allowed */
723};
724
725/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200726 * @brief supported YANG schema version values
727 */
728typedef enum LYS_VERSION {
729 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
730 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
731 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
732} LYS_VERSION;
733
734/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200735 * @brief Printable YANG schema tree structure representing YANG module.
736 *
737 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
738 */
739struct lysp_module {
740 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
741 const char *name; /**< name of the module (mandatory) */
742 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
743 union {
744 /* module */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200745 const char *ns; /**< namespace of the module (module - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200746 /* submodule */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200747 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200748 };
Michal Vaskod5927ca2018-09-07 15:05:32 +0200749 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200750 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
751 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200752 const char *org; /**< party/company responsible for the module */
753 const char *contact; /**< contact information for the module */
754 const char *dsc; /**< description of the module */
755 const char *ref; /**< cross-reference for the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200756 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200757 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200758 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
759 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
760 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
761 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
762 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200763 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200764 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
765 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
766 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
767 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
768 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200769
Radek Krejcif0fceb62018-09-05 14:58:45 +0200770 uint8_t submodule:1; /**< flag to distinguish main modules and submodules */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200771 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
772 uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is
773 the latest revision found */
Radek Krejcif0fceb62018-09-05 14:58:45 +0200774 uint8_t version:4; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200775};
776
777/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200778 * @brief Free the printable YANG schema tree structure.
779 *
780 * @param[in] module Printable YANG schema tree structure to free.
781 */
782void lysp_module_free(struct lysp_module *module);
783
784/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200785 * @brief YANG import-stmt
786 */
787struct lysc_import {
788 struct lysc_module *module; /**< link to the imported module */
789 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
790 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
791};
792
793/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200794 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200795 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200796struct lysc_when {
797 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200798 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200799};
800
801/**
802 * @brief YANG feature-stmt
803 */
804struct lysc_feature {
805 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200806 struct lysc_feature **depfeatures;/**< list of pointers to other features depending on this one ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200807 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
808 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200809 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
810 #LYS_FENABLED values allowed */
811};
812
Radek Krejci151a5b72018-10-19 14:21:44 +0200813/**
814 * @defgroup ifftokens if-feature expression tokens
815 * Tokens of if-feature expression used in ::lysc_iffeature#expr
816 *
817 * @{
818 */
819#define LYS_IFF_NOT 0x00 /**< operand "not" */
820#define LYS_IFF_AND 0x01 /**< operand "and" */
821#define LYS_IFF_OR 0x02 /**< operand "or" */
822#define LYS_IFF_F 0x03 /**< feature */
823/**
824 * @}
825 */
826
827/**
828 * @brief Compiled YANG if-feature-stmt
829 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200830struct lysc_iffeature {
Radek Krejci151a5b72018-10-19 14:21:44 +0200831 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
832 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200833};
834
835/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200836 * @brief Compiled YANG data node
837 */
838struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200839 uint16_t nodetype; /**< type of the node (mandatory) */
840 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
841 struct lysp_node *sp; /**< link to the simply parsed (SP) original of the node, NULL if the SP schema was removed. */
842 struct lysc_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
843 const char *name; /**< node name (mandatory) */
844 struct lysc_when *when; /**< when statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200845 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
846 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200847};
848
849/**
850 * @brief Compiled YANG schema tree structure representing YANG module.
851 *
852 * Semantically validated YANG schema tree for data tree parsing.
853 * Contains only the necessary information for the data validation.
854 */
855struct lysc_module {
856 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
857 const char *name; /**< name of the module (mandatory) */
858 const char *ns; /**< namespace of the module (mandatory) */
859 const char *prefix; /**< module prefix (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200860 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200861
862
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200863 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200864
865
866 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
867 uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is
868 the latest revision found */
869 uint8_t version:4; /**< yang-version (LYS_VERSION values) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200870};
871
872/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200873 * @brief Get how the if-feature statement currently evaluates.
874 *
875 * @param[in] iff Compiled if-feature statement to evaluate.
876 * @return If the statement evaluates to true, 1 is returned. 0 is returned when the statement evaluates to false.
877 */
878int lysc_iffeature_value(const struct lysc_iffeature *iff);
879
880/**
881 * @brief Get the current status of the provided feature.
882 *
883 * @param[in] feature Compiled feature statement to examine.
884 * @return
885 * - 1 if feature is enabled,
886 * - 0 if feature is disabled,
887 * - -1 in case of error (invalid argument)
888 */
889int lysc_feature_value(const struct lysc_feature *feature);
890
891/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200892 * @brief Available YANG schema tree structures representing YANG module.
893 */
894struct lys_module {
895 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
896 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing */
897};
898
Radek Krejci151a5b72018-10-19 14:21:44 +0200899/**
900 * @brief Enable specified feature in the module
901 *
902 * By default, when the module is loaded by libyang parser, all features are disabled.
903 *
904 * @param[in] module Module where the feature will be enabled.
905 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
906 * @return LY_ERR value.
907 */
908LY_ERR lys_feature_enable(struct lys_module *module, const char *feature);
909
910/**
911 * @brief Disable specified feature in the module
912 *
913 * By default, when the module is loaded by libyang parser, all features are disabled.
914 *
915 * @param[in] module Module where the feature will be disabled.
916 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
917 * @return LY_ERR value
918 */
919LY_ERR lys_feature_disable(struct lys_module *module, const char *feature);
920
921/**
922 * @brief Get the current status of the specified feature in the module.
923 *
924 * @param[in] module Module where the feature is defined.
925 * @param[in] feature Name of the feature to inspect.
926 * @return
927 * - 1 if feature is enabled,
928 * - 0 if feature is disabled,
929 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
930 */
931int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200932
933/**
Radek Krejci86d106e2018-10-18 09:53:19 +0200934 * @brief Load a schema into the specified context.
935 *
936 * @param[in] ctx libyang context where to process the data model.
937 * @param[in] data The string containing the dumped data model in the specified
938 * format.
939 * @param[in] format Format of the input data (YANG or YIN).
940 * @return Pointer to the data model structure or NULL on error.
941 */
942const struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
943
944/**
945 * @brief Read a schema from file descriptor into the specified context.
946 *
947 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
948 *
949 * @param[in] ctx libyang context where to process the data model.
950 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
951 * in the specified format.
952 * @param[in] format Format of the input data (YANG or YIN).
953 * @return Pointer to the data model structure or NULL on error.
954 */
955const struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
956
957/**
958 * @brief Load a schema into the specified context from a file.
959 *
960 * @param[in] ctx libyang context where to process the data model.
961 * @param[in] path Path to the file with the model in the specified format.
962 * @param[in] format Format of the input data (YANG or YIN).
963 * @return Pointer to the data model structure or NULL on error.
964 */
965const struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
966
967/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200968 * @defgroup scflags Schema compile flags
969 * @ingroup schematree
970 *
971 * @{
972 */
973#define LYSC_OPT_FREE_SP 1 /**< Free the input printable schema */
974
975/**
976 * @}
977 */
978
979/**
980 * @brief Compile printable schema into a validated schema linking all the references.
981 *
982 * @param[in] sp Simple parsed printable schema to compile. Can be changed according to the provided options.
983 * @param[in] options Various options to modify compiler behavior, see [compile flags](@ref scflags).
984 * @param[out] sc Resulting compiled schema structure.
985 * @return LY_ERR value.
986 */
987LY_ERR lys_compile(struct lysp_module *sp, int options, struct lysc_module **sc);
988
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200989/** @} */
990
Radek Krejci70853c52018-10-15 14:46:16 +0200991#ifdef __cplusplus
992}
993#endif
994
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200995#endif /* LY_TREE_SCHEMA_H_ */