blob: a307e2dc55a16a8cc24e24371ffbb08a3da07d83 [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
Radek Krejci54579462019-04-30 12:47:06 +020018#define PCRE2_CODE_UNIT_WIDTH 8
19
20#include <pcre2.h>
Radek Krejci535ea9f2020-05-29 16:01:05 +020021
Radek Krejci5aeea3a2018-09-05 13:29:36 +020022#include <stdint.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020023#include <stdio.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020024
Radek Krejcie7b95092019-05-15 11:03:07 +020025#include "log.h"
26#include "tree.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020027#include "tree_data.h"
Radek Krejcice8c1592018-10-29 15:35:51 +010028
Radek Krejcie7b95092019-05-15 11:03:07 +020029struct ly_ctx;
Michal Vasko004d3152020-06-11 19:59:22 +020030struct ly_path;
Radek Krejci535ea9f2020-05-29 16:01:05 +020031struct ly_set;
Radek Krejcie7b95092019-05-15 11:03:07 +020032
Radek Krejci70853c52018-10-15 14:46:16 +020033#ifdef __cplusplus
34extern "C" {
35#endif
36
Radek Krejci5aeea3a2018-09-05 13:29:36 +020037/**
Radek Krejci2ff0d572020-05-21 15:27:28 +020038 * @defgroup schematree Schema Tree
39 * @ingroup trees
40 * @{
41 *
42 * Data structures and functions to manipulate and access schema tree.
43 */
44
45/**
Radek Krejci0935f412019-08-20 16:15:18 +020046 * @brief Macro to iterate via all elements in a schema tree which can be instantiated in data tree
Radek Krejciad5963b2019-09-06 16:03:05 +020047 * (skips cases, input, output). This is the opening part to the #LYSC_TREE_DFS_END - they always have to be used together.
Radek Krejci0935f412019-08-20 16:15:18 +020048 *
49 * The function follows deep-first search algorithm:
50 * <pre>
51 * 1
52 * / \
53 * 2 4
54 * / / \
55 * 3 5 6
56 * </pre>
57 *
58 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
59 * START can be any of the lysc_node* types (including lysc_action and lysc_notif),
60 * ELEM variable must be of the struct lysc_node* type.
61 *
62 * To skip a particular subtree, instead of the continue statement, set LYSC_TREE_DFS_continue
63 * variable to non-zero value.
64 *
65 * Use with opening curly bracket '{' after the macro.
66 *
67 * @param START Pointer to the starting element processed first.
68 * @param ELEM Iterator intended for use in the block.
69 */
70#define LYSC_TREE_DFS_BEGIN(START, ELEM) \
71 { int LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
72 for ((ELEM) = (LYSC_TREE_DFS_next) = (START); \
73 (ELEM); \
74 (ELEM) = (LYSC_TREE_DFS_next), LYSC_TREE_DFS_continue = 0)
75
76/**
77 * @brief Macro to iterate via all elements in a (sub)tree. This is the closing part
78 * to the #LYSC_TREE_DFS_BEGIN - they always have to be used together.
79 *
80 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
81 * START can be a pointer to any of the lysc_node* types (including lysc_action and lysc_notif),
82 * ELEM variable must be pointer to the lysc_node type.
83 *
84 * Use with closing curly bracket '}' after the macro.
85 *
86 * @param START Pointer to the starting element processed first.
87 * @param ELEM Iterator intended for use in the block.
88 */
89
90#define LYSC_TREE_DFS_END(START, ELEM) \
91 /* select element for the next run - children first */ \
92 if (LYSC_TREE_DFS_continue) { \
93 (LYSC_TREE_DFS_next) = NULL; \
94 } else { \
95 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, 0); \
96 }\
97 if (!(LYSC_TREE_DFS_next)) { \
98 /* in case of RPC/action, get also the output children */ \
Michal Vasko1bf09392020-03-27 12:38:10 +010099 if (!LYSC_TREE_DFS_continue && (ELEM)->nodetype & (LYS_RPC | LYS_ACTION)) { \
Radek Krejci0935f412019-08-20 16:15:18 +0200100 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, LYS_CONFIG_R); \
101 } \
102 if (!(LYSC_TREE_DFS_next)) { \
103 /* no children */ \
104 if ((ELEM) == (struct lysc_node*)(START)) { \
105 /* we are done, (START) has no children */ \
106 break; \
107 } \
108 /* try siblings */ \
109 (LYSC_TREE_DFS_next) = (ELEM)->next; \
110 } \
111 } \
112 while (!(LYSC_TREE_DFS_next)) { \
113 /* parent is already processed, go to its sibling */ \
114 (ELEM) = (ELEM)->parent; \
115 /* no siblings, go back through parents */ \
116 if ((ELEM) == (struct lysc_node*)(START)) { \
117 /* we are done, no next element to process */ \
118 break; \
119 } \
Michal Vasko1bf09392020-03-27 12:38:10 +0100120 if ((ELEM)->nodetype & (LYS_RPC | LYS_ACTION)) { \
Radek Krejci0935f412019-08-20 16:15:18 +0200121 /* there is actually next node as a child of action's output */ \
122 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, LYS_CONFIG_R); \
123 } \
124 if (!(LYSC_TREE_DFS_next)) { \
125 (LYSC_TREE_DFS_next) = (ELEM)->next; \
126 } \
127 } } \
128
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200129#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
130
Michal Vaskob55f6c12018-09-12 11:13:15 +0200131#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
132#define LYS_CONTAINER 0x0001 /**< container statement node */
133#define LYS_CHOICE 0x0002 /**< choice statement node */
134#define LYS_LEAF 0x0004 /**< leaf statement node */
135#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
136#define LYS_LIST 0x0010 /**< list statement node */
137#define LYS_ANYXML 0x0020 /**< anyxml statement node */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200138#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 +0200139
Michal Vasko1bf09392020-03-27 12:38:10 +0100140#define LYS_RPC 0x400 /**< RPC statement node */
141#define LYS_ACTION 0x800 /**< action statement node */
142#define LYS_NOTIF 0x1000 /**< notification statement node */
Radek Krejcie7b95092019-05-15 11:03:07 +0200143
Radek Krejcia3045382018-11-22 14:30:31 +0100144#define LYS_CASE 0x0040 /**< case statement node */
145#define LYS_USES 0x0080 /**< uses statement node */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200146#define LYS_INPUT 0x100
147#define LYS_OUTPUT 0x200
148#define LYS_INOUT 0x300
Michal Vasko1bf09392020-03-27 12:38:10 +0100149#define LYS_GROUPING 0x2000
150#define LYS_AUGMENT 0x4000
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100151
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200152/**
Radek Krejcid6b76452019-09-03 17:03:03 +0200153 * @brief List of YANG statements
154 */
155enum ly_stmt {
156 LY_STMT_NONE = 0,
Radek Krejciad5963b2019-09-06 16:03:05 +0200157 LY_STMT_STATUS, /**< in lysc_ext_substmt::storage stored as a pointer to `uint16_t`, only cardinality < #LY_STMT_CARD_SOME is allowed */
158 LY_STMT_CONFIG, /**< in lysc_ext_substmt::storage stored as a pointer to `uint16_t`, only cardinality < #LY_STMT_CARD_SOME is allowed */
Radek Krejci335332a2019-09-05 13:03:35 +0200159 LY_STMT_MANDATORY,
Radek Krejciad5963b2019-09-06 16:03:05 +0200160 LY_STMT_UNITS, /**< in lysc_ext_substmt::storage stored as a pointer to `const char *` (cardinality < #LY_STMT_CARD_SOME)
161 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200162 LY_STMT_DEFAULT,
Radek Krejciad5963b2019-09-06 16:03:05 +0200163 LY_STMT_TYPE, /**< in lysc_ext_substmt::storage stored as a pointer to `struct lysc_type *` (cardinality < #LY_STMT_CARD_SOME)
164 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_type **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200165
Radek Krejcid6b76452019-09-03 17:03:03 +0200166 LY_STMT_ACTION,
167 LY_STMT_ANYDATA,
168 LY_STMT_ANYXML,
169 LY_STMT_ARGUMENT,
170 LY_STMT_AUGMENT,
171 LY_STMT_BASE,
172 LY_STMT_BELONGS_TO,
173 LY_STMT_BIT,
174 LY_STMT_CASE,
175 LY_STMT_CHOICE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200176 LY_STMT_CONTACT,
177 LY_STMT_CONTAINER,
Radek Krejcid6b76452019-09-03 17:03:03 +0200178 LY_STMT_DESCRIPTION,
179 LY_STMT_DEVIATE,
180 LY_STMT_DEVIATION,
181 LY_STMT_ENUM,
182 LY_STMT_ERROR_APP_TAG,
183 LY_STMT_ERROR_MESSAGE,
184 LY_STMT_EXTENSION,
185 LY_STMT_FEATURE,
186 LY_STMT_FRACTION_DIGITS,
187 LY_STMT_GROUPING,
188 LY_STMT_IDENTITY,
Radek Krejciad5963b2019-09-06 16:03:05 +0200189 LY_STMT_IF_FEATURE, /**< in lysc_ext_substmt::storage stored as a pointer to `struct lysc_iffeature` (cardinality < #LY_STMT_CARD_SOME)
190 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_iffeature *` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200191 LY_STMT_IMPORT,
192 LY_STMT_INCLUDE,
193 LY_STMT_INPUT,
194 LY_STMT_KEY,
195 LY_STMT_LEAF,
196 LY_STMT_LEAF_LIST,
197 LY_STMT_LENGTH,
198 LY_STMT_LIST,
Radek Krejcid6b76452019-09-03 17:03:03 +0200199 LY_STMT_MAX_ELEMENTS,
200 LY_STMT_MIN_ELEMENTS,
201 LY_STMT_MODIFIER,
202 LY_STMT_MODULE,
203 LY_STMT_MUST,
204 LY_STMT_NAMESPACE,
205 LY_STMT_NOTIFICATION,
206 LY_STMT_ORDERED_BY,
207 LY_STMT_ORGANIZATION,
208 LY_STMT_OUTPUT,
209 LY_STMT_PATH,
210 LY_STMT_PATTERN,
211 LY_STMT_POSITION,
212 LY_STMT_PREFIX,
213 LY_STMT_PRESENCE,
214 LY_STMT_RANGE,
215 LY_STMT_REFERENCE,
216 LY_STMT_REFINE,
217 LY_STMT_REQUIRE_INSTANCE,
218 LY_STMT_REVISION,
219 LY_STMT_REVISION_DATE,
220 LY_STMT_RPC,
Radek Krejcid6b76452019-09-03 17:03:03 +0200221 LY_STMT_SUBMODULE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200222 LY_STMT_TYPEDEF,
223 LY_STMT_UNIQUE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200224 LY_STMT_USES,
225 LY_STMT_VALUE,
226 LY_STMT_WHEN,
227 LY_STMT_YANG_VERSION,
228 LY_STMT_YIN_ELEMENT,
229 LY_STMT_EXTENSION_INSTANCE,
230
231 LY_STMT_SYNTAX_SEMICOLON,
232 LY_STMT_SYNTAX_LEFT_BRACE,
233 LY_STMT_SYNTAX_RIGHT_BRACE,
234
235 LY_STMT_ARG_TEXT,
236 LY_STMT_ARG_VALUE
237};
238
239/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200240 * @brief Extension instance structure parent enumeration
241 */
242typedef enum {
Radek Krejci0935f412019-08-20 16:15:18 +0200243 LYEXT_PAR_MODULE, /**< ::lysc_module */
244 LYEXT_PAR_NODE, /**< ::lysc_node (and the derived structures including ::lysc_action and ::lysc_notif) */
245 LYEXT_PAR_INPUT, /**< ::lysc_action_inout */
246 LYEXT_PAR_OUTPUT, /**< ::lysc_action_inout */
247 LYEXT_PAR_TYPE, /**< ::lysc_type */
248 LYEXT_PAR_TYPE_BIT, /**< ::lysc_type_bitenum_item */
249 LYEXT_PAR_TYPE_ENUM, /**< ::lysc_type_bitenum_item */
250 LYEXT_PAR_FEATURE, /**< ::lysc_feature */
251 LYEXT_PAR_MUST, /**< ::lysc_must */
252 LYEXT_PAR_PATTERN, /**< ::lysc_pattern */
253 LYEXT_PAR_LENGTH, /**< ::lysc_range */
254 LYEXT_PAR_RANGE, /**< ::lysc_range */
255 LYEXT_PAR_WHEN, /**< ::lysc_when */
256 LYEXT_PAR_IDENT, /**< ::lysc_ident */
257 LYEXT_PAR_EXT, /**< ::lysc_ext */
258 LYEXT_PAR_IMPORT, /**< ::lysc_import */
259// LYEXT_PAR_TPDF, /**< ::lysp_tpdf */
260// LYEXT_PAR_EXTINST, /**< ::lysp_ext_instance */
261// LYEXT_PAR_REFINE, /**< ::lysp_refine */
262// LYEXT_PAR_DEVIATION, /**< ::lysp_deviation */
263// LYEXT_PAR_DEVIATE, /**< ::lysp_deviate */
264// LYEXT_PAR_INCLUDE, /**< ::lysp_include */
265// LYEXT_PAR_REVISION, /**< ::lysp_revision */
Radek Krejci0e59c312019-08-15 15:34:15 +0200266} LYEXT_PARENT;
267
268/**
Radek Krejci0935f412019-08-20 16:15:18 +0200269 * @brief Stringify extension instance parent type.
270 * @param[in] type Parent type to stringify.
271 * @return Constant string with the name of the parent statement.
272 */
273const char *lyext_parent2str(LYEXT_PARENT type);
274
275/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200276 * @brief Enum of substatements in which extension instances can appear.
277 */
278typedef enum {
279 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
280 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
281 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
282 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
283 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
284 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
285 lys_node_choice and lys_deviate */
286 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
287 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
288 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
289 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
290 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
291 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
292 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
293 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
294 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
295 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
296 belongs-to's prefix) and lys_import */
297 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
298 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
299 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
300 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
301 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
302 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
303 lys_node_leaflist and lys_deviate */
304 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
305 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
306 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
307 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
308 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
309 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
310 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
311 lys_node_anydata and lys_deviate */
312 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
313 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
314 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
315 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
316 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
317 lys_node_leaflist and lys_deviate */
318 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
319 lys_node_leaflist and lys_deviate */
320 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
321 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
322 LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */
323} LYEXT_SUBSTMT;
324
325/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200326 * @brief YANG import-stmt
327 */
328struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200329 struct lys_module *module; /**< pointer to the imported module
330 (mandatory, but resolved when the referring module is completely parsed) */
331 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200332 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200333 const char *dsc; /**< description */
334 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200335 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200336 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
337};
338
339/**
340 * @brief YANG include-stmt
341 */
342struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100343 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200344 (mandatory, but resolved when the referring module is completely parsed) */
345 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200346 const char *dsc; /**< description */
347 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200348 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200349 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
350};
351
352/**
353 * @brief YANG extension-stmt
354 */
355struct lysp_ext {
356 const char *name; /**< extension name */
357 const char *argument; /**< argument name, NULL if not specified */
358 const char *dsc; /**< description statement */
359 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200360 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200361 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */
Michal Vasko5fe75f12020-03-02 13:52:37 +0100362
363 struct lysc_ext *compiled; /**< pointer to the compiled extension definition */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200364};
365
366/**
367 * @brief Helper structure for generic storage of the extension instances content.
368 */
369struct lysp_stmt {
370 const char *stmt; /**< identifier of the statement */
371 const char *arg; /**< statement's argument */
372 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200373 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
David Sedlákb9d75c42019-08-14 10:49:42 +0200374 uint16_t flags; /**< statement flags, can be set to LYS_YIN_ATTR */
Radek Krejci335332a2019-09-05 13:03:35 +0200375 enum ly_stmt kw; /**< numeric respresentation of the stmt value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200376};
377
David Sedlákae4b4512019-08-14 10:45:56 +0200378#define LYS_YIN 0x1 /**< used to specify input format of extension instance */
379
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200380/**
381 * @brief YANG extension instance
382 */
383struct lysp_ext_instance {
David Sedlákbbd06ca2019-06-27 14:15:38 +0200384 const char *name; /**< extension identifier, including possible prefix */
385 const char *argument; /**< optional value of the extension's argument */
Radek Krejci335332a2019-09-05 13:03:35 +0200386 void *parent; /**< pointer to the parent element holding the extension instance(s), use
387 ::lysp_ext_instance#parent_type to access the schema element */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200388 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200389 struct lysc_ext_instance *compiled; /**< pointer to the compiled data if any - in case the source format is YIN,
390 some of the information (argument) are available only after compilation */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200391 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200392 LY_ARRAY_SIZE_TYPE insubstmt_index; /**< in case the instance is in a substatement, this identifies
David Sedlákbbd06ca2019-06-27 14:15:38 +0200393 the index of that substatement */
David Sedlákae4b4512019-08-14 10:45:56 +0200394 uint8_t yin; /** flag for YIN source format, can be set to LYS_YIN */
Radek Krejci335332a2019-09-05 13:03:35 +0200395 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200396};
397
398/**
399 * @brief YANG feature-stmt
400 */
401struct lysp_feature {
402 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200403 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200404 const char *dsc; /**< description statement */
405 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200406 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200407 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
408};
409
410/**
411 * @brief YANG identity-stmt
412 */
413struct lysp_ident {
414 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200415 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
416 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200417 const char *dsc; /**< description statement */
418 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200419 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200420 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
421};
422
Michal Vasko71e64ca2018-09-07 16:30:29 +0200423/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200424 * @brief Covers restrictions: range, length, pattern, must
425 */
426struct lysp_restr {
427 const char *arg; /**< The restriction expression/value (mandatory);
428 in case of pattern restriction, the first byte has a special meaning:
429 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
430 const char *emsg; /**< error-message */
431 const char *eapptag; /**< error-app-tag value */
432 const char *dsc; /**< description */
433 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200434 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200435};
436
437/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200438 * @brief YANG revision-stmt
439 */
440struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200441 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200442 const char *dsc; /**< description statement */
443 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200444 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200445};
446
447/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200448 * @brief Enumeration/Bit value definition
449 */
450struct lysp_type_enum {
451 const char *name; /**< name (mandatory) */
452 const char *dsc; /**< description statement */
453 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200454 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200455 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200456 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200457 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
458 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200459};
460
461/**
462 * @brief YANG type-stmt
463 *
464 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
465 */
466struct lysp_type {
467 const char *name; /**< name of the type (mandatory) */
468 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
469 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200470 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
471 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
472 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Michal Vasko004d3152020-06-11 19:59:22 +0200473 struct lyxp_expr *path; /**< parsed path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200474 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200475 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
476 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200477
Radek Krejci2167ee12018-11-02 16:09:07 +0100478 struct lysc_type *compiled; /**< pointer to the compiled type */
479
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200480 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
481 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100482 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200483};
484
485/**
486 * @brief YANG typedef-stmt
487 */
488struct lysp_tpdf {
489 const char *name; /**< name of the newly defined type (mandatory) */
490 const char *units; /**< units of the newly defined type */
491 const char *dflt; /**< default value of the newly defined type */
492 const char *dsc; /**< description statement */
493 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200494 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200495 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100496 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200497};
498
499/**
500 * @brief YANG grouping-stmt
501 */
502struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100503 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
504 uint16_t nodetype; /**< LYS_GROUPING */
505 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200506 const char *name; /**< grouping name (mandatory) */
507 const char *dsc; /**< description statement */
508 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200509 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
510 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200511 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200512 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
513 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
514 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200515};
516
517/**
518 * @brief YANG when-stmt
519 */
520struct lysp_when {
521 const char *cond; /**< specified condition (mandatory) */
522 const char *dsc; /**< description statement */
523 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200524 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200525};
526
527/**
528 * @brief YANG refine-stmt
529 */
530struct lysp_refine {
531 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
532 const char *dsc; /**< description statement */
533 const char *ref; /**< reference 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_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200536 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200537 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200538 uint32_t min; /**< min-elements constraint */
539 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200540 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200541 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
542};
543
544/**
Michal Vasko82a83432019-11-14 12:33:04 +0100545 * @brief YANG uses-augment-stmt and augment-stmt (compatible with struct lysp_node )
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200546 */
547struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100548 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
549 uint16_t nodetype; /**< LYS_AUGMENT */
550 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Michal Vasko82a83432019-11-14 12:33:04 +0100551 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200552 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
553 const char *dsc; /**< description statement */
554 const char *ref; /**< reference statement */
555 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200556 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Michal Vasko82a83432019-11-14 12:33:04 +0100557 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
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
562/**
563 * @defgroup deviatetypes Deviate types
564 * @{
565 */
566#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
567#define LYS_DEV_ADD 2 /**< deviate type add */
568#define LYS_DEV_DELETE 3 /**< deviate type delete */
569#define LYS_DEV_REPLACE 4 /**< deviate type replace */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200570/** @} deviatetypes */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200571
572/**
573 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
574 */
575struct lysp_deviate {
576 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
577 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200578 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200579};
580
581struct lysp_deviate_add {
582 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
583 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200584 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200585 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200586 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200587 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
588 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200589 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
590 uint32_t min; /**< min-elements constraint */
591 uint32_t max; /**< max-elements constraint, 0 means unbounded */
592};
593
594struct lysp_deviate_del {
595 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
596 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200597 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200598 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200599 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200600 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
601 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200602};
603
604struct lysp_deviate_rpl {
605 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
606 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200607 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200608 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200609 const char *units; /**< units of the values */
610 const char *dflt; /**< default value */
611 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
612 uint32_t min; /**< min-elements constraint */
613 uint32_t max; /**< max-elements constraint, 0 means unbounded */
614};
615
616struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200617 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200618 const char *dsc; /**< description statement */
619 const char *ref; /**< reference statement */
620 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200621 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200622};
623
Radek Krejci4f28eda2018-11-12 11:46:16 +0100624/**
625 * @defgroup spnodeflags Parsed schema nodes flags
626 * @ingroup snodeflags
627 *
628 * Various flags for parsed schema nodes.
629 *
630 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
631 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200632 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100633 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
634 * 5 - list 10 - input 15 - typedef 20 - deviate
635 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200636 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
637 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
638 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
639 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
640 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
641 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
642 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
643 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
644 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
645 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
646 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
647 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
648 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
649 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
650 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
651 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
652 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
653 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
654 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
655 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
656 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
657 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
658 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
659 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
660 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
661 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
662 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
663 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
664 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
665 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
666 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
667 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
668 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
669 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
670 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
671 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
672 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
673 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
674 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200675 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
David Sedlákae4b4512019-08-14 10:45:56 +0200676 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejcid3ca0632019-04-16 16:54:54 +0200677 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejcif56e2a42019-09-09 14:15:25 +0200678 * 12 LYS_YIN_ARGUMENT | | | | | | | | | | | | | | | | | | | | | | |x|
679 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100680 *
681 */
682
683/**
684 * @defgroup scnodeflags Compiled schema nodes flags
685 * @ingroup snodeflags
686 *
687 * Various flags for compiled schema nodes.
688 *
Radek Krejci61e042e2019-09-10 15:53:09 +0200689 * 1 - container 6 - anydata/anyxml 11 - identity
690 * 2 - choice 7 - case 12 - extension
691 * 3 - leaf 8 - notification 13 - bitenum
Michal Vasko03ff5a72019-09-11 13:49:33 +0200692 * 4 - leaflist 9 - rpc/action 14 - when
Michal Vaskoecd62de2019-11-13 12:35:11 +0100693 * 5 - list 10 - feature
Radek Krejci4f28eda2018-11-12 11:46:16 +0100694 *
Michal Vaskoecd62de2019-11-13 12:35:11 +0100695 * 1 1 1 1 1
696 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
697 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
698 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | |
699 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
700 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | |
701 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
702 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x|x|x|x| |x|
703 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
704 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x|x|x|x| |x|
705 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
706 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x|x|x|x| |x|
707 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
708 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
709 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
710 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
711 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | |
712 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
713 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
714 * LYS_PRESENCE |x| | | | | | | | | | | | | |
715 * LYS_UNIQUE | | |x| | | | | | | | | | | |
716 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
717 * 9 LYS_KEY | | |x| | | | | | | | | | | |
718 * LYS_FENABLED | | | | | | | | | |x| | | | |
719 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
720 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
721 * LYS_ISENUM | | | | | | | | | | | | |x| |
722 * LYS_KEYLESS | | | | |x| | | | | | | | | |
723 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
724 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
725 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
726 * 12 LYS_SET_CONFIG |x|x|x|x|x|x| | | | | | | | |
727 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100728 *
729 */
730
731/**
732 * @defgroup snodeflags Schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100733 * @{
734 */
Michal Vasko1bf09392020-03-27 12:38:10 +0100735#define LYS_CONFIG_W 0x01 /**< config true; also set for input children nodes */
736#define LYS_CONFIG_R 0x02 /**< config false; also set for output and notification children nodes */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200737#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100738#define LYS_STATUS_CURR 0x04 /**< status current; */
739#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
740#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
741#define LYS_STATUS_MASK 0x1C /**< mask for status value */
742#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100743 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
744 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
745 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
746 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100747#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
748 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
749 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100750#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100751#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, applicable only to ::lysc_node_container */
752#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
753#define LYS_KEY 0x100 /**< flag for leafs being a key of a list, applicable only to ::lysc_node_leaf */
Radek Krejci0fe9b512019-07-26 17:51:05 +0200754#define LYS_KEYLESS 0x200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100755#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysc_feature */
Radek Krejcife909632019-02-12 15:34:42 +0100756#define LYS_ORDBY_SYSTEM 0x80 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
Radek Krejci4f28eda2018-11-12 11:46:16 +0100757 ::lysc_node_list/::lysp_node_list */
758#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
759 ::lysc_node_list/::lysp_node_list */
760#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
761#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
762#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
763#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200764#define LYS_USED_GRP 0x400 /**< internal flag for validating not-instantiated groupings
765 (resp. do not validate again the instantiated groupings). */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100766#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100767#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200768#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100769
770#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
771#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
772#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
773#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
774#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
775#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
776#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
777#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
778#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
779#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100780#define LYS_SET_DFLT 0x0200 /**< flag to mark leaf/leaflist with own (or refined) default value, not a default value taken from its type, and default
Radek Krejci76b3e962018-12-14 17:01:25 +0100781 cases of choice. This information is important for refines, since it is prohibited to make leafs
782 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100783 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
784 between own default or the default values taken from the type. */
785#define LYS_SET_UNITS 0x0400 /**< flag to know if the leaf's/leaflist's units are their own (flag set) or it is taken from the type. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100786#define LYS_SET_CONFIG 0x0800 /**< flag to know if the config property was set explicitly (flag set) or it is inherited. */
Radek Krejci0e5d8382018-11-28 16:37:53 +0100787
Radek Krejcif56e2a42019-09-09 14:15:25 +0200788#define LYS_SINGLEQUOTED 0x100 /**< flag for single-quoted argument of an extension instance's substatement, only when the source is YANG */
789#define LYS_DOUBLEQUOTED 0x200 /**< flag for double-quoted argument of an extension instance's substatement, only when the source is YANG */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200790
Radek Krejcif56e2a42019-09-09 14:15:25 +0200791#define LYS_YIN_ATTR 0x400 /**< flag to identify YIN attribute parsed as extension's substatement, only when the source is YIN */
792#define LYS_YIN_ARGUMENT 0x800 /**< flag to identify statement representing extension's argument, only when the source is YIN */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200793
Radek Krejci693262f2019-04-29 15:23:20 +0200794#define LYS_ISENUM 0x200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
795
Radek Krejcife909632019-02-12 15:34:42 +0100796#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200797/** @} snodeflags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200798
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200799/**
800 * @brief Generic YANG data node
801 */
802struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100803 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200804 uint16_t nodetype; /**< type of the node (mandatory) */
805 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100806 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200807 const char *name; /**< node name (mandatory) */
808 const char *dsc; /**< description statement */
809 const char *ref; /**< reference statement */
810 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200811 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200812 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200813};
814
815/**
816 * @brief Extension structure of the lysp_node for YANG container
817 */
818struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100819 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200820 uint16_t nodetype; /**< LYS_CONTAINER */
821 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
822 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
823 const char *name; /**< node name (mandatory) */
824 const char *dsc; /**< description statement */
825 const char *ref; /**< reference statement */
826 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200827 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200828 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200829
830 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200831 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200832 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200833 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
834 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200835 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200836 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
837 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200838};
839
840struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100841 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200842 uint16_t nodetype; /**< LYS_LEAF */
843 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
844 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
845 const char *name; /**< node name (mandatory) */
846 const char *dsc; /**< description statement */
847 const char *ref; /**< reference statement */
848 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200849 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200850 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200851
852 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200853 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200854 struct lysp_type type; /**< type of the leaf node (mandatory) */
855 const char *units; /**< units of the leaf's type */
856 const char *dflt; /**< default value */
857};
858
859struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100860 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200861 uint16_t nodetype; /**< LYS_LEAFLIST */
862 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
863 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
864 const char *name; /**< node name (mandatory) */
865 const char *dsc; /**< description statement */
866 const char *ref; /**< reference statement */
867 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200868 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200869 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200870
871 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200872 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200873 struct lysp_type type; /**< type of the leaf node (mandatory) */
874 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200875 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200876 uint32_t min; /**< min-elements constraint */
877 uint32_t max; /**< max-elements constraint, 0 means unbounded */
878};
879
880struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100881 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200882 uint16_t nodetype; /**< LYS_LIST */
883 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
884 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
885 const char *name; /**< node name (mandatory) */
886 const char *dsc; /**< description statement */
887 const char *ref; /**< reference statement */
888 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200889 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200890 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200891
892 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200893 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200894 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200895 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
896 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200897 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200898 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
899 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200900 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200901 uint32_t min; /**< min-elements constraint */
902 uint32_t max; /**< max-elements constraint, 0 means unbounded */
903};
904
905struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100906 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200907 uint16_t nodetype; /**< LYS_CHOICE */
908 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
909 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
910 const char *name; /**< node name (mandatory) */
911 const char *dsc; /**< description statement */
912 const char *ref; /**< reference statement */
913 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200914 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200915 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200916
917 /* choice */
918 struct lysp_node *child; /**< list of data nodes (linked list) */
919 const char* dflt; /**< default case */
920};
921
922struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100923 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200924 uint16_t nodetype; /**< LYS_CASE */
925 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
926 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
927 const char *name; /**< node name (mandatory) */
928 const char *dsc; /**< description statement */
929 const char *ref; /**< reference statement */
930 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200931 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200932 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200933
934 /* case */
935 struct lysp_node *child; /**< list of data nodes (linked list) */
936};
937
938struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100939 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200940 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
941 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
942 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
943 const char *name; /**< node name (mandatory) */
944 const char *dsc; /**< description statement */
945 const char *ref; /**< reference statement */
946 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200947 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200948 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200949
950 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200951 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200952};
953
954struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100955 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200956 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200957 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
958 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
959 const char *name; /**< grouping name reference (mandatory) */
960 const char *dsc; /**< description statement */
961 const char *ref; /**< reference statement */
962 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200963 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200964 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200965
966 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200967 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
968 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200969};
970
971/**
972 * @brief YANG input-stmt and output-stmt
973 */
974struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100975 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
976 uint16_t nodetype; /**< LYS_INOUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200977 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
978 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
979 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200980 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200981 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200982};
983
984/**
985 * @brief YANG rpc-stmt and action-stmt
986 */
987struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100988 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko1bf09392020-03-27 12:38:10 +0100989 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100990 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200991 const char *name; /**< grouping name reference (mandatory) */
992 const char *dsc; /**< description statement */
993 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200994 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200995 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
996 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100997 struct lysp_action_inout input; /**< RPC's/Action's input */
998 struct lysp_action_inout output; /**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200999 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001000};
1001
1002/**
1003 * @brief YANG notification-stmt
1004 */
1005struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001006 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1007 uint16_t nodetype; /**< LYS_NOTIF */
1008 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001009 const char *name; /**< grouping name reference (mandatory) */
1010 const char *dsc; /**< description statement */
1011 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +02001012 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001013 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1014 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1015 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001016 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001017 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001018};
1019
1020/**
Radek Krejcif0fceb62018-09-05 14:58:45 +02001021 * @brief supported YANG schema version values
1022 */
1023typedef enum LYS_VERSION {
1024 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
1025 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
1026 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
1027} LYS_VERSION;
1028
1029/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001030 * @brief Printable YANG schema tree structure representing YANG module.
1031 *
1032 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
1033 */
1034struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001035 struct lys_module *mod; /**< covering module structure */
1036
Radek Krejcib7db73a2018-10-24 14:18:40 +02001037 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1038 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001039 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1040 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001041 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1042 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1043 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1044 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1045 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001046 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001047 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1048 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1049 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1050 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
1051 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001052
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001053 uint8_t parsing:1; /**< flag for circular check */
1054};
1055
1056struct lysp_submodule {
1057 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
1058
1059 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1060 in the list is always the last (newest) revision of the module */
1061 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1062 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
1063 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1064 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1065 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1066 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1067 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
1068 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
1069 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1070 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1071 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1072 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
1073 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1074
1075 uint8_t parsing:1; /**< flag for circular check */
1076
Radek Krejci086c7132018-10-26 15:29:04 +02001077 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
1078 1 - the latest revision in searchdirs was not searched yet and this is the
1079 latest revision in the current context
1080 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001081 const char *name; /**< name of the module (mandatory) */
1082 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1083 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
1084 const char *org; /**< party/company responsible for the module */
1085 const char *contact; /**< contact information for the module */
1086 const char *dsc; /**< description of the module */
1087 const char *ref; /**< cross-reference for the module */
Radek Krejci086c7132018-10-26 15:29:04 +02001088 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001089};
1090
1091/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +02001092 * @brief Free the printable YANG schema tree structure.
1093 *
1094 * @param[in] module Printable YANG schema tree structure to free.
1095 */
1096void lysp_module_free(struct lysp_module *module);
1097
1098/**
Radek Krejci535ea9f2020-05-29 16:01:05 +02001099 * @defgroup scflags Schema compile flags
1100 * @ingroup schematree
1101 *
1102 * @{
1103 */
1104#define LYSC_OPT_RPC_INPUT LYS_CONFIG_W /**< Internal option when compiling schema tree of RPC/action input */
1105#define LYSC_OPT_RPC_OUTPUT LYS_CONFIG_R /**< Internal option when compiling schema tree of RPC/action output */
1106#define LYSC_OPT_RPC_MASK LYS_CONFIG_MASK /**< mask for the internal RPC options */
1107#define LYSC_OPT_FREE_SP 0x04 /**< Free the input printable schema */
1108#define LYSC_OPT_INTERNAL 0x08 /**< Internal compilation caused by dependency */
1109#define LYSC_OPT_NOTIFICATION 0x10 /**< Internal option when compiling schema tree of Notification */
1110
1111#define LYSC_OPT_GROUPING 0x20 /** Compiling (validation) of a non-instantiated grouping.
1112 In this case not all the restrictions are checked since they can be valid only
1113 in the real placement of the grouping. TODO - what specifically is not done */
1114/** @} scflags */
1115
1116/**
Radek Krejci0e59c312019-08-15 15:34:15 +02001117 * @brief Compiled YANG extension-stmt
1118 */
1119struct lysc_ext {
1120 const char *name; /**< extension name */
1121 const char *argument; /**< argument name, NULL if not specified */
Radek Krejci0e59c312019-08-15 15:34:15 +02001122 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1123 struct lyext_plugin *plugin; /**< Plugin implementing the specific extension */
Radek Krejci0935f412019-08-20 16:15:18 +02001124 struct lys_module *module; /**< module structure */
Michal Vasko6f4cbb62020-02-28 11:15:47 +01001125 uint32_t refcount; /**< reference counter since extension definition is shared among all its instances */
Radek Krejci0e59c312019-08-15 15:34:15 +02001126 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
1127};
1128
1129/**
Radek Krejcice8c1592018-10-29 15:35:51 +01001130 * @brief YANG extension instance
1131 */
1132struct lysc_ext_instance {
Radek Krejciad5963b2019-09-06 16:03:05 +02001133 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
1134 this identifies the index of the substatement for this extension instance */
Radek Krejci28681fa2019-09-06 13:08:45 +02001135 struct lys_module *module; /**< module where the extension instantiated is defined */
Radek Krejciad5963b2019-09-06 16:03:05 +02001136 struct lysc_ext *def; /**< pointer to the extension definition */
Radek Krejcice8c1592018-10-29 15:35:51 +01001137 void *parent; /**< pointer to the parent element holding the extension instance(s), use
1138 ::lysc_ext_instance#parent_type to access the schema element */
1139 const char *argument; /**< optional value of the extension's argument */
1140 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +01001141 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001142 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0e59c312019-08-15 15:34:15 +02001143 void *data; /**< private plugins's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +01001144};
1145
1146/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001147 * @brief Compiled YANG if-feature-stmt
1148 */
1149struct lysc_iffeature {
1150 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
1151 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
1152};
1153
1154/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001155 * @brief YANG import-stmt
1156 */
1157struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +01001158 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +02001159 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001160 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +02001161};
1162
1163/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001164 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001165 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001166struct lysc_when {
Radek Krejcia0f704a2019-09-09 16:12:23 +02001167 struct lys_module *module; /**< module where the must was defined */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001168 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko175012e2019-11-06 15:49:14 +01001169 struct lysc_node *context; /**< context node for evaluating the expression, NULL if the context is root node */
Radek Krejcic8b31002019-01-08 10:24:45 +01001170 const char *dsc; /**< description */
1171 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001172 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001173 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Michal Vaskoecd62de2019-11-13 12:35:11 +01001174 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS is allowed */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001175};
1176
1177/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001178 * @brief YANG identity-stmt
1179 */
1180struct lysc_ident {
1181 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +01001182 const char *dsc; /**< description */
1183 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001184 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001185 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
1186 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001187 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001188 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1189};
1190
1191/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001192 * @brief YANG feature-stmt
1193 */
1194struct lysc_feature {
1195 const char *name; /**< feature name (mandatory) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001196 const char *dsc; /**< description */
1197 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001198 struct lys_module *module; /**< module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001199 struct lysc_feature **depfeatures;/**< list of pointers to other features depending on this one ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001200 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001201 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001202 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
1203 #LYS_FENABLED values allowed */
1204};
1205
Radek Krejci151a5b72018-10-19 14:21:44 +02001206/**
1207 * @defgroup ifftokens if-feature expression tokens
1208 * Tokens of if-feature expression used in ::lysc_iffeature#expr
1209 *
1210 * @{
1211 */
1212#define LYS_IFF_NOT 0x00 /**< operand "not" */
1213#define LYS_IFF_AND 0x01 /**< operand "and" */
1214#define LYS_IFF_OR 0x02 /**< operand "or" */
1215#define LYS_IFF_F 0x03 /**< feature */
Radek Krejci2ff0d572020-05-21 15:27:28 +02001216/** @} ifftokens */
Radek Krejci151a5b72018-10-19 14:21:44 +02001217
1218/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001219 * @brief Compiled YANG revision statement
1220 */
1221struct lysc_revision {
1222 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1223 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1224};
1225
Radek Krejci2167ee12018-11-02 16:09:07 +01001226struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001227 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001228 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001229 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1230 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001231 };
Radek Krejci693262f2019-04-29 15:23:20 +02001232 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001233 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1234 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001235 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001236 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001237 const char *dsc; /**< description */
1238 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001239 const char *emsg; /**< error-message */
1240 const char *eapptag; /**< error-app-tag value */
1241 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1242};
1243
1244struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001245 const char *expr; /**< original, not compiled, regular expression */
1246 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001247 const char *dsc; /**< description */
1248 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001249 const char *emsg; /**< error-message */
1250 const char *eapptag; /**< error-app-tag value */
1251 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4586a022018-11-13 11:29:26 +01001252 uint32_t inverted:1; /**< invert-match flag */
1253 uint32_t refcount:31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001254};
1255
1256struct lysc_must {
1257 struct lys_module *module; /**< module where the must was defined */
1258 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001259 const char *dsc; /**< description */
1260 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001261 const char *emsg; /**< error-message */
1262 const char *eapptag; /**< error-app-tag value */
1263 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1264};
1265
1266struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001267 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001268 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001269 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001270 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001271 LY_DATA_TYPE basetype; /**< Base type of the type */
1272 uint32_t refcount; /**< reference counter for type sharing */
1273};
1274
1275struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001276 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001277 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001278 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001279 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001280 LY_DATA_TYPE basetype; /**< Base type of the type */
1281 uint32_t refcount; /**< reference counter for type sharing */
1282 struct lysc_range *range; /**< Optional range limitation */
1283};
1284
1285struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001286 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001287 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001288 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001289 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001290 LY_DATA_TYPE basetype; /**< Base type of the type */
1291 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001292 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001293 struct lysc_range *range; /**< Optional range limitation */
1294};
1295
1296struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001297 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001298 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001299 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001300 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001301 LY_DATA_TYPE basetype; /**< Base type of the type */
1302 uint32_t refcount; /**< reference counter for type sharing */
1303 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001304 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001305};
1306
Radek Krejci693262f2019-04-29 15:23:20 +02001307struct lysc_type_bitenum_item {
1308 const char *name; /**< enumeration identifier */
1309 const char *dsc; /**< description */
1310 const char *ref; /**< reference */
1311 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1312 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1313 union {
1314 int32_t value; /**< integer value associated with the enumeration */
1315 uint32_t position; /**< non-negative integer value associated with the bit */
1316 };
1317 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1318 values are allowed */
1319};
1320
Radek Krejci2167ee12018-11-02 16:09:07 +01001321struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001322 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001323 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001324 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001325 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001326 LY_DATA_TYPE basetype; /**< Base type of the type */
1327 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001328 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1329};
1330
1331struct lysc_type_bits {
1332 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1333 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001334 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001335 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci693262f2019-04-29 15:23:20 +02001336 LY_DATA_TYPE basetype; /**< Base type of the type */
1337 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001338 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1339 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001340};
1341
1342struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001343 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001344 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001345 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001346 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001347 LY_DATA_TYPE basetype; /**< Base type of the type */
1348 uint32_t refcount; /**< reference counter for type sharing */
Michal Vasko004d3152020-06-11 19:59:22 +02001349 struct lyxp_expr *path; /**< parsed target path, compiled path cannot be stored because of type sharing */
Radek Krejci96a0bfd2018-11-22 15:25:06 +01001350 struct lys_module *path_context; /**< module where the path is defined, so it provides context to resolve prefixes */
Radek Krejci412ddfa2018-11-23 11:44:11 +01001351 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001352 uint8_t require_instance; /**< require-instance flag */
1353};
1354
1355struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001356 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001357 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001358 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001359 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001360 LY_DATA_TYPE basetype; /**< Base type of the type */
1361 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001362 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001363 mandatory (at least 1 item) */
1364};
1365
1366struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001367 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001368 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001369 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001370 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001371 LY_DATA_TYPE basetype; /**< Base type of the type */
1372 uint32_t refcount; /**< reference counter for type sharing */
1373 uint8_t require_instance; /**< require-instance flag */
1374};
1375
Radek Krejci2167ee12018-11-02 16:09:07 +01001376struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001377 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001378 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001379 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001380 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001381 LY_DATA_TYPE basetype; /**< Base type of the type */
1382 uint32_t refcount; /**< reference counter for type sharing */
1383 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1384};
1385
1386struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001387 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001388 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001389 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001390 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001391 LY_DATA_TYPE basetype; /**< Base type of the type */
1392 uint32_t refcount; /**< reference counter for type sharing */
1393 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001394};
1395
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001396struct lysc_action_inout {
1397 struct lysc_node *data; /**< first child node (linked list) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001398 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1399};
1400
Radek Krejci056d0a82018-12-06 16:57:25 +01001401struct lysc_action {
Michal Vasko1bf09392020-03-27 12:38:10 +01001402 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci056d0a82018-12-06 16:57:25 +01001403 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001404 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001405 struct lysp_action *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1406 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1407
Radek Krejcifc11bd72019-04-11 16:00:05 +02001408 struct lysc_ext_instance *input_exts; /**< list of the extension instances of input ([sized array](@ref sizedarrays)) */
1409 struct lysc_ext_instance *output_exts; /**< list of the extension instances of outpu ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001410
Radek Krejci056d0a82018-12-06 16:57:25 +01001411 const char *name; /**< action/RPC name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001412 const char *dsc; /**< description */
1413 const char *ref; /**< reference */
1414
Radek Krejcifc11bd72019-04-11 16:00:05 +02001415 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1416 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1417
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001418 struct lysc_action_inout input; /**< RPC's/action's input */
1419 struct lysc_action_inout output; /**< RPC's/action's output */
1420
Radek Krejci056d0a82018-12-06 16:57:25 +01001421};
1422
1423struct lysc_notif {
1424 uint16_t nodetype; /**< LYS_NOTIF */
1425 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001426 struct lys_module *module; /**< module structure */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001427 struct lysp_notif *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001428 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1429
Radek Krejcifc11bd72019-04-11 16:00:05 +02001430 struct lysc_node *data; /**< first child node (linked list) */
1431 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1432
Radek Krejci056d0a82018-12-06 16:57:25 +01001433 const char *name; /**< Notification name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001434 const char *dsc; /**< description */
1435 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001436
1437 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1438 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001439};
1440
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001441/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001442 * @brief Compiled YANG data node
1443 */
1444struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001445 uint16_t nodetype; /**< type of the node (mandatory) */
1446 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001447 struct lys_module *module; /**< module structure */
Michal Vaskocc048b22020-03-27 15:52:38 +01001448 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or
1449 in case of implicit case node. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001450 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1451 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1452 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1453 never NULL. If there is no sibling node, pointer points to the node
1454 itself. In case of the first node, this pointer points to the last
1455 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001456 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001457 const char *dsc; /**< description */
1458 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001459 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001460 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001461 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001462};
1463
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001464struct lysc_node_container {
1465 uint16_t nodetype; /**< LYS_CONTAINER */
1466 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1467 struct lys_module *module; /**< module structure */
1468 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1469 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1470 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1471 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1472 never NULL. If there is no sibling node, pointer points to the node
1473 itself. In case of the first node, this pointer points to the last
1474 node in the list. */
1475 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001476 const char *dsc; /**< description */
1477 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001478 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001479 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001480 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001481
1482 struct lysc_node *child; /**< first child node (linked list) */
1483 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1484 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1485 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001486};
1487
Radek Krejcia3045382018-11-22 14:30:31 +01001488struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001489 uint16_t nodetype; /**< LYS_CASE */
1490 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1491 struct lys_module *module; /**< module structure */
1492 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1493 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1494 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1495 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1496 never NULL. If there is no sibling node, pointer points to the node
1497 itself. In case of the first node, this pointer points to the last
1498 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001499 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001500 const char *dsc; /**< description */
1501 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001502 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001503 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001504 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001505
Radek Krejcia3045382018-11-22 14:30:31 +01001506 struct lysc_node *child; /**< first child node of the case (linked list). Note that all the children of all the sibling cases are linked
Radek Krejcife13da42019-02-15 14:51:01 +01001507 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001508};
1509
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001510struct lysc_node_choice {
1511 uint16_t nodetype; /**< LYS_CHOICE */
1512 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1513 struct lys_module *module; /**< module structure */
1514 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1515 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1516 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1517 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1518 never NULL. If there is no sibling node, pointer points to the node
1519 itself. In case of the first node, this pointer points to the last
1520 node in the list. */
1521 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001522 const char *dsc; /**< description */
1523 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001524 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001525 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001526 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001527
Radek Krejcia9026eb2018-12-12 16:04:47 +01001528 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1529 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1530 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001531 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001532};
1533
1534struct lysc_node_leaf {
1535 uint16_t nodetype; /**< LYS_LEAF */
1536 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1537 struct lys_module *module; /**< module structure */
1538 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1539 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1540 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1541 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1542 never NULL. If there is no sibling node, pointer points to the node
1543 itself. In case of the first node, this pointer points to the last
1544 node in the list. */
1545 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001546 const char *dsc; /**< description */
1547 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001548 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001549 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001550 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001551
1552 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1553 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001554
Radek Krejci4f28eda2018-11-12 11:46:16 +01001555 const char *units; /**< units of the leaf's type */
Radek Krejcia1911222019-07-22 17:24:50 +02001556 struct lyd_value *dflt; /**< default value */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001557 struct lys_module *dflt_mod; /**< module where the lysc_node_leaf::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001558};
1559
1560struct lysc_node_leaflist {
1561 uint16_t nodetype; /**< LYS_LEAFLIST */
1562 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1563 struct lys_module *module; /**< module structure */
1564 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1565 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1566 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1567 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1568 never NULL. If there is no sibling node, pointer points to the node
1569 itself. In case of the first node, this pointer points to the last
1570 node in the list. */
1571 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001572 const char *dsc; /**< description */
1573 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001574 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001575 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001576 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001577
1578 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1579 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1580
Radek Krejci0e5d8382018-11-28 16:37:53 +01001581 const char *units; /**< units of the leaf's type */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001582 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values */
1583 struct lys_module **dflts_mods; /**< list ([sized array](@ref sizedarrays)) of modules where the lysc_node_leaflist::dflts values were defined
1584 (needed to correctly map prefixes). */
Radek Krejci0e5d8382018-11-28 16:37:53 +01001585 uint32_t min; /**< min-elements constraint */
1586 uint32_t max; /**< max-elements constraint */
1587
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001588};
1589
1590struct lysc_node_list {
1591 uint16_t nodetype; /**< LYS_LIST */
1592 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1593 struct lys_module *module; /**< module structure */
1594 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1595 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1596 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1597 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1598 never NULL. If there is no sibling node, pointer points to the node
1599 itself. In case of the first node, this pointer points to the last
1600 node in the list. */
1601 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001602 const char *dsc; /**< description */
1603 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001604 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001605 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001606 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001607
1608 struct lysc_node *child; /**< first child node (linked list) */
1609 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1610 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1611 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1612
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001613 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1614 uint32_t min; /**< min-elements constraint */
1615 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001616};
1617
1618struct lysc_node_anydata {
1619 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1620 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1621 struct lys_module *module; /**< module structure */
1622 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1623 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1624 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1625 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1626 never NULL. If there is no sibling node, pointer points to the node
1627 itself. In case of the first node, this pointer points to the last
1628 node in the list. */
1629 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001630 const char *dsc; /**< description */
1631 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001632 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001633 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001634 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9800fb82018-12-13 14:26:23 +01001635
1636 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001637};
1638
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001639/**
1640 * @brief Compiled YANG schema tree structure representing YANG module.
1641 *
1642 * Semantically validated YANG schema tree for data tree parsing.
1643 * Contains only the necessary information for the data validation.
1644 */
1645struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001646 struct lys_module *mod; /**< covering module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001647 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001648
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001649 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001650 struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1651 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1652 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1653 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001654 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko57c10cd2020-05-27 15:57:11 +02001655 struct lys_module **deviated_by; /**< List of modules that deviate this module ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001656};
1657
1658/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001659 * @brief Get the groupings sized array of the given (parsed) schema node.
1660 * Decides the node's type and in case it has a groupings array, returns it.
1661 * @param[in] node Node to examine.
1662 * @return The node's groupings sized array if any, NULL otherwise.
1663 */
1664const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1665
1666/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001667 * @brief Get the typedefs sized array of the given (parsed) schema node.
1668 * Decides the node's type and in case it has a typedefs array, returns it.
1669 * @param[in] node Node to examine.
1670 * @return The node's typedefs sized array if any, NULL otherwise.
1671 */
1672const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1673
1674/**
1675 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1676 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1677 * @param[in] node Node to examine.
1678 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1679 */
1680const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1681
1682/**
1683 * @brief Get the Notifications sized array of the given (parsed) schema node.
1684 * Decides the node's type and in case it has a Notifications array, returns it.
1685 * @param[in] node Node to examine.
1686 * @return The node's Notifications sized array if any, NULL otherwise.
1687 */
1688const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1689
1690/**
1691 * @brief Get the children linked list of the given (parsed) schema node.
1692 * Decides the node's type and in case it has a children list, returns it.
1693 * @param[in] node Node to examine.
1694 * @return The node's children linked list if any, NULL otherwise.
1695 */
1696const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1697
1698/**
1699 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1700 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1701 * @param[in] node Node to examine.
1702 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1703 */
1704const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1705
1706/**
1707 * @brief Get the Notifications sized array of the given (compiled) schema node.
1708 * Decides the node's type and in case it has a Notifications array, returns it.
1709 * @param[in] node Node to examine.
1710 * @return The node's Notifications sized array if any, NULL otherwise.
1711 */
1712const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1713
1714/**
1715 * @brief Get the children linked list of the given (compiled) schema node.
1716 * Decides the node's type and in case it has a children list, returns it.
1717 * @param[in] node Node to examine.
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001718 * @param[in] flags Config flag to distinguish input (LYS_CONFIG_W) and output (LYS_CONFIG_R) data in case of RPC/action node.
Radek Krejci056d0a82018-12-06 16:57:25 +01001719 * @return The node's children linked list if any, NULL otherwise.
1720 */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001721const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Radek Krejci056d0a82018-12-06 16:57:25 +01001722
1723/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001724 * @brief Get how the if-feature statement currently evaluates.
1725 *
1726 * @param[in] iff Compiled if-feature statement to evaluate.
Michal Vasko28d78432020-05-26 13:10:53 +02001727 * @return LY_SUCCESS if the statement evaluates to true,
1728 * @return LY_ENOT if it evaluates to false,
1729 * @return LY_ERR on error.
Radek Krejci151a5b72018-10-19 14:21:44 +02001730 */
Michal Vasko28d78432020-05-26 13:10:53 +02001731LY_ERR lysc_iffeature_value(const struct lysc_iffeature *iff);
Radek Krejci151a5b72018-10-19 14:21:44 +02001732
1733/**
1734 * @brief Get the current status of the provided feature.
1735 *
1736 * @param[in] feature Compiled feature statement to examine.
Michal Vasko28d78432020-05-26 13:10:53 +02001737 * @return LY_SUCCESS if feature is enabled,
1738 * @return LY_ENOT if feature is disabled,
1739 * @return LY_ERR in case of error (invalid argument)
Radek Krejci151a5b72018-10-19 14:21:44 +02001740 */
Michal Vasko28d78432020-05-26 13:10:53 +02001741LY_ERR lysc_feature_value(const struct lysc_feature *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001742
1743/**
Michal Vasko519fd602020-05-26 12:17:39 +02001744 * @brief Get all the schema nodes (atoms) that are required for \p xpath to be evaluated.
1745 *
1746 * @param[in] ctx_node XPath schema context node.
1747 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LYD_JSON format is expected.
1748 * @param[in] options Whether to apply some node access restrictions, one of the options should always be used.
1749 * If none is set, ::LYXP_SCNODE is used.
1750 * @param[out] set Set of found atoms (schema nodes).
1751 * @return LY_SUCCESS on success, @p set is returned.
1752 * @return LY_ERR value if an error occurred.
1753 */
1754LY_ERR lys_atomize_xpath(const struct lysc_node *ctx_node, const char *xpath, int options, struct ly_set **set);
1755
1756#define LYXP_SCNODE 0x02 /**< No special tree access modifiers. */
1757#define LYXP_SCNODE_SCHEMA 0x04 /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */
1758#define LYXP_SCNODE_OUTPUT 0x08 /**< Search RPC/action output nodes instead of input ones. */
1759
1760/**
Michal Vasko03ff5a72019-09-11 13:49:33 +02001761 * @brief Types of the different schema paths.
1762 */
1763typedef enum {
1764 LYSC_PATH_LOG /**< Descriptive path format used in log messages */
1765} LYSC_PATH_TYPE;
1766
1767/**
Radek Krejci327de162019-06-14 12:52:07 +02001768 * @brief Generate path of the given node in the requested format.
1769 *
1770 * @param[in] node Schema path of this node will be generated.
1771 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001772 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
1773 * If NULL, memory for the complete path is allocated.
1774 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02001775 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001776 * In case the @p buffer is NULL, the returned string is dynamically allocated and caller is responsible to free it.
Radek Krejci327de162019-06-14 12:52:07 +02001777 */
Michal Vasko03ff5a72019-09-11 13:49:33 +02001778char *lysc_path(const struct lysc_node *node, LYSC_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02001779
1780/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001781 * @brief Available YANG schema tree structures representing YANG module.
1782 */
1783struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001784 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
1785 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01001786 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001787 const char *ns; /**< namespace of the module (module - mandatory) */
1788 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
1789 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1790 const char *org; /**< party/company responsible for the module */
1791 const char *contact; /**< contact information for the module */
1792 const char *dsc; /**< description of the module */
1793 const char *ref; /**< cross-reference for the module */
1794
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001795 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01001796 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
1797 Available only for implemented modules. */
1798 struct lysc_feature *off_features;/**< List of pre-compiled features of the module in non implemented modules ([sized array](@ref sizedarrays)).
1799 These features are always disabled and cannot be enabled until the module
1800 become implemented. The features are present in this form to allow their linkage
1801 from if-feature statements of the compiled schemas and their proper use in case
1802 the module became implemented in future (no matter if implicitly via augment/deviate
1803 or explicitly via ly_ctx_module_implement()). */
Radek Krejci95710c92019-02-11 15:49:55 +01001804 uint8_t implemented; /**< flag if the module is implemented, not just imported. The module is implemented if
1805 the flag has non-zero value. Specific values are used internally:
1806 1 - implemented module
1807 2 - recently implemented module by dependency, it can be reverted in rollback procedure */
1808 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001809 1 - the latest revision in searchdirs was not searched yet and this is the
1810 latest revision in the current context
1811 2 - searchdirs were searched and this is the latest available revision */
1812 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001813};
1814
Radek Krejci151a5b72018-10-19 14:21:44 +02001815/**
1816 * @brief Enable specified feature in the module
1817 *
1818 * By default, when the module is loaded by libyang parser, all features are disabled.
1819 *
Radek Krejcica3db002018-11-01 10:31:01 +01001820 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
1821 * enabling all features on the following feature set will fail since it is not possible to enable both features
1822 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
1823 * is untouched.
1824 *
1825 * feature f1;
1826 * feature f2 { if-feature 'not f1';}
1827 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001828 * @param[in] module Module where the feature will be enabled.
1829 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
1830 * @return LY_ERR value.
1831 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001832LY_ERR lys_feature_enable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001833
1834/**
1835 * @brief Disable specified feature in the module
1836 *
1837 * By default, when the module is loaded by libyang parser, all features are disabled.
1838 *
1839 * @param[in] module Module where the feature will be disabled.
1840 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
1841 * @return LY_ERR value
1842 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001843LY_ERR lys_feature_disable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001844
1845/**
1846 * @brief Get the current status of the specified feature in the module.
1847 *
1848 * @param[in] module Module where the feature is defined.
1849 * @param[in] feature Name of the feature to inspect.
1850 * @return
1851 * - 1 if feature is enabled,
1852 * - 0 if feature is disabled,
1853 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
1854 */
1855int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001856
1857/**
Radek Krejcia3045382018-11-22 14:30:31 +01001858 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
1859 * be from an augment.
1860 *
1861 * lys_getnext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
1862 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
1863 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
1864 * \p parent and \p module parameters.
1865 *
1866 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
1867 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
1868 * all the schema nodes are iteratively returned.
1869 *
1870 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
1871 * @param[in] parent Parent of the subtree where the function starts processing.
1872 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
1873 * module must be specified.
1874 * @param[in] options [ORed options](@ref sgetnextflags).
1875 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
1876 */
1877const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
1878 const struct lysc_module *module, int options);
1879
1880/**
1881 * @defgroup sgetnextflags lys_getnext() flags
Radek Krejcia3045382018-11-22 14:30:31 +01001882 * @{
1883 */
1884#define LYS_GETNEXT_WITHCHOICE 0x01 /**< lys_getnext() option to allow returning #LYS_CHOICE nodes instead of looking into them */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001885#define LYS_GETNEXT_NOCHOICE 0x02 /**< lys_getnext() option to ignore (kind of conditional) nodes within choice node */
Radek Krejci056d0a82018-12-06 16:57:25 +01001886#define LYS_GETNEXT_WITHCASE 0x04 /**< lys_getnext() option to allow returning #LYS_CASE nodes instead of looking into them */
Radek Krejcia3045382018-11-22 14:30:31 +01001887#define LYS_GETNEXT_INTONPCONT 0x40 /**< lys_getnext() option to look into non-presence container, instead of returning container itself */
1888#define LYS_GETNEXT_NOSTATECHECK 0x100 /**< lys_getnext() option to skip checking module validity (import-only, disabled) and
1889 relevant if-feature conditions state */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001890#define LYS_GETNEXT_OUTPUT 0x200 /**< lys_getnext() option to provide RPC's/action's output schema nodes instead of input schema nodes
1891 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01001892/** @} sgetnextflags */
1893
1894/**
1895 * @brief Get child node according to the specified criteria.
1896 *
1897 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
1898 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
1899 * @param[in] name Name of the node to find.
1900 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
1901 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
1902 * Used as a bitmask, so multiple nodetypes can be specified.
1903 * @param[in] options [ORed options](@ref sgetnextflags).
1904 * @return Found node if any.
1905 */
Michal Vaskoe444f752020-02-10 12:20:06 +01001906const struct lysc_node *lys_find_child(const struct lysc_node *parent, const struct lys_module *module,
1907 const char *name, size_t name_len, uint16_t nodetype, int options);
Radek Krejcia3045382018-11-22 14:30:31 +01001908
1909/**
Radek Krejci09e8d0a2019-11-17 12:14:15 +08001910 * @brief Get schema node specified by the schema path.
1911 *
1912 * In case the @p qpath uses prefixes (from imports or of the schema itself), the @p context_node must be specified
1913 * even if the path is absolute. In case the @p context_node is not provided, the names of the schemas are expected as the
1914 * node's prefixes in the @qpath. It also means that the relative paths are accepted only with the schema prefixes,
1915 * not the full names.
1916 *
1917 * @param[in] ctx libyang context for logging and getting the correct schema if @p contet_node not provided.
1918 * @param[in] context_node Context node for relative paths and/or as a source of the context module to resolve node's
1919 * prefixes in @qpath.
1920 * @param[in] qpath Schema path to be resolved. Not prefixed nodes inherits the prefix from its parent nodes. It means
1921 * that the first node in the path must be prefixed. Both, import prefixes as well as full schema names are accepted as
1922 * prefixes according to the @p context_node parameter presence.
1923 * @return NULL in case of invalid path.
1924 * @return found schema node.
1925 */
1926const struct lysc_node *lys_find_node(struct ly_ctx *ctx, const struct lysc_node *context_node, const char *qpath);
1927
1928/**
Radek Krejci77a8bcd2019-09-11 11:20:02 +02001929 * @brief Make the specific module implemented.
1930 *
1931 * @param[in] mod Module to make implemented. It is not an error
1932 * to provide already implemented module, it just does nothing.
Michal Vaskoe444f752020-02-10 12:20:06 +01001933 * @return LY_SUCCESS on success.
1934 * @return LY_EDENIED in case the context contains some other revision of the same module which is already implemented.
Radek Krejci77a8bcd2019-09-11 11:20:02 +02001935 */
1936LY_ERR lys_set_implemented(struct lys_module *mod);
1937
1938/**
Radek Krejcia3045382018-11-22 14:30:31 +01001939 * @brief Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statement
1940 * affecting the node.
1941 *
1942 * @param[in] node Schema node to check.
1943 * @param[in] recursive - 0 to check if-feature only in the \p node schema node,
1944 * - 1 to check if-feature in all ascendant schema nodes until there is a node possibly having an instance in a data tree
Michal Vaskoe444f752020-02-10 12:20:06 +01001945 * @return NULL if enabled,
Michal Vaskoc193ce92020-03-06 11:04:48 +01001946 * @return pointer to the node with the unsatisfied (disabled) if-feature expression.
Radek Krejcia3045382018-11-22 14:30:31 +01001947 */
Michal Vaskoc193ce92020-03-06 11:04:48 +01001948const struct lysc_node *lysc_node_is_disabled(const struct lysc_node *node, int recursive);
Radek Krejcia3045382018-11-22 14:30:31 +01001949
Radek Krejci084289f2019-07-09 17:35:30 +02001950/**
1951 * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
1952 *
1953 * This function check just the type's restriction, if you want to check also the data tree context (e.g. in case of
1954 * require-instance restriction), use lyd_value_validate().
1955 *
1956 * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
1957 * @param[in] node Schema node for the @p value.
1958 * @param[in] value String value to be checked.
1959 * @param[in] value_len Length of the given @p value (mandatory).
1960 * @param[in] get_prefix Callback function to resolve prefixes used in the @p value string.
1961 * @param[in] get_prefix_data Private data for the @p get_prefix callback.
1962 * @param[in] format Input format of the @p value.
1963 * @return LY_SUCCESS on success
1964 * @return LY_ERR value if an error occurred.
1965 */
Michal Vasko44685da2020-03-17 15:38:06 +01001966LY_ERR lys_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len,
Radek Krejci084289f2019-07-09 17:35:30 +02001967 ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format);
1968
Radek Krejci0935f412019-08-20 16:15:18 +02001969/**
1970 * @brief Stringify schema nodetype.
1971 * @param[in] nodetype Nodetype to stringify.
1972 * @return Constant string with the name of the node's type.
1973 */
1974const char *lys_nodetype2str(uint16_t nodetype);
1975
Radek Krejci2ff0d572020-05-21 15:27:28 +02001976/** @} schematree */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001977
Radek Krejci70853c52018-10-15 14:46:16 +02001978#ifdef __cplusplus
1979}
1980#endif
1981
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001982#endif /* LY_TREE_SCHEMA_H_ */