blob: ff1d929cf9597299609c7acfe4c1b516187c9b25 [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 {
Radek Krejci086c7132018-10-26 15:29:04 +0200165 struct lys_module *module; /**< pointer to the imported module
166 (mandatory, but resolved when the referring module is completely parsed) */
167 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200168 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200169 const char *dsc; /**< description */
170 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200171 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200172 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
173};
174
175/**
176 * @brief YANG include-stmt
177 */
178struct lysp_include {
Radek Krejci086c7132018-10-26 15:29:04 +0200179 struct lysp_module *submodule; /**< pointer to the parsed submodule structure
180 (mandatory, but resolved when the referring module is completely parsed) */
181 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200182 const char *dsc; /**< description */
183 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200184 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200185 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
186};
187
188/**
189 * @brief YANG extension-stmt
190 */
191struct lysp_ext {
192 const char *name; /**< extension name */
193 const char *argument; /**< argument name, NULL if not specified */
194 const char *dsc; /**< description statement */
195 const char *ref; /**< reference statement */
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 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
198};
199
200/**
201 * @brief Helper structure for generic storage of the extension instances content.
202 */
203struct lysp_stmt {
204 const char *stmt; /**< identifier of the statement */
205 const char *arg; /**< statement's argument */
206 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200207 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200208};
209
210/**
Michal Vaskod92e42a2018-09-07 08:35:02 +0200211 * @brief Enum of substatements in which extension instances can appear.
212 */
213typedef enum {
214 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
215 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
216 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
217 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
218 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
219 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
220 lys_node_choice and lys_deviate */
221 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
222 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
223 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
224 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
225 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
226 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
227 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
228 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
229 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
230 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
231 belongs-to's prefix) and lys_import */
232 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
233 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
234 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
235 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
236 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
237 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
238 lys_node_leaflist and lys_deviate */
239 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
240 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
241 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
242 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
243 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
244 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
245 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
246 lys_node_anydata and lys_deviate */
247 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
248 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
249 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200250 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200251 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
252 lys_node_leaflist and lys_deviate */
253 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
254 lys_node_leaflist and lys_deviate */
255 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
256 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200257 LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200258} LYEXT_SUBSTMT;
259
260/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200261 * @brief YANG extension instance
262 */
263struct lysp_ext_instance {
264 const char *name; /**< extension identifier, including possible prefix */
265 const char *argument; /**< optional value of the extension's argument */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200266 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
267 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
268 the index of that substatement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200269 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200270};
271
272/**
273 * @brief YANG feature-stmt
274 */
275struct lysp_feature {
276 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200277 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200278 const char *dsc; /**< description statement */
279 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200280 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200281 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
282};
283
284/**
285 * @brief YANG identity-stmt
286 */
287struct lysp_ident {
288 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200289 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
290 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200291 const char *dsc; /**< description statement */
292 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200293 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200294 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
295};
296
Michal Vasko71e64ca2018-09-07 16:30:29 +0200297/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200298 * @brief Covers restrictions: range, length, pattern, must
299 */
300struct lysp_restr {
301 const char *arg; /**< The restriction expression/value (mandatory);
302 in case of pattern restriction, the first byte has a special meaning:
303 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
304 const char *emsg; /**< error-message */
305 const char *eapptag; /**< error-app-tag value */
306 const char *dsc; /**< description */
307 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200308 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200309};
310
311/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200312 * @brief YANG revision-stmt
313 */
314struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200315 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200316 const char *dsc; /**< description statement */
317 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200318 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200319};
320
321/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200322 * @brief Enumeration/Bit value definition
323 */
324struct lysp_type_enum {
325 const char *name; /**< name (mandatory) */
326 const char *dsc; /**< description statement */
327 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200328 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200329 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200330 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200331 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
332 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200333};
334
335/**
336 * @brief YANG type-stmt
337 *
338 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
339 */
340struct lysp_type {
341 const char *name; /**< name of the type (mandatory) */
342 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
343 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200344 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
345 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
346 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200347 const char *path; /**< path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200348 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200349 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
350 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200351
352 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
353 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200354 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_SET_REQINST allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200355};
356
357/**
358 * @brief YANG typedef-stmt
359 */
360struct lysp_tpdf {
361 const char *name; /**< name of the newly defined type (mandatory) */
362 const char *units; /**< units of the newly defined type */
363 const char *dflt; /**< default value of the newly defined type */
364 const char *dsc; /**< description statement */
365 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200366 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200367 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
368 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
369};
370
371/**
372 * @brief YANG grouping-stmt
373 */
374struct lysp_grp {
375 const char *name; /**< grouping name (mandatory) */
376 const char *dsc; /**< description statement */
377 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200378 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
379 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200380 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200381 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
382 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
383 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200384 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
385};
386
387/**
388 * @brief YANG when-stmt
389 */
390struct lysp_when {
391 const char *cond; /**< specified condition (mandatory) */
392 const char *dsc; /**< description statement */
393 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200394 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200395};
396
397/**
398 * @brief YANG refine-stmt
399 */
400struct lysp_refine {
401 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
402 const char *dsc; /**< description statement */
403 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200404 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200405 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200406 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200407 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200408 uint32_t min; /**< min-elements constraint */
409 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200410 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200411 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
412};
413
414/**
415 * @brief YANG uses-augment-stmt and augment-stmt
416 */
417struct lysp_augment {
418 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
419 const char *dsc; /**< description statement */
420 const char *ref; /**< reference statement */
421 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200422 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200423 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200424 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
425 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
426 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200427 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
428};
429
430/**
431 * @defgroup deviatetypes Deviate types
432 * @{
433 */
434#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
435#define LYS_DEV_ADD 2 /**< deviate type add */
436#define LYS_DEV_DELETE 3 /**< deviate type delete */
437#define LYS_DEV_REPLACE 4 /**< deviate type replace */
438/** @} */
439
440/**
441 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
442 */
443struct lysp_deviate {
444 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
445 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200446 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200447};
448
449struct lysp_deviate_add {
450 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
451 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200452 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200453 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200454 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200455 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
456 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200457 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
458 uint32_t min; /**< min-elements constraint */
459 uint32_t max; /**< max-elements constraint, 0 means unbounded */
460};
461
462struct lysp_deviate_del {
463 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
464 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200465 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200466 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200467 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200468 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
469 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200470 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200471};
472
473struct lysp_deviate_rpl {
474 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
475 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200476 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200477 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200478 const char *units; /**< units of the values */
479 const char *dflt; /**< default value */
480 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
481 uint32_t min; /**< min-elements constraint */
482 uint32_t max; /**< max-elements constraint, 0 means unbounded */
483};
484
485struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200486 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200487 const char *dsc; /**< description statement */
488 const char *ref; /**< reference statement */
489 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200490 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200491};
492
Michal Vaskob55f6c12018-09-12 11:13:15 +0200493#define LYS_CONFIG_W 0x01 /**< config true; */
494#define LYS_CONFIG_R 0x02 /**< config false; */
495#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
496#define LYS_STATUS_CURR 0x08 /**< status current; */
497#define LYS_STATUS_DEPRC 0x10 /**< status deprecated; */
498#define LYS_STATUS_OBSLT 0x20 /**< status obsolete; */
499#define LYS_STATUS_MASK 0x38 /**< mask for status value */
500#define LYS_MAND_TRUE 0x40 /**< mandatory true; applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200501 ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf
502 and ::lysp_node_anydata/::lysc_node_anydata */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200503#define LYS_MAND_FALSE 0x80 /**< mandatory false; applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200504 ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf
505 and ::lysp_node_anydata/::lysc_node_anydata */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200506#define LYS_MAND_MASK 0xc0 /**< mask for mandatory values */
507#define LYS_ORDBY_SYSTEM 0x100 /**< ordered-by system lists, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200508 ::lysp_node_list/lysc_node_list and ::lysp_node_leaflist/::lysc_node_list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200509#define LYS_ORDBY_USER 0x200 /**< ordered-by user lists, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200510 ::lysp_node_list/lysc_node_list and ::lysp_node_leaflist/::lysc_node_list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200511#define LYS_ORDBY_MASK 0x300 /**< mask for ordered-by flags */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200512#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysp_feature/::lysc_feature */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200513#define LYS_AUTOASSIGNED 0x01 /**< value was auto-assigned, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200514 ::lysp_type/::lysc_type enum and bits flags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200515#define LYS_YINELEM_TRUE 0x01 /**< yin-element true for extension's argument */
516#define LYS_YINELEM_FALSE 0x02 /**< yin-element false for extension's argument */
517#define LYS_YINELEM_MASK 0x03 /**< mask for yin-element value */
518#define LYS_SET_VALUE 0x01 /**< value attribute is set */
519#define LYS_SET_MAX 0x400 /**< max attribute is set */
520#define LYS_SET_MIN 0x800 /**< min attribute is set */
521#define LYS_SET_REQINST 0x01 /**< require_instance attribute is set */
522
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200523/**
524 * @brief Generic YANG data node
525 */
526struct lysp_node {
527 uint16_t nodetype; /**< type of the node (mandatory) */
528 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
529 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
530 const char *name; /**< node name (mandatory) */
531 const char *dsc; /**< description statement */
532 const char *ref; /**< reference statement */
533 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200534 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200535 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200536};
537
538/**
539 * @brief Extension structure of the lysp_node for YANG container
540 */
541struct lysp_node_container {
542 uint16_t nodetype; /**< LYS_CONTAINER */
543 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
544 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
545 const char *name; /**< node name (mandatory) */
546 const char *dsc; /**< description statement */
547 const char *ref; /**< reference statement */
548 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200549 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200550 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200551
552 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200553 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200554 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200555 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
556 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200557 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200558 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
559 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200560};
561
562struct lysp_node_leaf {
563 uint16_t nodetype; /**< LYS_LEAF */
564 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
565 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
566 const char *name; /**< node name (mandatory) */
567 const char *dsc; /**< description statement */
568 const char *ref; /**< reference statement */
569 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200570 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200571 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200572
573 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200574 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200575 struct lysp_type type; /**< type of the leaf node (mandatory) */
576 const char *units; /**< units of the leaf's type */
577 const char *dflt; /**< default value */
578};
579
580struct lysp_node_leaflist {
581 uint16_t nodetype; /**< LYS_LEAFLIST */
582 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
583 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
584 const char *name; /**< node name (mandatory) */
585 const char *dsc; /**< description statement */
586 const char *ref; /**< reference statement */
587 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200588 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200589 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200590
591 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200592 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200593 struct lysp_type type; /**< type of the leaf node (mandatory) */
594 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200595 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200596 uint32_t min; /**< min-elements constraint */
597 uint32_t max; /**< max-elements constraint, 0 means unbounded */
598};
599
600struct lysp_node_list {
601 uint16_t nodetype; /**< LYS_LIST */
602 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
603 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
604 const char *name; /**< node name (mandatory) */
605 const char *dsc; /**< description statement */
606 const char *ref; /**< reference statement */
607 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200608 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200609 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200610
611 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200612 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200613 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200614 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
615 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200616 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200617 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
618 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200619 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200620 uint32_t min; /**< min-elements constraint */
621 uint32_t max; /**< max-elements constraint, 0 means unbounded */
622};
623
624struct lysp_node_choice {
625 uint16_t nodetype; /**< LYS_CHOICE */
626 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
627 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
628 const char *name; /**< node name (mandatory) */
629 const char *dsc; /**< description statement */
630 const char *ref; /**< reference statement */
631 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200632 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200633 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200634
635 /* choice */
636 struct lysp_node *child; /**< list of data nodes (linked list) */
637 const char* dflt; /**< default case */
638};
639
640struct lysp_node_case {
641 uint16_t nodetype; /**< LYS_CASE */
642 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
643 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
644 const char *name; /**< node name (mandatory) */
645 const char *dsc; /**< description statement */
646 const char *ref; /**< reference statement */
647 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200648 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200649 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200650
651 /* case */
652 struct lysp_node *child; /**< list of data nodes (linked list) */
653};
654
655struct lysp_node_anydata {
656 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
657 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
658 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
659 const char *name; /**< node name (mandatory) */
660 const char *dsc; /**< description statement */
661 const char *ref; /**< reference statement */
662 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200663 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200664 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200665
666 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200667 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200668};
669
670struct lysp_node_uses {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200671 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200672 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
673 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
674 const char *name; /**< grouping name reference (mandatory) */
675 const char *dsc; /**< description statement */
676 const char *ref; /**< reference statement */
677 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200678 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200679 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200680
681 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200682 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
683 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200684};
685
686/**
687 * @brief YANG input-stmt and output-stmt
688 */
689struct lysp_action_inout {
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200690 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
691 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
692 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200693 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200694 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200695};
696
697/**
698 * @brief YANG rpc-stmt and action-stmt
699 */
700struct lysp_action {
701 const char *name; /**< grouping name reference (mandatory) */
702 const char *dsc; /**< description statement */
703 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200704 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200705 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
706 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200707 struct lysp_action_inout *input; /**< RPC's/Action's input */
708 struct lysp_action_inout *output;/**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200709 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200710 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
711};
712
713/**
714 * @brief YANG notification-stmt
715 */
716struct lysp_notif {
717 const char *name; /**< grouping name reference (mandatory) */
718 const char *dsc; /**< description statement */
719 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200720 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200721 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
722 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
723 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200724 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200725 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200726 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
727};
728
729/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200730 * @brief supported YANG schema version values
731 */
732typedef enum LYS_VERSION {
733 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
734 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
735 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
736} LYS_VERSION;
737
738/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200739 * @brief Printable YANG schema tree structure representing YANG module.
740 *
741 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
742 */
743struct lysp_module {
744 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
745 const char *name; /**< name of the module (mandatory) */
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100746 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200747 union {
748 /* module */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200749 const char *ns; /**< namespace of the module (module - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200750 /* submodule */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200751 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200752 };
Michal Vaskod5927ca2018-09-07 15:05:32 +0200753 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
Radek Krejcib7db73a2018-10-24 14:18:40 +0200754 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
755 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200756 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
757 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200758 const char *org; /**< party/company responsible for the module */
759 const char *contact; /**< contact information for the module */
760 const char *dsc; /**< description of the module */
761 const char *ref; /**< cross-reference for the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200762 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
763 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
764 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
765 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
766 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200767 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200768 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
769 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
770 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
771 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
772 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200773
Radek Krejcif0fceb62018-09-05 14:58:45 +0200774 uint8_t submodule:1; /**< flag to distinguish main modules and submodules */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200775 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
Radek Krejci086c7132018-10-26 15:29:04 +0200776 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
777 1 - the latest revision in searchdirs was not searched yet and this is the
778 latest revision in the current context
779 2 - searchdirs were searched and this is the latest available revision */
780 uint8_t parsing:1; /**< flag for circular check */
781 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejcid33273d2018-10-25 14:55:52 +0200782 uint16_t refcount; /**< 0 in modules, number of includes of a submodules */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200783};
784
785/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200786 * @brief Free the printable YANG schema tree structure.
787 *
788 * @param[in] module Printable YANG schema tree structure to free.
789 */
790void lysp_module_free(struct lysp_module *module);
791
792/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200793 * @brief YANG import-stmt
794 */
795struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100796 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +0200797 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
798 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
799};
800
801/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200802 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200803 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200804struct lysc_when {
805 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200806 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200807};
808
809/**
810 * @brief YANG feature-stmt
811 */
812struct lysc_feature {
813 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200814 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 +0200815 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
816 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200817 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
818 #LYS_FENABLED values allowed */
819};
820
Radek Krejci151a5b72018-10-19 14:21:44 +0200821/**
822 * @defgroup ifftokens if-feature expression tokens
823 * Tokens of if-feature expression used in ::lysc_iffeature#expr
824 *
825 * @{
826 */
827#define LYS_IFF_NOT 0x00 /**< operand "not" */
828#define LYS_IFF_AND 0x01 /**< operand "and" */
829#define LYS_IFF_OR 0x02 /**< operand "or" */
830#define LYS_IFF_F 0x03 /**< feature */
831/**
832 * @}
833 */
834
835/**
Radek Krejcib7db73a2018-10-24 14:18:40 +0200836 * @brief Compiled YANG revision statement
837 */
838struct lysc_revision {
839 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
840 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
841};
842
843/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200844 * @brief Compiled YANG if-feature-stmt
845 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200846struct lysc_iffeature {
Radek Krejci151a5b72018-10-19 14:21:44 +0200847 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
848 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200849};
850
851/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200852 * @brief Compiled YANG data node
853 */
854struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200855 uint16_t nodetype; /**< type of the node (mandatory) */
856 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
857 struct lysp_node *sp; /**< link to the simply parsed (SP) original of the node, NULL if the SP schema was removed. */
858 struct lysc_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
859 const char *name; /**< node name (mandatory) */
860 struct lysc_when *when; /**< when statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200861 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
862 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200863};
864
865/**
866 * @brief Compiled YANG schema tree structure representing YANG module.
867 *
868 * Semantically validated YANG schema tree for data tree parsing.
869 * Contains only the necessary information for the data validation.
870 */
871struct lysc_module {
872 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
873 const char *name; /**< name of the module (mandatory) */
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100874 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200875 const char *ns; /**< namespace of the module (mandatory) */
876 const char *prefix; /**< module prefix (mandatory) */
Radek Krejcib7db73a2018-10-24 14:18:40 +0200877 struct lysc_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
878 in the list is always the last (newest) revision of the module */
Radek Krejci151a5b72018-10-19 14:21:44 +0200879 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200880
881
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200882 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200883
884
885 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
886 uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is
887 the latest revision found */
Radek Krejci086c7132018-10-26 15:29:04 +0200888 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200889};
890
891/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200892 * @brief Get how the if-feature statement currently evaluates.
893 *
894 * @param[in] iff Compiled if-feature statement to evaluate.
895 * @return If the statement evaluates to true, 1 is returned. 0 is returned when the statement evaluates to false.
896 */
897int lysc_iffeature_value(const struct lysc_iffeature *iff);
898
899/**
900 * @brief Get the current status of the provided feature.
901 *
902 * @param[in] feature Compiled feature statement to examine.
903 * @return
904 * - 1 if feature is enabled,
905 * - 0 if feature is disabled,
906 * - -1 in case of error (invalid argument)
907 */
908int lysc_feature_value(const struct lysc_feature *feature);
909
910/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200911 * @brief Available YANG schema tree structures representing YANG module.
912 */
913struct lys_module {
914 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
915 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing */
916};
917
Radek Krejci151a5b72018-10-19 14:21:44 +0200918/**
919 * @brief Enable specified feature in the module
920 *
921 * By default, when the module is loaded by libyang parser, all features are disabled.
922 *
923 * @param[in] module Module where the feature will be enabled.
924 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
925 * @return LY_ERR value.
926 */
927LY_ERR lys_feature_enable(struct lys_module *module, const char *feature);
928
929/**
930 * @brief Disable specified feature in the module
931 *
932 * By default, when the module is loaded by libyang parser, all features are disabled.
933 *
934 * @param[in] module Module where the feature will be disabled.
935 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
936 * @return LY_ERR value
937 */
938LY_ERR lys_feature_disable(struct lys_module *module, const char *feature);
939
940/**
941 * @brief Get the current status of the specified feature in the module.
942 *
943 * @param[in] module Module where the feature is defined.
944 * @param[in] feature Name of the feature to inspect.
945 * @return
946 * - 1 if feature is enabled,
947 * - 0 if feature is disabled,
948 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
949 */
950int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200951
952/**
Radek Krejci86d106e2018-10-18 09:53:19 +0200953 * @brief Load a schema into the specified context.
954 *
955 * @param[in] ctx libyang context where to process the data model.
956 * @param[in] data The string containing the dumped data model in the specified
957 * format.
958 * @param[in] format Format of the input data (YANG or YIN).
959 * @return Pointer to the data model structure or NULL on error.
960 */
961const struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
962
963/**
964 * @brief Read a schema from file descriptor into the specified context.
965 *
966 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
967 *
968 * @param[in] ctx libyang context where to process the data model.
969 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
970 * in the specified format.
971 * @param[in] format Format of the input data (YANG or YIN).
972 * @return Pointer to the data model structure or NULL on error.
973 */
974const struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
975
976/**
Radek Krejcid33273d2018-10-25 14:55:52 +0200977 * @brief Read a schema into the specified context from a file.
Radek Krejci86d106e2018-10-18 09:53:19 +0200978 *
979 * @param[in] ctx libyang context where to process the data model.
980 * @param[in] path Path to the file with the model in the specified format.
981 * @param[in] format Format of the input data (YANG or YIN).
982 * @return Pointer to the data model structure or NULL on error.
983 */
984const struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
985
986/**
Radek Krejcid33273d2018-10-25 14:55:52 +0200987 * @brief Search for the schema file in the specified searchpaths.
988 *
989 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
990 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
991 * result of the ly_ctx_get_searchdirs().
992 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
993 * @param[in] name Name of the schema to find.
994 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
995 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
996 * complying the provided restriction is found, NULL is set.
997 * @param[out] format Optional output variable containing expected format of the schema document according to the
998 * file suffix.
999 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
1000 */
1001LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
1002
1003/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001004 * @defgroup scflags Schema compile flags
1005 * @ingroup schematree
1006 *
1007 * @{
1008 */
1009#define LYSC_OPT_FREE_SP 1 /**< Free the input printable schema */
1010
1011/**
1012 * @}
1013 */
1014
1015/**
1016 * @brief Compile printable schema into a validated schema linking all the references.
1017 *
1018 * @param[in] sp Simple parsed printable schema to compile. Can be changed according to the provided options.
1019 * @param[in] options Various options to modify compiler behavior, see [compile flags](@ref scflags).
1020 * @param[out] sc Resulting compiled schema structure.
1021 * @return LY_ERR value.
1022 */
1023LY_ERR lys_compile(struct lysp_module *sp, int options, struct lysc_module **sc);
1024
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001025/** @} */
1026
Radek Krejci70853c52018-10-15 14:46:16 +02001027#ifdef __cplusplus
1028}
1029#endif
1030
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001031#endif /* LY_TREE_SCHEMA_H_ */