blob: 5410de402ae7753f0571cd79376bf7f9127b0bf1 [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 Krejci70853c52018-10-15 14:46:16 +020029#ifdef __cplusplus
30extern "C" {
31#endif
32
Radek Krejcica376bd2020-06-11 16:04:06 +020033struct ly_ctx;
34struct ly_set;
35
Radek Krejci5aeea3a2018-09-05 13:29:36 +020036/**
Radek Krejci2ff0d572020-05-21 15:27:28 +020037 * @defgroup schematree Schema Tree
38 * @ingroup trees
39 * @{
40 *
41 * Data structures and functions to manipulate and access schema tree.
42 */
43
44/**
Radek Krejci0935f412019-08-20 16:15:18 +020045 * @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 +020046 * (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 +020047 *
48 * The function follows deep-first search algorithm:
49 * <pre>
50 * 1
51 * / \
52 * 2 4
53 * / / \
54 * 3 5 6
55 * </pre>
56 *
57 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
58 * START can be any of the lysc_node* types (including lysc_action and lysc_notif),
59 * ELEM variable must be of the struct lysc_node* type.
60 *
61 * To skip a particular subtree, instead of the continue statement, set LYSC_TREE_DFS_continue
62 * variable to non-zero value.
63 *
64 * Use with opening curly bracket '{' after the macro.
65 *
66 * @param START Pointer to the starting element processed first.
67 * @param ELEM Iterator intended for use in the block.
68 */
69#define LYSC_TREE_DFS_BEGIN(START, ELEM) \
70 { int LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
71 for ((ELEM) = (LYSC_TREE_DFS_next) = (START); \
72 (ELEM); \
73 (ELEM) = (LYSC_TREE_DFS_next), LYSC_TREE_DFS_continue = 0)
74
75/**
76 * @brief Macro to iterate via all elements in a (sub)tree. This is the closing part
77 * to the #LYSC_TREE_DFS_BEGIN - they always have to be used together.
78 *
79 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
80 * START can be a pointer to any of the lysc_node* types (including lysc_action and lysc_notif),
81 * ELEM variable must be pointer to the lysc_node type.
82 *
83 * Use with closing curly bracket '}' after the macro.
84 *
85 * @param START Pointer to the starting element processed first.
86 * @param ELEM Iterator intended for use in the block.
87 */
88
89#define LYSC_TREE_DFS_END(START, ELEM) \
90 /* select element for the next run - children first */ \
91 if (LYSC_TREE_DFS_continue) { \
92 (LYSC_TREE_DFS_next) = NULL; \
93 } else { \
94 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, 0); \
95 }\
96 if (!(LYSC_TREE_DFS_next)) { \
97 /* in case of RPC/action, get also the output children */ \
Michal Vasko1bf09392020-03-27 12:38:10 +010098 if (!LYSC_TREE_DFS_continue && (ELEM)->nodetype & (LYS_RPC | LYS_ACTION)) { \
Radek Krejci0935f412019-08-20 16:15:18 +020099 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, LYS_CONFIG_R); \
100 } \
101 if (!(LYSC_TREE_DFS_next)) { \
102 /* no children */ \
103 if ((ELEM) == (struct lysc_node*)(START)) { \
104 /* we are done, (START) has no children */ \
105 break; \
106 } \
107 /* try siblings */ \
108 (LYSC_TREE_DFS_next) = (ELEM)->next; \
109 } \
110 } \
111 while (!(LYSC_TREE_DFS_next)) { \
112 /* parent is already processed, go to its sibling */ \
113 (ELEM) = (ELEM)->parent; \
114 /* no siblings, go back through parents */ \
115 if ((ELEM) == (struct lysc_node*)(START)) { \
116 /* we are done, no next element to process */ \
117 break; \
118 } \
Michal Vasko1bf09392020-03-27 12:38:10 +0100119 if ((ELEM)->nodetype & (LYS_RPC | LYS_ACTION)) { \
Radek Krejci0935f412019-08-20 16:15:18 +0200120 /* there is actually next node as a child of action's output */ \
121 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, LYS_CONFIG_R); \
122 } \
123 if (!(LYSC_TREE_DFS_next)) { \
124 (LYSC_TREE_DFS_next) = (ELEM)->next; \
125 } \
126 } } \
127
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200128#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
129
Michal Vaskob55f6c12018-09-12 11:13:15 +0200130#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
131#define LYS_CONTAINER 0x0001 /**< container statement node */
132#define LYS_CHOICE 0x0002 /**< choice statement node */
133#define LYS_LEAF 0x0004 /**< leaf statement node */
134#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
135#define LYS_LIST 0x0010 /**< list statement node */
136#define LYS_ANYXML 0x0020 /**< anyxml statement node */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200137#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 +0200138
Michal Vasko1bf09392020-03-27 12:38:10 +0100139#define LYS_RPC 0x400 /**< RPC statement node */
140#define LYS_ACTION 0x800 /**< action statement node */
141#define LYS_NOTIF 0x1000 /**< notification statement node */
Radek Krejcie7b95092019-05-15 11:03:07 +0200142
Radek Krejcia3045382018-11-22 14:30:31 +0100143#define LYS_CASE 0x0040 /**< case statement node */
144#define LYS_USES 0x0080 /**< uses statement node */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200145#define LYS_INPUT 0x100
146#define LYS_OUTPUT 0x200
147#define LYS_INOUT 0x300
Michal Vasko1bf09392020-03-27 12:38:10 +0100148#define LYS_GROUPING 0x2000
149#define LYS_AUGMENT 0x4000
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100150
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200151/**
Radek Krejcid6b76452019-09-03 17:03:03 +0200152 * @brief List of YANG statements
153 */
154enum ly_stmt {
155 LY_STMT_NONE = 0,
Radek Krejciad5963b2019-09-06 16:03:05 +0200156 LY_STMT_STATUS, /**< in lysc_ext_substmt::storage stored as a pointer to `uint16_t`, only cardinality < #LY_STMT_CARD_SOME is allowed */
157 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 +0200158 LY_STMT_MANDATORY,
Radek Krejciad5963b2019-09-06 16:03:05 +0200159 LY_STMT_UNITS, /**< in lysc_ext_substmt::storage stored as a pointer to `const char *` (cardinality < #LY_STMT_CARD_SOME)
160 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200161 LY_STMT_DEFAULT,
Radek Krejciad5963b2019-09-06 16:03:05 +0200162 LY_STMT_TYPE, /**< in lysc_ext_substmt::storage stored as a pointer to `struct lysc_type *` (cardinality < #LY_STMT_CARD_SOME)
163 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_type **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200164
Radek Krejcid6b76452019-09-03 17:03:03 +0200165 LY_STMT_ACTION,
166 LY_STMT_ANYDATA,
167 LY_STMT_ANYXML,
168 LY_STMT_ARGUMENT,
169 LY_STMT_AUGMENT,
170 LY_STMT_BASE,
171 LY_STMT_BELONGS_TO,
172 LY_STMT_BIT,
173 LY_STMT_CASE,
174 LY_STMT_CHOICE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200175 LY_STMT_CONTACT,
176 LY_STMT_CONTAINER,
Radek Krejcid6b76452019-09-03 17:03:03 +0200177 LY_STMT_DESCRIPTION,
178 LY_STMT_DEVIATE,
179 LY_STMT_DEVIATION,
180 LY_STMT_ENUM,
181 LY_STMT_ERROR_APP_TAG,
182 LY_STMT_ERROR_MESSAGE,
183 LY_STMT_EXTENSION,
184 LY_STMT_FEATURE,
185 LY_STMT_FRACTION_DIGITS,
186 LY_STMT_GROUPING,
187 LY_STMT_IDENTITY,
Radek Krejciad5963b2019-09-06 16:03:05 +0200188 LY_STMT_IF_FEATURE, /**< in lysc_ext_substmt::storage stored as a pointer to `struct lysc_iffeature` (cardinality < #LY_STMT_CARD_SOME)
189 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_iffeature *` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200190 LY_STMT_IMPORT,
191 LY_STMT_INCLUDE,
192 LY_STMT_INPUT,
193 LY_STMT_KEY,
194 LY_STMT_LEAF,
195 LY_STMT_LEAF_LIST,
196 LY_STMT_LENGTH,
197 LY_STMT_LIST,
Radek Krejcid6b76452019-09-03 17:03:03 +0200198 LY_STMT_MAX_ELEMENTS,
199 LY_STMT_MIN_ELEMENTS,
200 LY_STMT_MODIFIER,
201 LY_STMT_MODULE,
202 LY_STMT_MUST,
203 LY_STMT_NAMESPACE,
204 LY_STMT_NOTIFICATION,
205 LY_STMT_ORDERED_BY,
206 LY_STMT_ORGANIZATION,
207 LY_STMT_OUTPUT,
208 LY_STMT_PATH,
209 LY_STMT_PATTERN,
210 LY_STMT_POSITION,
211 LY_STMT_PREFIX,
212 LY_STMT_PRESENCE,
213 LY_STMT_RANGE,
214 LY_STMT_REFERENCE,
215 LY_STMT_REFINE,
216 LY_STMT_REQUIRE_INSTANCE,
217 LY_STMT_REVISION,
218 LY_STMT_REVISION_DATE,
219 LY_STMT_RPC,
Radek Krejcid6b76452019-09-03 17:03:03 +0200220 LY_STMT_SUBMODULE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200221 LY_STMT_TYPEDEF,
222 LY_STMT_UNIQUE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200223 LY_STMT_USES,
224 LY_STMT_VALUE,
225 LY_STMT_WHEN,
226 LY_STMT_YANG_VERSION,
227 LY_STMT_YIN_ELEMENT,
228 LY_STMT_EXTENSION_INSTANCE,
229
230 LY_STMT_SYNTAX_SEMICOLON,
231 LY_STMT_SYNTAX_LEFT_BRACE,
232 LY_STMT_SYNTAX_RIGHT_BRACE,
233
234 LY_STMT_ARG_TEXT,
235 LY_STMT_ARG_VALUE
236};
237
238/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200239 * @brief Extension instance structure parent enumeration
240 */
241typedef enum {
Radek Krejci0935f412019-08-20 16:15:18 +0200242 LYEXT_PAR_MODULE, /**< ::lysc_module */
243 LYEXT_PAR_NODE, /**< ::lysc_node (and the derived structures including ::lysc_action and ::lysc_notif) */
244 LYEXT_PAR_INPUT, /**< ::lysc_action_inout */
245 LYEXT_PAR_OUTPUT, /**< ::lysc_action_inout */
246 LYEXT_PAR_TYPE, /**< ::lysc_type */
247 LYEXT_PAR_TYPE_BIT, /**< ::lysc_type_bitenum_item */
248 LYEXT_PAR_TYPE_ENUM, /**< ::lysc_type_bitenum_item */
249 LYEXT_PAR_FEATURE, /**< ::lysc_feature */
250 LYEXT_PAR_MUST, /**< ::lysc_must */
251 LYEXT_PAR_PATTERN, /**< ::lysc_pattern */
252 LYEXT_PAR_LENGTH, /**< ::lysc_range */
253 LYEXT_PAR_RANGE, /**< ::lysc_range */
254 LYEXT_PAR_WHEN, /**< ::lysc_when */
255 LYEXT_PAR_IDENT, /**< ::lysc_ident */
256 LYEXT_PAR_EXT, /**< ::lysc_ext */
257 LYEXT_PAR_IMPORT, /**< ::lysc_import */
258// LYEXT_PAR_TPDF, /**< ::lysp_tpdf */
259// LYEXT_PAR_EXTINST, /**< ::lysp_ext_instance */
260// LYEXT_PAR_REFINE, /**< ::lysp_refine */
261// LYEXT_PAR_DEVIATION, /**< ::lysp_deviation */
262// LYEXT_PAR_DEVIATE, /**< ::lysp_deviate */
263// LYEXT_PAR_INCLUDE, /**< ::lysp_include */
264// LYEXT_PAR_REVISION, /**< ::lysp_revision */
Radek Krejci0e59c312019-08-15 15:34:15 +0200265} LYEXT_PARENT;
266
267/**
Radek Krejci0935f412019-08-20 16:15:18 +0200268 * @brief Stringify extension instance parent type.
269 * @param[in] type Parent type to stringify.
270 * @return Constant string with the name of the parent statement.
271 */
272const char *lyext_parent2str(LYEXT_PARENT type);
273
274/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200275 * @brief Enum of substatements in which extension instances can appear.
276 */
277typedef enum {
278 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
279 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
280 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
281 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
282 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
283 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
284 lys_node_choice and lys_deviate */
285 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
286 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
287 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
288 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
289 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
290 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
291 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
292 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
293 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
294 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
295 belongs-to's prefix) and lys_import */
296 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
297 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
298 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
299 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
300 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
301 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
302 lys_node_leaflist and lys_deviate */
303 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
304 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
305 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
306 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
307 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
308 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
309 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
310 lys_node_anydata and lys_deviate */
311 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
312 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
313 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
314 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
315 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
316 lys_node_leaflist and lys_deviate */
317 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
318 lys_node_leaflist and lys_deviate */
319 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
320 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
321 LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */
322} LYEXT_SUBSTMT;
323
324/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200325 * @brief YANG import-stmt
326 */
327struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200328 struct lys_module *module; /**< pointer to the imported module
329 (mandatory, but resolved when the referring module is completely parsed) */
330 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200331 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200332 const char *dsc; /**< description */
333 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200334 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200335 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
336};
337
338/**
339 * @brief YANG include-stmt
340 */
341struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100342 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200343 (mandatory, but resolved when the referring module is completely parsed) */
344 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200345 const char *dsc; /**< description */
346 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200347 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200348 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
349};
350
351/**
352 * @brief YANG extension-stmt
353 */
354struct lysp_ext {
355 const char *name; /**< extension name */
356 const char *argument; /**< argument name, NULL if not specified */
357 const char *dsc; /**< description statement */
358 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200359 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200360 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */
Michal Vasko5fe75f12020-03-02 13:52:37 +0100361
362 struct lysc_ext *compiled; /**< pointer to the compiled extension definition */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200363};
364
365/**
366 * @brief Helper structure for generic storage of the extension instances content.
367 */
368struct lysp_stmt {
369 const char *stmt; /**< identifier of the statement */
370 const char *arg; /**< statement's argument */
371 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200372 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
David Sedlákb9d75c42019-08-14 10:49:42 +0200373 uint16_t flags; /**< statement flags, can be set to LYS_YIN_ATTR */
Radek Krejci335332a2019-09-05 13:03:35 +0200374 enum ly_stmt kw; /**< numeric respresentation of the stmt value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200375};
376
David Sedlákae4b4512019-08-14 10:45:56 +0200377#define LYS_YIN 0x1 /**< used to specify input format of extension instance */
378
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200379/**
380 * @brief YANG extension instance
381 */
382struct lysp_ext_instance {
David Sedlákbbd06ca2019-06-27 14:15:38 +0200383 const char *name; /**< extension identifier, including possible prefix */
384 const char *argument; /**< optional value of the extension's argument */
Radek Krejci335332a2019-09-05 13:03:35 +0200385 void *parent; /**< pointer to the parent element holding the extension instance(s), use
386 ::lysp_ext_instance#parent_type to access the schema element */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200387 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200388 struct lysc_ext_instance *compiled; /**< pointer to the compiled data if any - in case the source format is YIN,
389 some of the information (argument) are available only after compilation */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200390 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200391 LY_ARRAY_COUNT_TYPE insubstmt_index; /**< in case the instance is in a substatement, this identifies
David Sedlákbbd06ca2019-06-27 14:15:38 +0200392 the index of that substatement */
David Sedlákae4b4512019-08-14 10:45:56 +0200393 uint8_t yin; /** flag for YIN source format, can be set to LYS_YIN */
Radek Krejci335332a2019-09-05 13:03:35 +0200394 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200395};
396
397/**
398 * @brief YANG feature-stmt
399 */
400struct lysp_feature {
401 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200402 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200403 const char *dsc; /**< description statement */
404 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200405 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200406 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
407};
408
409/**
410 * @brief YANG identity-stmt
411 */
412struct lysp_ident {
413 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200414 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
415 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200416 const char *dsc; /**< description statement */
417 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200418 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200419 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
420};
421
Michal Vasko71e64ca2018-09-07 16:30:29 +0200422/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200423 * @brief Covers restrictions: range, length, pattern, must
424 */
425struct lysp_restr {
426 const char *arg; /**< The restriction expression/value (mandatory);
427 in case of pattern restriction, the first byte has a special meaning:
428 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
429 const char *emsg; /**< error-message */
430 const char *eapptag; /**< error-app-tag value */
431 const char *dsc; /**< description */
432 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200433 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200434};
435
436/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200437 * @brief YANG revision-stmt
438 */
439struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200440 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200441 const char *dsc; /**< description statement */
442 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200443 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200444};
445
446/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200447 * @brief Enumeration/Bit value definition
448 */
449struct lysp_type_enum {
450 const char *name; /**< name (mandatory) */
451 const char *dsc; /**< description statement */
452 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200453 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200454 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200455 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200456 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
457 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200458};
459
460/**
461 * @brief YANG type-stmt
462 *
463 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
464 */
465struct lysp_type {
466 const char *name; /**< name of the type (mandatory) */
467 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
468 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200469 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
470 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
471 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Michal Vasko004d3152020-06-11 19:59:22 +0200472 struct lyxp_expr *path; /**< parsed path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200473 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200474 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
475 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200476
Radek Krejci2167ee12018-11-02 16:09:07 +0100477 struct lysc_type *compiled; /**< pointer to the compiled type */
478
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200479 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
480 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100481 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200482};
483
484/**
485 * @brief YANG typedef-stmt
486 */
487struct lysp_tpdf {
488 const char *name; /**< name of the newly defined type (mandatory) */
489 const char *units; /**< units of the newly defined type */
490 const char *dflt; /**< default value of the newly defined type */
491 const char *dsc; /**< description statement */
492 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200493 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200494 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100495 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200496};
497
498/**
499 * @brief YANG grouping-stmt
500 */
501struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100502 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
503 uint16_t nodetype; /**< LYS_GROUPING */
504 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200505 const char *name; /**< grouping name (mandatory) */
506 const char *dsc; /**< description statement */
507 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200508 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
509 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200510 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200511 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
512 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
513 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200514};
515
516/**
517 * @brief YANG when-stmt
518 */
519struct lysp_when {
520 const char *cond; /**< specified condition (mandatory) */
521 const char *dsc; /**< description statement */
522 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200523 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200524};
525
526/**
527 * @brief YANG refine-stmt
528 */
529struct lysp_refine {
530 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
531 const char *dsc; /**< description statement */
532 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200533 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200534 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200535 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200536 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200537 uint32_t min; /**< min-elements constraint */
538 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200539 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200540 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
541};
542
543/**
Michal Vasko82a83432019-11-14 12:33:04 +0100544 * @brief YANG uses-augment-stmt and augment-stmt (compatible with struct lysp_node )
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200545 */
546struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100547 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
548 uint16_t nodetype; /**< LYS_AUGMENT */
549 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Michal Vasko82a83432019-11-14 12:33:04 +0100550 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200551 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
552 const char *dsc; /**< description statement */
553 const char *ref; /**< reference statement */
554 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200555 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Michal Vasko82a83432019-11-14 12:33:04 +0100556 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200557 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
558 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200559};
560
561/**
562 * @defgroup deviatetypes Deviate types
563 * @{
564 */
565#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
566#define LYS_DEV_ADD 2 /**< deviate type add */
567#define LYS_DEV_DELETE 3 /**< deviate type delete */
568#define LYS_DEV_REPLACE 4 /**< deviate type replace */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200569/** @} deviatetypes */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200570
571/**
572 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
573 */
574struct lysp_deviate {
575 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
576 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200577 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200578};
579
580struct lysp_deviate_add {
581 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
582 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200583 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200584 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200585 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200586 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
587 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200588 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
589 uint32_t min; /**< min-elements constraint */
590 uint32_t max; /**< max-elements constraint, 0 means unbounded */
591};
592
593struct lysp_deviate_del {
594 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
595 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200596 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200597 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200598 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200599 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
600 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200601};
602
603struct lysp_deviate_rpl {
604 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
605 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200606 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200607 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200608 const char *units; /**< units of the values */
609 const char *dflt; /**< default value */
610 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
611 uint32_t min; /**< min-elements constraint */
612 uint32_t max; /**< max-elements constraint, 0 means unbounded */
613};
614
615struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200616 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200617 const char *dsc; /**< description statement */
618 const char *ref; /**< reference statement */
619 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200620 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200621};
622
Radek Krejci4f28eda2018-11-12 11:46:16 +0100623/**
624 * @defgroup spnodeflags Parsed schema nodes flags
625 * @ingroup snodeflags
626 *
627 * Various flags for parsed schema nodes.
628 *
629 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
630 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200631 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100632 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
633 * 5 - list 10 - input 15 - typedef 20 - deviate
634 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200635 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
636 * 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
637 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
638 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
639 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
640 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
641 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
642 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
643 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
644 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
645 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
646 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
647 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
648 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
649 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
650 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
651 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
652 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
653 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
654 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
655 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
656 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
657 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
658 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
659 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
660 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
661 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
662 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
663 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
664 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
665 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
666 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
667 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
668 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
669 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
670 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
671 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
672 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
673 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200674 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
David Sedlákae4b4512019-08-14 10:45:56 +0200675 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejcid3ca0632019-04-16 16:54:54 +0200676 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejcif56e2a42019-09-09 14:15:25 +0200677 * 12 LYS_YIN_ARGUMENT | | | | | | | | | | | | | | | | | | | | | | |x|
678 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100679 *
680 */
681
682/**
683 * @defgroup scnodeflags Compiled schema nodes flags
684 * @ingroup snodeflags
685 *
686 * Various flags for compiled schema nodes.
687 *
Radek Krejci61e042e2019-09-10 15:53:09 +0200688 * 1 - container 6 - anydata/anyxml 11 - identity
689 * 2 - choice 7 - case 12 - extension
690 * 3 - leaf 8 - notification 13 - bitenum
Michal Vasko03ff5a72019-09-11 13:49:33 +0200691 * 4 - leaflist 9 - rpc/action 14 - when
Michal Vaskoecd62de2019-11-13 12:35:11 +0100692 * 5 - list 10 - feature
Radek Krejci4f28eda2018-11-12 11:46:16 +0100693 *
Michal Vaskoecd62de2019-11-13 12:35:11 +0100694 * 1 1 1 1 1
695 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
696 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
697 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | |
698 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
699 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | |
700 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
701 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x|x|x|x| |x|
702 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
703 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x|x|x|x| |x|
704 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
705 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x|x|x|x| |x|
706 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
707 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
708 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
709 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
710 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | |
711 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
712 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
713 * LYS_PRESENCE |x| | | | | | | | | | | | | |
714 * LYS_UNIQUE | | |x| | | | | | | | | | | |
715 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
716 * 9 LYS_KEY | | |x| | | | | | | | | | | |
717 * LYS_FENABLED | | | | | | | | | |x| | | | |
718 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
719 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
720 * LYS_ISENUM | | | | | | | | | | | | |x| |
721 * LYS_KEYLESS | | | | |x| | | | | | | | | |
722 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
723 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
724 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
725 * 12 LYS_SET_CONFIG |x|x|x|x|x|x| | | | | | | | |
726 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100727 *
728 */
729
730/**
731 * @defgroup snodeflags Schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100732 * @{
733 */
Michal Vasko1bf09392020-03-27 12:38:10 +0100734#define LYS_CONFIG_W 0x01 /**< config true; also set for input children nodes */
735#define LYS_CONFIG_R 0x02 /**< config false; also set for output and notification children nodes */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200736#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100737#define LYS_STATUS_CURR 0x04 /**< status current; */
738#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
739#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
740#define LYS_STATUS_MASK 0x1C /**< mask for status value */
741#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100742 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
743 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
744 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
745 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100746#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
747 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
748 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100749#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100750#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, applicable only to ::lysc_node_container */
751#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
752#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 +0200753#define LYS_KEYLESS 0x200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100754#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysc_feature */
Radek Krejcife909632019-02-12 15:34:42 +0100755#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 +0100756 ::lysc_node_list/::lysp_node_list */
757#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
758 ::lysc_node_list/::lysp_node_list */
759#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
760#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
761#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
762#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200763#define LYS_USED_GRP 0x400 /**< internal flag for validating not-instantiated groupings
764 (resp. do not validate again the instantiated groupings). */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100765#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100766#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200767#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100768
769#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
770#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
771#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
772#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
773#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
774#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
775#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
776#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
777#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
778#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100779#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 +0100780 cases of choice. This information is important for refines, since it is prohibited to make leafs
781 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100782 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
783 between own default or the default values taken from the type. */
784#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 +0100785#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 +0100786
Radek Krejcif56e2a42019-09-09 14:15:25 +0200787#define LYS_SINGLEQUOTED 0x100 /**< flag for single-quoted argument of an extension instance's substatement, only when the source is YANG */
788#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 +0200789
Radek Krejcif56e2a42019-09-09 14:15:25 +0200790#define LYS_YIN_ATTR 0x400 /**< flag to identify YIN attribute parsed as extension's substatement, only when the source is YIN */
791#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 +0200792
Radek Krejci693262f2019-04-29 15:23:20 +0200793#define LYS_ISENUM 0x200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
794
Radek Krejcife909632019-02-12 15:34:42 +0100795#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200796/** @} snodeflags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200797
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200798/**
799 * @brief Generic YANG data node
800 */
801struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100802 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200803 uint16_t nodetype; /**< type of the node (mandatory) */
804 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100805 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200806 const char *name; /**< node name (mandatory) */
807 const char *dsc; /**< description statement */
808 const char *ref; /**< reference statement */
809 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200810 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200811 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200812};
813
814/**
815 * @brief Extension structure of the lysp_node for YANG container
816 */
817struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100818 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200819 uint16_t nodetype; /**< LYS_CONTAINER */
820 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
821 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
822 const char *name; /**< node name (mandatory) */
823 const char *dsc; /**< description statement */
824 const char *ref; /**< reference statement */
825 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200826 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200827 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200828
829 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200830 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200831 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200832 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
833 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200834 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200835 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
836 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200837};
838
839struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100840 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200841 uint16_t nodetype; /**< LYS_LEAF */
842 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
843 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
844 const char *name; /**< node name (mandatory) */
845 const char *dsc; /**< description statement */
846 const char *ref; /**< reference statement */
847 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200848 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200849 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200850
851 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200852 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200853 struct lysp_type type; /**< type of the leaf node (mandatory) */
854 const char *units; /**< units of the leaf's type */
855 const char *dflt; /**< default value */
856};
857
858struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100859 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200860 uint16_t nodetype; /**< LYS_LEAFLIST */
861 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
862 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
863 const char *name; /**< node name (mandatory) */
864 const char *dsc; /**< description statement */
865 const char *ref; /**< reference statement */
866 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200867 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200868 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200869
870 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200871 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200872 struct lysp_type type; /**< type of the leaf node (mandatory) */
873 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200874 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200875 uint32_t min; /**< min-elements constraint */
876 uint32_t max; /**< max-elements constraint, 0 means unbounded */
877};
878
879struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100880 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200881 uint16_t nodetype; /**< LYS_LIST */
882 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
883 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
884 const char *name; /**< node name (mandatory) */
885 const char *dsc; /**< description statement */
886 const char *ref; /**< reference statement */
887 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200888 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200889 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200890
891 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200892 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200893 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200894 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
895 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200896 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200897 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
898 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200899 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200900 uint32_t min; /**< min-elements constraint */
901 uint32_t max; /**< max-elements constraint, 0 means unbounded */
902};
903
904struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100905 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200906 uint16_t nodetype; /**< LYS_CHOICE */
907 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
908 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
909 const char *name; /**< node name (mandatory) */
910 const char *dsc; /**< description statement */
911 const char *ref; /**< reference statement */
912 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200913 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200914 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200915
916 /* choice */
917 struct lysp_node *child; /**< list of data nodes (linked list) */
918 const char* dflt; /**< default case */
919};
920
921struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100922 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200923 uint16_t nodetype; /**< LYS_CASE */
924 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
925 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
926 const char *name; /**< node name (mandatory) */
927 const char *dsc; /**< description statement */
928 const char *ref; /**< reference statement */
929 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200930 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200931 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200932
933 /* case */
934 struct lysp_node *child; /**< list of data nodes (linked list) */
935};
936
937struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100938 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200939 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
940 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
941 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
942 const char *name; /**< node name (mandatory) */
943 const char *dsc; /**< description statement */
944 const char *ref; /**< reference statement */
945 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200946 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200947 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200948
949 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200950 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200951};
952
953struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100954 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200955 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200956 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
957 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
958 const char *name; /**< grouping name reference (mandatory) */
959 const char *dsc; /**< description statement */
960 const char *ref; /**< reference statement */
961 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200962 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200963 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200964
965 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200966 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
967 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200968};
969
970/**
971 * @brief YANG input-stmt and output-stmt
972 */
973struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100974 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
975 uint16_t nodetype; /**< LYS_INOUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200976 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
977 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
978 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200979 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200980 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200981};
982
983/**
984 * @brief YANG rpc-stmt and action-stmt
985 */
986struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100987 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko1bf09392020-03-27 12:38:10 +0100988 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100989 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200990 const char *name; /**< grouping name reference (mandatory) */
991 const char *dsc; /**< description statement */
992 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200993 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200994 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
995 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100996 struct lysp_action_inout input; /**< RPC's/Action's input */
997 struct lysp_action_inout output; /**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200998 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200999};
1000
1001/**
1002 * @brief YANG notification-stmt
1003 */
1004struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001005 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1006 uint16_t nodetype; /**< LYS_NOTIF */
1007 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001008 const char *name; /**< grouping name reference (mandatory) */
1009 const char *dsc; /**< description statement */
1010 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +02001011 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001012 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1013 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1014 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001015 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001016 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001017};
1018
1019/**
Radek Krejcif0fceb62018-09-05 14:58:45 +02001020 * @brief supported YANG schema version values
1021 */
1022typedef enum LYS_VERSION {
1023 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
1024 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
1025 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
1026} LYS_VERSION;
1027
1028/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001029 * @brief Printable YANG schema tree structure representing YANG module.
1030 *
1031 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
1032 */
1033struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001034 struct lys_module *mod; /**< covering module structure */
1035
Radek Krejcib7db73a2018-10-24 14:18:40 +02001036 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1037 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001038 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1039 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001040 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1041 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1042 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1043 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1044 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001045 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001046 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1047 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1048 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1049 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
1050 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001051
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001052 uint8_t parsing:1; /**< flag for circular check */
1053};
1054
1055struct lysp_submodule {
1056 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
1057
1058 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1059 in the list is always the last (newest) revision of the module */
1060 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1061 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
1062 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1063 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1064 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1065 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1066 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
1067 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
1068 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1069 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1070 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1071 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
1072 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1073
1074 uint8_t parsing:1; /**< flag for circular check */
1075
Radek Krejci086c7132018-10-26 15:29:04 +02001076 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
1077 1 - the latest revision in searchdirs was not searched yet and this is the
1078 latest revision in the current context
1079 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001080 const char *name; /**< name of the module (mandatory) */
1081 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1082 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
1083 const char *org; /**< party/company responsible for the module */
1084 const char *contact; /**< contact information for the module */
1085 const char *dsc; /**< description of the module */
1086 const char *ref; /**< cross-reference for the module */
Radek Krejci086c7132018-10-26 15:29:04 +02001087 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001088};
1089
1090/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +02001091 * @brief Free the printable YANG schema tree structure.
1092 *
1093 * @param[in] module Printable YANG schema tree structure to free.
1094 */
1095void lysp_module_free(struct lysp_module *module);
1096
1097/**
Radek Krejci535ea9f2020-05-29 16:01:05 +02001098 * @defgroup scflags Schema compile flags
1099 * @ingroup schematree
1100 *
1101 * @{
1102 */
1103#define LYSC_OPT_RPC_INPUT LYS_CONFIG_W /**< Internal option when compiling schema tree of RPC/action input */
1104#define LYSC_OPT_RPC_OUTPUT LYS_CONFIG_R /**< Internal option when compiling schema tree of RPC/action output */
1105#define LYSC_OPT_RPC_MASK LYS_CONFIG_MASK /**< mask for the internal RPC options */
1106#define LYSC_OPT_FREE_SP 0x04 /**< Free the input printable schema */
1107#define LYSC_OPT_INTERNAL 0x08 /**< Internal compilation caused by dependency */
1108#define LYSC_OPT_NOTIFICATION 0x10 /**< Internal option when compiling schema tree of Notification */
1109
1110#define LYSC_OPT_GROUPING 0x20 /** Compiling (validation) of a non-instantiated grouping.
1111 In this case not all the restrictions are checked since they can be valid only
1112 in the real placement of the grouping. TODO - what specifically is not done */
1113/** @} scflags */
1114
1115/**
Radek Krejci0e59c312019-08-15 15:34:15 +02001116 * @brief Compiled YANG extension-stmt
1117 */
1118struct lysc_ext {
1119 const char *name; /**< extension name */
1120 const char *argument; /**< argument name, NULL if not specified */
Radek Krejci0e59c312019-08-15 15:34:15 +02001121 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1122 struct lyext_plugin *plugin; /**< Plugin implementing the specific extension */
Radek Krejci0935f412019-08-20 16:15:18 +02001123 struct lys_module *module; /**< module structure */
Michal Vasko6f4cbb62020-02-28 11:15:47 +01001124 uint32_t refcount; /**< reference counter since extension definition is shared among all its instances */
Radek Krejci0e59c312019-08-15 15:34:15 +02001125 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
1126};
1127
1128/**
Radek Krejcice8c1592018-10-29 15:35:51 +01001129 * @brief YANG extension instance
1130 */
1131struct lysc_ext_instance {
Radek Krejciad5963b2019-09-06 16:03:05 +02001132 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
1133 this identifies the index of the substatement for this extension instance */
Radek Krejci28681fa2019-09-06 13:08:45 +02001134 struct lys_module *module; /**< module where the extension instantiated is defined */
Radek Krejciad5963b2019-09-06 16:03:05 +02001135 struct lysc_ext *def; /**< pointer to the extension definition */
Radek Krejcice8c1592018-10-29 15:35:51 +01001136 void *parent; /**< pointer to the parent element holding the extension instance(s), use
1137 ::lysc_ext_instance#parent_type to access the schema element */
1138 const char *argument; /**< optional value of the extension's argument */
1139 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +01001140 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001141 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0e59c312019-08-15 15:34:15 +02001142 void *data; /**< private plugins's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +01001143};
1144
1145/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001146 * @brief Compiled YANG if-feature-stmt
1147 */
1148struct lysc_iffeature {
1149 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
1150 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
1151};
1152
1153/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001154 * @brief YANG import-stmt
1155 */
1156struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +01001157 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +02001158 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001159 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +02001160};
1161
1162/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001163 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001164 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001165struct lysc_when {
Radek Krejcia0f704a2019-09-09 16:12:23 +02001166 struct lys_module *module; /**< module where the must was defined */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001167 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko175012e2019-11-06 15:49:14 +01001168 struct lysc_node *context; /**< context node for evaluating the expression, NULL if the context is root node */
Radek Krejcic8b31002019-01-08 10:24:45 +01001169 const char *dsc; /**< description */
1170 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001171 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001172 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Michal Vaskoecd62de2019-11-13 12:35:11 +01001173 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS is allowed */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001174};
1175
1176/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001177 * @brief YANG identity-stmt
1178 */
1179struct lysc_ident {
1180 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +01001181 const char *dsc; /**< description */
1182 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001183 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001184 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
1185 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001186 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001187 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1188};
1189
1190/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001191 * @brief YANG feature-stmt
1192 */
1193struct lysc_feature {
1194 const char *name; /**< feature name (mandatory) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001195 const char *dsc; /**< description */
1196 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001197 struct lys_module *module; /**< module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001198 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 +01001199 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001200 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001201 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
1202 #LYS_FENABLED values allowed */
1203};
1204
Radek Krejci151a5b72018-10-19 14:21:44 +02001205/**
1206 * @defgroup ifftokens if-feature expression tokens
1207 * Tokens of if-feature expression used in ::lysc_iffeature#expr
1208 *
1209 * @{
1210 */
1211#define LYS_IFF_NOT 0x00 /**< operand "not" */
1212#define LYS_IFF_AND 0x01 /**< operand "and" */
1213#define LYS_IFF_OR 0x02 /**< operand "or" */
1214#define LYS_IFF_F 0x03 /**< feature */
Radek Krejci2ff0d572020-05-21 15:27:28 +02001215/** @} ifftokens */
Radek Krejci151a5b72018-10-19 14:21:44 +02001216
1217/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001218 * @brief Compiled YANG revision statement
1219 */
1220struct lysc_revision {
1221 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1222 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1223};
1224
Radek Krejci2167ee12018-11-02 16:09:07 +01001225struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001226 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001227 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001228 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1229 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001230 };
Radek Krejci693262f2019-04-29 15:23:20 +02001231 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001232 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1233 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001234 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001235 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001236 const char *dsc; /**< description */
1237 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001238 const char *emsg; /**< error-message */
1239 const char *eapptag; /**< error-app-tag value */
1240 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1241};
1242
1243struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001244 const char *expr; /**< original, not compiled, regular expression */
1245 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001246 const char *dsc; /**< description */
1247 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001248 const char *emsg; /**< error-message */
1249 const char *eapptag; /**< error-app-tag value */
1250 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4586a022018-11-13 11:29:26 +01001251 uint32_t inverted:1; /**< invert-match flag */
1252 uint32_t refcount:31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001253};
1254
1255struct lysc_must {
1256 struct lys_module *module; /**< module where the must was defined */
1257 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001258 const char *dsc; /**< description */
1259 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001260 const char *emsg; /**< error-message */
1261 const char *eapptag; /**< error-app-tag value */
1262 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1263};
1264
1265struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001266 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001267 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001268 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 +02001269 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 +01001270 LY_DATA_TYPE basetype; /**< Base type of the type */
1271 uint32_t refcount; /**< reference counter for type sharing */
1272};
1273
1274struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001275 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001276 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001277 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 +02001278 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 +01001279 LY_DATA_TYPE basetype; /**< Base type of the type */
1280 uint32_t refcount; /**< reference counter for type sharing */
1281 struct lysc_range *range; /**< Optional range limitation */
1282};
1283
1284struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001285 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001286 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001287 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 +02001288 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 +01001289 LY_DATA_TYPE basetype; /**< Base type of the type */
1290 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001291 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001292 struct lysc_range *range; /**< Optional range limitation */
1293};
1294
1295struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001296 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001297 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001298 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 +02001299 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 +01001300 LY_DATA_TYPE basetype; /**< Base type of the type */
1301 uint32_t refcount; /**< reference counter for type sharing */
1302 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001303 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001304};
1305
Radek Krejci693262f2019-04-29 15:23:20 +02001306struct lysc_type_bitenum_item {
1307 const char *name; /**< enumeration identifier */
1308 const char *dsc; /**< description */
1309 const char *ref; /**< reference */
1310 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1311 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1312 union {
1313 int32_t value; /**< integer value associated with the enumeration */
1314 uint32_t position; /**< non-negative integer value associated with the bit */
1315 };
1316 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1317 values are allowed */
1318};
1319
Radek Krejci2167ee12018-11-02 16:09:07 +01001320struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001321 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001322 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001323 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 +02001324 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 +01001325 LY_DATA_TYPE basetype; /**< Base type of the type */
1326 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001327 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1328};
1329
1330struct lysc_type_bits {
1331 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1332 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001333 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 +02001334 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 +02001335 LY_DATA_TYPE basetype; /**< Base type of the type */
1336 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001337 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1338 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001339};
1340
1341struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001342 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001343 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001344 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 +02001345 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 +01001346 LY_DATA_TYPE basetype; /**< Base type of the type */
1347 uint32_t refcount; /**< reference counter for type sharing */
Michal Vasko004d3152020-06-11 19:59:22 +02001348 struct lyxp_expr *path; /**< parsed target path, compiled path cannot be stored because of type sharing */
Radek Krejci96a0bfd2018-11-22 15:25:06 +01001349 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 +01001350 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001351 uint8_t require_instance; /**< require-instance flag */
1352};
1353
1354struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001355 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001356 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001357 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 +02001358 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 +01001359 LY_DATA_TYPE basetype; /**< Base type of the type */
1360 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001361 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001362 mandatory (at least 1 item) */
1363};
1364
1365struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001366 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001367 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001368 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 +02001369 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 +01001370 LY_DATA_TYPE basetype; /**< Base type of the type */
1371 uint32_t refcount; /**< reference counter for type sharing */
1372 uint8_t require_instance; /**< require-instance flag */
1373};
1374
Radek Krejci2167ee12018-11-02 16:09:07 +01001375struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001376 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001377 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001378 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 +02001379 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 +01001380 LY_DATA_TYPE basetype; /**< Base type of the type */
1381 uint32_t refcount; /**< reference counter for type sharing */
1382 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1383};
1384
1385struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001386 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001387 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001388 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 +02001389 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 +01001390 LY_DATA_TYPE basetype; /**< Base type of the type */
1391 uint32_t refcount; /**< reference counter for type sharing */
1392 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001393};
1394
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001395struct lysc_action_inout {
1396 struct lysc_node *data; /**< first child node (linked list) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001397 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1398};
1399
Michal Vasko60ea6352020-06-29 13:39:39 +02001400/**
1401 * @brief Maximum number of hashes stored in a schema node.
1402 */
1403#define LYS_NODE_HASH_COUNT 4
1404
Radek Krejci056d0a82018-12-06 16:57:25 +01001405struct lysc_action {
Michal Vasko1bf09392020-03-27 12:38:10 +01001406 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci056d0a82018-12-06 16:57:25 +01001407 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001408 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejci95710c92019-02-11 15:49:55 +01001409 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001410 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. */
1411 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1412
Radek Krejcifc11bd72019-04-11 16:00:05 +02001413 struct lysc_ext_instance *input_exts; /**< list of the extension instances of input ([sized array](@ref sizedarrays)) */
1414 struct lysc_ext_instance *output_exts; /**< list of the extension instances of outpu ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001415
Radek Krejci056d0a82018-12-06 16:57:25 +01001416 const char *name; /**< action/RPC name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001417 const char *dsc; /**< description */
1418 const char *ref; /**< reference */
1419
Radek Krejcifc11bd72019-04-11 16:00:05 +02001420 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1421 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1422
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001423 struct lysc_action_inout input; /**< RPC's/action's input */
1424 struct lysc_action_inout output; /**< RPC's/action's output */
1425
Radek Krejci056d0a82018-12-06 16:57:25 +01001426};
1427
1428struct lysc_notif {
1429 uint16_t nodetype; /**< LYS_NOTIF */
1430 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001431 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejci95710c92019-02-11 15:49:55 +01001432 struct lys_module *module; /**< module structure */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001433 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 +01001434 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1435
Radek Krejcifc11bd72019-04-11 16:00:05 +02001436 struct lysc_node *data; /**< first child node (linked list) */
1437 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1438
Radek Krejci056d0a82018-12-06 16:57:25 +01001439 const char *name; /**< Notification name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001440 const char *dsc; /**< description */
1441 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001442
1443 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1444 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001445};
1446
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001447/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001448 * @brief Compiled YANG data node
1449 */
1450struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001451 uint16_t nodetype; /**< type of the node (mandatory) */
1452 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001453 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001454 struct lys_module *module; /**< module structure */
Michal Vaskocc048b22020-03-27 15:52:38 +01001455 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or
1456 in case of implicit case node. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001457 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1458 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1459 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1460 never NULL. If there is no sibling node, pointer points to the node
1461 itself. In case of the first node, this pointer points to the last
1462 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001463 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001464 const char *dsc; /**< description */
1465 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001466 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001467 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001468 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001469};
1470
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001471struct lysc_node_container {
1472 uint16_t nodetype; /**< LYS_CONTAINER */
1473 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001474 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001475 struct lys_module *module; /**< module structure */
1476 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. */
1477 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1478 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1479 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1480 never NULL. If there is no sibling node, pointer points to the node
1481 itself. In case of the first node, this pointer points to the last
1482 node in the list. */
1483 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001484 const char *dsc; /**< description */
1485 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001486 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001487 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001488 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001489
1490 struct lysc_node *child; /**< first child node (linked list) */
1491 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1492 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1493 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001494};
1495
Radek Krejcia3045382018-11-22 14:30:31 +01001496struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001497 uint16_t nodetype; /**< LYS_CASE */
1498 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001499 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
Radek Krejci056d0a82018-12-06 16:57:25 +01001500 struct lys_module *module; /**< module structure */
1501 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. */
1502 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1503 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1504 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1505 never NULL. If there is no sibling node, pointer points to the node
1506 itself. In case of the first node, this pointer points to the last
1507 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001508 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001509 const char *dsc; /**< description */
1510 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001511 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001512 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001513 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001514
Radek Krejcia3045382018-11-22 14:30:31 +01001515 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 +01001516 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001517};
1518
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001519struct lysc_node_choice {
1520 uint16_t nodetype; /**< LYS_CHOICE */
1521 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001522 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001523 struct lys_module *module; /**< module structure */
1524 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. */
1525 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1526 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1527 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1528 never NULL. If there is no sibling node, pointer points to the node
1529 itself. In case of the first node, this pointer points to the last
1530 node in the list. */
1531 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001532 const char *dsc; /**< description */
1533 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001534 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001535 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001536 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001537
Radek Krejcia9026eb2018-12-12 16:04:47 +01001538 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1539 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1540 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001541 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001542};
1543
1544struct lysc_node_leaf {
1545 uint16_t nodetype; /**< LYS_LEAF */
1546 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001547 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001548 struct lys_module *module; /**< module structure */
1549 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. */
1550 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1551 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1552 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1553 never NULL. If there is no sibling node, pointer points to the node
1554 itself. In case of the first node, this pointer points to the last
1555 node in the list. */
1556 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001557 const char *dsc; /**< description */
1558 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001559 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001560 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001561 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001562
1563 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1564 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001565
Radek Krejci4f28eda2018-11-12 11:46:16 +01001566 const char *units; /**< units of the leaf's type */
Radek Krejcia1911222019-07-22 17:24:50 +02001567 struct lyd_value *dflt; /**< default value */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001568 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 +01001569};
1570
1571struct lysc_node_leaflist {
1572 uint16_t nodetype; /**< LYS_LEAFLIST */
1573 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001574 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001575 struct lys_module *module; /**< module structure */
1576 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. */
1577 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1578 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1579 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1580 never NULL. If there is no sibling node, pointer points to the node
1581 itself. In case of the first node, this pointer points to the last
1582 node in the list. */
1583 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001584 const char *dsc; /**< description */
1585 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001586 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001587 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001588 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001589
1590 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1591 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1592
Radek Krejci0e5d8382018-11-28 16:37:53 +01001593 const char *units; /**< units of the leaf's type */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001594 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values */
1595 struct lys_module **dflts_mods; /**< list ([sized array](@ref sizedarrays)) of modules where the lysc_node_leaflist::dflts values were defined
1596 (needed to correctly map prefixes). */
Radek Krejci0e5d8382018-11-28 16:37:53 +01001597 uint32_t min; /**< min-elements constraint */
1598 uint32_t max; /**< max-elements constraint */
1599
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001600};
1601
1602struct lysc_node_list {
1603 uint16_t nodetype; /**< LYS_LIST */
1604 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001605 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001606 struct lys_module *module; /**< module structure */
1607 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. */
1608 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1609 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1610 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1611 never NULL. If there is no sibling node, pointer points to the node
1612 itself. In case of the first node, this pointer points to the last
1613 node in the list. */
1614 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001615 const char *dsc; /**< description */
1616 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001617 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001618 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001619 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001620
1621 struct lysc_node *child; /**< first child node (linked list) */
1622 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1623 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1624 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1625
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001626 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1627 uint32_t min; /**< min-elements constraint */
1628 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001629};
1630
1631struct lysc_node_anydata {
1632 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1633 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001634 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001635 struct lys_module *module; /**< module structure */
1636 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. */
1637 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1638 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1639 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1640 never NULL. If there is no sibling node, pointer points to the node
1641 itself. In case of the first node, this pointer points to the last
1642 node in the list. */
1643 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001644 const char *dsc; /**< description */
1645 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001646 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001647 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001648 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9800fb82018-12-13 14:26:23 +01001649
1650 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001651};
1652
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001653/**
1654 * @brief Compiled YANG schema tree structure representing YANG module.
1655 *
1656 * Semantically validated YANG schema tree for data tree parsing.
1657 * Contains only the necessary information for the data validation.
1658 */
1659struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001660 struct lys_module *mod; /**< covering module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001661 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001662
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001663 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001664 struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1665 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1666 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1667 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001668 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko57c10cd2020-05-27 15:57:11 +02001669 struct lys_module **deviated_by; /**< List of modules that deviate this module ([sized array](@ref sizedarrays)) */
Michal Vaskoa3af5982020-06-29 11:51:37 +02001670 struct lys_module **augmented_by;/**< List of modules that augment this module ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001671};
1672
1673/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001674 * @brief Get the groupings sized array of the given (parsed) schema node.
1675 * Decides the node's type and in case it has a groupings array, returns it.
1676 * @param[in] node Node to examine.
1677 * @return The node's groupings sized array if any, NULL otherwise.
1678 */
1679const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1680
1681/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001682 * @brief Get the typedefs sized array of the given (parsed) schema node.
1683 * Decides the node's type and in case it has a typedefs array, returns it.
1684 * @param[in] node Node to examine.
1685 * @return The node's typedefs sized array if any, NULL otherwise.
1686 */
1687const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1688
1689/**
1690 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1691 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1692 * @param[in] node Node to examine.
1693 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1694 */
1695const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1696
1697/**
1698 * @brief Get the Notifications sized array of the given (parsed) schema node.
1699 * Decides the node's type and in case it has a Notifications array, returns it.
1700 * @param[in] node Node to examine.
1701 * @return The node's Notifications sized array if any, NULL otherwise.
1702 */
1703const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1704
1705/**
1706 * @brief Get the children linked list of the given (parsed) schema node.
1707 * Decides the node's type and in case it has a children list, returns it.
1708 * @param[in] node Node to examine.
1709 * @return The node's children linked list if any, NULL otherwise.
1710 */
1711const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1712
1713/**
1714 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1715 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1716 * @param[in] node Node to examine.
1717 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1718 */
1719const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1720
1721/**
1722 * @brief Get the Notifications sized array of the given (compiled) schema node.
1723 * Decides the node's type and in case it has a Notifications array, returns it.
1724 * @param[in] node Node to examine.
1725 * @return The node's Notifications sized array if any, NULL otherwise.
1726 */
1727const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1728
1729/**
1730 * @brief Get the children linked list of the given (compiled) schema node.
1731 * Decides the node's type and in case it has a children list, returns it.
1732 * @param[in] node Node to examine.
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001733 * @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 +01001734 * @return The node's children linked list if any, NULL otherwise.
1735 */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001736const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Radek Krejci056d0a82018-12-06 16:57:25 +01001737
1738/**
Michal Vaskod975f862020-06-23 13:29:28 +02001739 * @brief Examine whether a node is user-ordered list or leaf-list.
1740 *
1741 * @param[in] node Node to examine.
1742 * @return non-zero if it is,
1743 * @return 0 if not.
1744 */
1745int lysc_is_userordered(const struct lysc_node *schema);
1746
1747/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001748 * @brief Get how the if-feature statement currently evaluates.
1749 *
1750 * @param[in] iff Compiled if-feature statement to evaluate.
Michal Vasko28d78432020-05-26 13:10:53 +02001751 * @return LY_SUCCESS if the statement evaluates to true,
1752 * @return LY_ENOT if it evaluates to false,
1753 * @return LY_ERR on error.
Radek Krejci151a5b72018-10-19 14:21:44 +02001754 */
Michal Vasko28d78432020-05-26 13:10:53 +02001755LY_ERR lysc_iffeature_value(const struct lysc_iffeature *iff);
Radek Krejci151a5b72018-10-19 14:21:44 +02001756
1757/**
1758 * @brief Get the current status of the provided feature.
1759 *
1760 * @param[in] feature Compiled feature statement to examine.
Michal Vasko28d78432020-05-26 13:10:53 +02001761 * @return LY_SUCCESS if feature is enabled,
1762 * @return LY_ENOT if feature is disabled,
1763 * @return LY_ERR in case of error (invalid argument)
Radek Krejci151a5b72018-10-19 14:21:44 +02001764 */
Michal Vasko28d78432020-05-26 13:10:53 +02001765LY_ERR lysc_feature_value(const struct lysc_feature *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001766
1767/**
Michal Vasko519fd602020-05-26 12:17:39 +02001768 * @brief Get all the schema nodes (atoms) that are required for \p xpath to be evaluated.
1769 *
1770 * @param[in] ctx_node XPath schema context node.
1771 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LYD_JSON format is expected.
1772 * @param[in] options Whether to apply some node access restrictions, one of the options should always be used.
1773 * If none is set, ::LYXP_SCNODE is used.
1774 * @param[out] set Set of found atoms (schema nodes).
1775 * @return LY_SUCCESS on success, @p set is returned.
1776 * @return LY_ERR value if an error occurred.
1777 */
1778LY_ERR lys_atomize_xpath(const struct lysc_node *ctx_node, const char *xpath, int options, struct ly_set **set);
1779
1780#define LYXP_SCNODE 0x02 /**< No special tree access modifiers. */
1781#define LYXP_SCNODE_SCHEMA 0x04 /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */
1782#define LYXP_SCNODE_OUTPUT 0x08 /**< Search RPC/action output nodes instead of input ones. */
1783
1784/**
Michal Vasko03ff5a72019-09-11 13:49:33 +02001785 * @brief Types of the different schema paths.
1786 */
1787typedef enum {
1788 LYSC_PATH_LOG /**< Descriptive path format used in log messages */
1789} LYSC_PATH_TYPE;
1790
1791/**
Radek Krejci327de162019-06-14 12:52:07 +02001792 * @brief Generate path of the given node in the requested format.
1793 *
1794 * @param[in] node Schema path of this node will be generated.
1795 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001796 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
1797 * If NULL, memory for the complete path is allocated.
1798 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02001799 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001800 * 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 +02001801 */
Michal Vasko03ff5a72019-09-11 13:49:33 +02001802char *lysc_path(const struct lysc_node *node, LYSC_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02001803
1804/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001805 * @brief Available YANG schema tree structures representing YANG module.
1806 */
1807struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001808 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
1809 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01001810 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001811 const char *ns; /**< namespace of the module (module - mandatory) */
1812 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
1813 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1814 const char *org; /**< party/company responsible for the module */
1815 const char *contact; /**< contact information for the module */
1816 const char *dsc; /**< description of the module */
1817 const char *ref; /**< cross-reference for the module */
1818
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001819 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01001820 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
1821 Available only for implemented modules. */
Michal Vasko33ff9422020-07-03 09:50:39 +02001822 struct lysc_feature *dis_features;/**< List of pre-compiled features in a non implemented module ([sized array](@ref sizedarrays)).
Radek Krejci0af46292019-01-11 16:02:31 +01001823 These features are always disabled and cannot be enabled until the module
Michal Vasko33ff9422020-07-03 09:50:39 +02001824 is implemented. The features are present in this form to allow their linkage
Radek Krejci0af46292019-01-11 16:02:31 +01001825 from if-feature statements of the compiled schemas and their proper use in case
1826 the module became implemented in future (no matter if implicitly via augment/deviate
1827 or explicitly via ly_ctx_module_implement()). */
Michal Vasko33ff9422020-07-03 09:50:39 +02001828 struct lysc_ident *dis_identities;/**< List of pre-compiled identities in a non-implemented module ([sized array](@ref sizedarrays))
1829 These identities cannot be instantiated in data (in identityrefs) until
1830 the module is implemented but can be linked by identities in implemented
1831 modules. */
Radek Krejci95710c92019-02-11 15:49:55 +01001832 uint8_t implemented; /**< flag if the module is implemented, not just imported. The module is implemented if
1833 the flag has non-zero value. Specific values are used internally:
1834 1 - implemented module
1835 2 - recently implemented module by dependency, it can be reverted in rollback procedure */
1836 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001837 1 - the latest revision in searchdirs was not searched yet and this is the
1838 latest revision in the current context
1839 2 - searchdirs were searched and this is the latest available revision */
1840 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001841};
1842
Radek Krejci151a5b72018-10-19 14:21:44 +02001843/**
1844 * @brief Enable specified feature in the module
1845 *
1846 * By default, when the module is loaded by libyang parser, all features are disabled.
1847 *
Radek Krejcica3db002018-11-01 10:31:01 +01001848 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
1849 * enabling all features on the following feature set will fail since it is not possible to enable both features
1850 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
1851 * is untouched.
1852 *
1853 * feature f1;
1854 * feature f2 { if-feature 'not f1';}
1855 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001856 * @param[in] module Module where the feature will be enabled.
1857 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
1858 * @return LY_ERR value.
1859 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001860LY_ERR lys_feature_enable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001861
1862/**
1863 * @brief Disable specified feature in the module
1864 *
1865 * By default, when the module is loaded by libyang parser, all features are disabled.
1866 *
1867 * @param[in] module Module where the feature will be disabled.
1868 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
1869 * @return LY_ERR value
1870 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001871LY_ERR lys_feature_disable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001872
1873/**
1874 * @brief Get the current status of the specified feature in the module.
1875 *
1876 * @param[in] module Module where the feature is defined.
1877 * @param[in] feature Name of the feature to inspect.
1878 * @return
1879 * - 1 if feature is enabled,
1880 * - 0 if feature is disabled,
1881 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
1882 */
1883int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001884
1885/**
Radek Krejcia3045382018-11-22 14:30:31 +01001886 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
1887 * be from an augment.
1888 *
1889 * lys_getnext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
1890 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
1891 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
1892 * \p parent and \p module parameters.
1893 *
1894 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
1895 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
1896 * all the schema nodes are iteratively returned.
1897 *
1898 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
1899 * @param[in] parent Parent of the subtree where the function starts processing.
1900 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
1901 * module must be specified.
1902 * @param[in] options [ORed options](@ref sgetnextflags).
1903 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
1904 */
1905const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
1906 const struct lysc_module *module, int options);
1907
1908/**
1909 * @defgroup sgetnextflags lys_getnext() flags
Radek Krejcia3045382018-11-22 14:30:31 +01001910 * @{
1911 */
1912#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 +01001913#define LYS_GETNEXT_NOCHOICE 0x02 /**< lys_getnext() option to ignore (kind of conditional) nodes within choice node */
Radek Krejci056d0a82018-12-06 16:57:25 +01001914#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 +01001915#define LYS_GETNEXT_INTONPCONT 0x40 /**< lys_getnext() option to look into non-presence container, instead of returning container itself */
1916#define LYS_GETNEXT_NOSTATECHECK 0x100 /**< lys_getnext() option to skip checking module validity (import-only, disabled) and
1917 relevant if-feature conditions state */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001918#define LYS_GETNEXT_OUTPUT 0x200 /**< lys_getnext() option to provide RPC's/action's output schema nodes instead of input schema nodes
1919 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01001920/** @} sgetnextflags */
1921
1922/**
1923 * @brief Get child node according to the specified criteria.
1924 *
1925 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
1926 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
1927 * @param[in] name Name of the node to find.
1928 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
1929 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
1930 * Used as a bitmask, so multiple nodetypes can be specified.
1931 * @param[in] options [ORed options](@ref sgetnextflags).
1932 * @return Found node if any.
1933 */
Michal Vaskoe444f752020-02-10 12:20:06 +01001934const struct lysc_node *lys_find_child(const struct lysc_node *parent, const struct lys_module *module,
1935 const char *name, size_t name_len, uint16_t nodetype, int options);
Radek Krejcia3045382018-11-22 14:30:31 +01001936
1937/**
Radek Krejci09e8d0a2019-11-17 12:14:15 +08001938 * @brief Get schema node specified by the schema path.
1939 *
1940 * In case the @p qpath uses prefixes (from imports or of the schema itself), the @p context_node must be specified
1941 * even if the path is absolute. In case the @p context_node is not provided, the names of the schemas are expected as the
1942 * node's prefixes in the @qpath. It also means that the relative paths are accepted only with the schema prefixes,
1943 * not the full names.
1944 *
1945 * @param[in] ctx libyang context for logging and getting the correct schema if @p contet_node not provided.
1946 * @param[in] context_node Context node for relative paths and/or as a source of the context module to resolve node's
1947 * prefixes in @qpath.
1948 * @param[in] qpath Schema path to be resolved. Not prefixed nodes inherits the prefix from its parent nodes. It means
1949 * that the first node in the path must be prefixed. Both, import prefixes as well as full schema names are accepted as
1950 * prefixes according to the @p context_node parameter presence.
1951 * @return NULL in case of invalid path.
1952 * @return found schema node.
1953 */
1954const struct lysc_node *lys_find_node(struct ly_ctx *ctx, const struct lysc_node *context_node, const char *qpath);
1955
1956/**
Radek Krejci77a8bcd2019-09-11 11:20:02 +02001957 * @brief Make the specific module implemented.
1958 *
1959 * @param[in] mod Module to make implemented. It is not an error
1960 * to provide already implemented module, it just does nothing.
Michal Vaskoe444f752020-02-10 12:20:06 +01001961 * @return LY_SUCCESS on success.
1962 * @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 +02001963 */
1964LY_ERR lys_set_implemented(struct lys_module *mod);
1965
1966/**
Radek Krejcia3045382018-11-22 14:30:31 +01001967 * @brief Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statement
1968 * affecting the node.
1969 *
1970 * @param[in] node Schema node to check.
1971 * @param[in] recursive - 0 to check if-feature only in the \p node schema node,
1972 * - 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 +01001973 * @return NULL if enabled,
Michal Vaskoc193ce92020-03-06 11:04:48 +01001974 * @return pointer to the node with the unsatisfied (disabled) if-feature expression.
Radek Krejcia3045382018-11-22 14:30:31 +01001975 */
Michal Vaskoc193ce92020-03-06 11:04:48 +01001976const struct lysc_node *lysc_node_is_disabled(const struct lysc_node *node, int recursive);
Radek Krejcia3045382018-11-22 14:30:31 +01001977
Radek Krejci084289f2019-07-09 17:35:30 +02001978/**
1979 * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
1980 *
1981 * This function check just the type's restriction, if you want to check also the data tree context (e.g. in case of
1982 * require-instance restriction), use lyd_value_validate().
1983 *
1984 * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
1985 * @param[in] node Schema node for the @p value.
1986 * @param[in] value String value to be checked.
1987 * @param[in] value_len Length of the given @p value (mandatory).
1988 * @param[in] get_prefix Callback function to resolve prefixes used in the @p value string.
1989 * @param[in] get_prefix_data Private data for the @p get_prefix callback.
1990 * @param[in] format Input format of the @p value.
1991 * @return LY_SUCCESS on success
1992 * @return LY_ERR value if an error occurred.
1993 */
Michal Vasko44685da2020-03-17 15:38:06 +01001994LY_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 +02001995 ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format);
1996
Radek Krejci0935f412019-08-20 16:15:18 +02001997/**
1998 * @brief Stringify schema nodetype.
1999 * @param[in] nodetype Nodetype to stringify.
2000 * @return Constant string with the name of the node's type.
2001 */
2002const char *lys_nodetype2str(uint16_t nodetype);
2003
Radek Krejci2ff0d572020-05-21 15:27:28 +02002004/** @} schematree */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002005
Radek Krejci70853c52018-10-15 14:46:16 +02002006#ifdef __cplusplus
2007}
2008#endif
2009
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002010#endif /* LY_TREE_SCHEMA_H_ */