blob: 4ed3e0781a498b8f3913cc31fd34dc39bece00d4 [file] [log] [blame]
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001/**
2 * @file tree_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief libyang representation of YANG schema trees.
5 *
6 * Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_TREE_SCHEMA_H_
16#define LY_TREE_SCHEMA_H_
17
Radek Krejci54579462019-04-30 12:47:06 +020018#define PCRE2_CODE_UNIT_WIDTH 8
19
20#include <pcre2.h>
Radek Krejci535ea9f2020-05-29 16:01:05 +020021
Radek Krejci5aeea3a2018-09-05 13:29:36 +020022#include <stdint.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020023#include <stdio.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020024
Radek Krejcie7b95092019-05-15 11:03:07 +020025#include "log.h"
26#include "tree.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020027#include "tree_data.h"
Radek Krejcice8c1592018-10-29 15:35:51 +010028
Radek Krejcie7b95092019-05-15 11:03:07 +020029struct ly_ctx;
Radek Krejci535ea9f2020-05-29 16:01:05 +020030struct ly_set;
Radek Krejcie7b95092019-05-15 11:03:07 +020031
Radek Krejci70853c52018-10-15 14:46:16 +020032#ifdef __cplusplus
33extern "C" {
34#endif
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
128/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200129 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
130 */
131typedef enum {
132 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
133 LYS_IN_YANG = 1, /**< YANG schema input format */
Radek Krejci693262f2019-04-29 15:23:20 +0200134 LYS_IN_YIN = 3 /**< YIN schema input format */
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200135} LYS_INFORMAT;
136
137/**
138 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
139 */
140typedef enum {
141 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
142 LYS_OUT_YANG = 1, /**< YANG schema output format */
Radek Krejci693262f2019-04-29 15:23:20 +0200143 LYS_OUT_YANG_COMPILED = 2, /**< YANG schema output format of the compiled schema tree */
FredGand944bdc2019-11-05 21:57:07 +0800144 LYS_OUT_YIN = 3, /**< YIN schema output format */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200145
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200146 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200147} LYS_OUTFORMAT;
148
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200149#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
150
Michal Vaskob55f6c12018-09-12 11:13:15 +0200151#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
152#define LYS_CONTAINER 0x0001 /**< container statement node */
153#define LYS_CHOICE 0x0002 /**< choice statement node */
154#define LYS_LEAF 0x0004 /**< leaf statement node */
155#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
156#define LYS_LIST 0x0010 /**< list statement node */
157#define LYS_ANYXML 0x0020 /**< anyxml statement node */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200158#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 +0200159
Michal Vasko1bf09392020-03-27 12:38:10 +0100160#define LYS_RPC 0x400 /**< RPC statement node */
161#define LYS_ACTION 0x800 /**< action statement node */
162#define LYS_NOTIF 0x1000 /**< notification statement node */
Radek Krejcie7b95092019-05-15 11:03:07 +0200163
Radek Krejcia3045382018-11-22 14:30:31 +0100164#define LYS_CASE 0x0040 /**< case statement node */
165#define LYS_USES 0x0080 /**< uses statement node */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200166#define LYS_INPUT 0x100
167#define LYS_OUTPUT 0x200
168#define LYS_INOUT 0x300
Michal Vasko1bf09392020-03-27 12:38:10 +0100169#define LYS_GROUPING 0x2000
170#define LYS_AUGMENT 0x4000
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100171
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200172/**
Radek Krejcid6b76452019-09-03 17:03:03 +0200173 * @brief List of YANG statements
174 */
175enum ly_stmt {
176 LY_STMT_NONE = 0,
Radek Krejciad5963b2019-09-06 16:03:05 +0200177 LY_STMT_STATUS, /**< in lysc_ext_substmt::storage stored as a pointer to `uint16_t`, only cardinality < #LY_STMT_CARD_SOME is allowed */
178 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 +0200179 LY_STMT_MANDATORY,
Radek Krejciad5963b2019-09-06 16:03:05 +0200180 LY_STMT_UNITS, /**< in lysc_ext_substmt::storage stored as a pointer to `const char *` (cardinality < #LY_STMT_CARD_SOME)
181 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200182 LY_STMT_DEFAULT,
Radek Krejciad5963b2019-09-06 16:03:05 +0200183 LY_STMT_TYPE, /**< in lysc_ext_substmt::storage stored as a pointer to `struct lysc_type *` (cardinality < #LY_STMT_CARD_SOME)
184 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_type **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200185
Radek Krejcid6b76452019-09-03 17:03:03 +0200186 LY_STMT_ACTION,
187 LY_STMT_ANYDATA,
188 LY_STMT_ANYXML,
189 LY_STMT_ARGUMENT,
190 LY_STMT_AUGMENT,
191 LY_STMT_BASE,
192 LY_STMT_BELONGS_TO,
193 LY_STMT_BIT,
194 LY_STMT_CASE,
195 LY_STMT_CHOICE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200196 LY_STMT_CONTACT,
197 LY_STMT_CONTAINER,
Radek Krejcid6b76452019-09-03 17:03:03 +0200198 LY_STMT_DESCRIPTION,
199 LY_STMT_DEVIATE,
200 LY_STMT_DEVIATION,
201 LY_STMT_ENUM,
202 LY_STMT_ERROR_APP_TAG,
203 LY_STMT_ERROR_MESSAGE,
204 LY_STMT_EXTENSION,
205 LY_STMT_FEATURE,
206 LY_STMT_FRACTION_DIGITS,
207 LY_STMT_GROUPING,
208 LY_STMT_IDENTITY,
Radek Krejciad5963b2019-09-06 16:03:05 +0200209 LY_STMT_IF_FEATURE, /**< in lysc_ext_substmt::storage stored as a pointer to `struct lysc_iffeature` (cardinality < #LY_STMT_CARD_SOME)
210 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_iffeature *` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200211 LY_STMT_IMPORT,
212 LY_STMT_INCLUDE,
213 LY_STMT_INPUT,
214 LY_STMT_KEY,
215 LY_STMT_LEAF,
216 LY_STMT_LEAF_LIST,
217 LY_STMT_LENGTH,
218 LY_STMT_LIST,
Radek Krejcid6b76452019-09-03 17:03:03 +0200219 LY_STMT_MAX_ELEMENTS,
220 LY_STMT_MIN_ELEMENTS,
221 LY_STMT_MODIFIER,
222 LY_STMT_MODULE,
223 LY_STMT_MUST,
224 LY_STMT_NAMESPACE,
225 LY_STMT_NOTIFICATION,
226 LY_STMT_ORDERED_BY,
227 LY_STMT_ORGANIZATION,
228 LY_STMT_OUTPUT,
229 LY_STMT_PATH,
230 LY_STMT_PATTERN,
231 LY_STMT_POSITION,
232 LY_STMT_PREFIX,
233 LY_STMT_PRESENCE,
234 LY_STMT_RANGE,
235 LY_STMT_REFERENCE,
236 LY_STMT_REFINE,
237 LY_STMT_REQUIRE_INSTANCE,
238 LY_STMT_REVISION,
239 LY_STMT_REVISION_DATE,
240 LY_STMT_RPC,
Radek Krejcid6b76452019-09-03 17:03:03 +0200241 LY_STMT_SUBMODULE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200242 LY_STMT_TYPEDEF,
243 LY_STMT_UNIQUE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200244 LY_STMT_USES,
245 LY_STMT_VALUE,
246 LY_STMT_WHEN,
247 LY_STMT_YANG_VERSION,
248 LY_STMT_YIN_ELEMENT,
249 LY_STMT_EXTENSION_INSTANCE,
250
251 LY_STMT_SYNTAX_SEMICOLON,
252 LY_STMT_SYNTAX_LEFT_BRACE,
253 LY_STMT_SYNTAX_RIGHT_BRACE,
254
255 LY_STMT_ARG_TEXT,
256 LY_STMT_ARG_VALUE
257};
258
259/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200260 * @brief Extension instance structure parent enumeration
261 */
262typedef enum {
Radek Krejci0935f412019-08-20 16:15:18 +0200263 LYEXT_PAR_MODULE, /**< ::lysc_module */
264 LYEXT_PAR_NODE, /**< ::lysc_node (and the derived structures including ::lysc_action and ::lysc_notif) */
265 LYEXT_PAR_INPUT, /**< ::lysc_action_inout */
266 LYEXT_PAR_OUTPUT, /**< ::lysc_action_inout */
267 LYEXT_PAR_TYPE, /**< ::lysc_type */
268 LYEXT_PAR_TYPE_BIT, /**< ::lysc_type_bitenum_item */
269 LYEXT_PAR_TYPE_ENUM, /**< ::lysc_type_bitenum_item */
270 LYEXT_PAR_FEATURE, /**< ::lysc_feature */
271 LYEXT_PAR_MUST, /**< ::lysc_must */
272 LYEXT_PAR_PATTERN, /**< ::lysc_pattern */
273 LYEXT_PAR_LENGTH, /**< ::lysc_range */
274 LYEXT_PAR_RANGE, /**< ::lysc_range */
275 LYEXT_PAR_WHEN, /**< ::lysc_when */
276 LYEXT_PAR_IDENT, /**< ::lysc_ident */
277 LYEXT_PAR_EXT, /**< ::lysc_ext */
278 LYEXT_PAR_IMPORT, /**< ::lysc_import */
279// LYEXT_PAR_TPDF, /**< ::lysp_tpdf */
280// LYEXT_PAR_EXTINST, /**< ::lysp_ext_instance */
281// LYEXT_PAR_REFINE, /**< ::lysp_refine */
282// LYEXT_PAR_DEVIATION, /**< ::lysp_deviation */
283// LYEXT_PAR_DEVIATE, /**< ::lysp_deviate */
284// LYEXT_PAR_INCLUDE, /**< ::lysp_include */
285// LYEXT_PAR_REVISION, /**< ::lysp_revision */
Radek Krejci0e59c312019-08-15 15:34:15 +0200286} LYEXT_PARENT;
287
288/**
Radek Krejci0935f412019-08-20 16:15:18 +0200289 * @brief Stringify extension instance parent type.
290 * @param[in] type Parent type to stringify.
291 * @return Constant string with the name of the parent statement.
292 */
293const char *lyext_parent2str(LYEXT_PARENT type);
294
295/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200296 * @brief Enum of substatements in which extension instances can appear.
297 */
298typedef enum {
299 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
300 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
301 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
302 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
303 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
304 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
305 lys_node_choice and lys_deviate */
306 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
307 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
308 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
309 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
310 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
311 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
312 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
313 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
314 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
315 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
316 belongs-to's prefix) and lys_import */
317 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
318 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
319 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
320 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
321 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
322 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
323 lys_node_leaflist and lys_deviate */
324 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
325 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
326 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
327 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
328 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
329 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
330 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
331 lys_node_anydata and lys_deviate */
332 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
333 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
334 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
335 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
336 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
337 lys_node_leaflist and lys_deviate */
338 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
339 lys_node_leaflist and lys_deviate */
340 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
341 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
342 LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */
343} LYEXT_SUBSTMT;
344
345/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200346 * @brief YANG import-stmt
347 */
348struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200349 struct lys_module *module; /**< pointer to the imported module
350 (mandatory, but resolved when the referring module is completely parsed) */
351 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200352 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200353 const char *dsc; /**< description */
354 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200355 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200356 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
357};
358
359/**
360 * @brief YANG include-stmt
361 */
362struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100363 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200364 (mandatory, but resolved when the referring module is completely parsed) */
365 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200366 const char *dsc; /**< description */
367 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200368 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200369 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
370};
371
372/**
373 * @brief YANG extension-stmt
374 */
375struct lysp_ext {
376 const char *name; /**< extension name */
377 const char *argument; /**< argument name, NULL if not specified */
378 const char *dsc; /**< description statement */
379 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200380 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200381 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */
Michal Vasko5fe75f12020-03-02 13:52:37 +0100382
383 struct lysc_ext *compiled; /**< pointer to the compiled extension definition */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200384};
385
386/**
387 * @brief Helper structure for generic storage of the extension instances content.
388 */
389struct lysp_stmt {
390 const char *stmt; /**< identifier of the statement */
391 const char *arg; /**< statement's argument */
392 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200393 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
David Sedlákb9d75c42019-08-14 10:49:42 +0200394 uint16_t flags; /**< statement flags, can be set to LYS_YIN_ATTR */
Radek Krejci335332a2019-09-05 13:03:35 +0200395 enum ly_stmt kw; /**< numeric respresentation of the stmt value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200396};
397
David Sedlákae4b4512019-08-14 10:45:56 +0200398#define LYS_YIN 0x1 /**< used to specify input format of extension instance */
399
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200400/**
401 * @brief YANG extension instance
402 */
403struct lysp_ext_instance {
David Sedlákbbd06ca2019-06-27 14:15:38 +0200404 const char *name; /**< extension identifier, including possible prefix */
405 const char *argument; /**< optional value of the extension's argument */
Radek Krejci335332a2019-09-05 13:03:35 +0200406 void *parent; /**< pointer to the parent element holding the extension instance(s), use
407 ::lysp_ext_instance#parent_type to access the schema element */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200408 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200409 struct lysc_ext_instance *compiled; /**< pointer to the compiled data if any - in case the source format is YIN,
410 some of the information (argument) are available only after compilation */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200411 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200412 LY_ARRAY_SIZE_TYPE insubstmt_index; /**< in case the instance is in a substatement, this identifies
David Sedlákbbd06ca2019-06-27 14:15:38 +0200413 the index of that substatement */
David Sedlákae4b4512019-08-14 10:45:56 +0200414 uint8_t yin; /** flag for YIN source format, can be set to LYS_YIN */
Radek Krejci335332a2019-09-05 13:03:35 +0200415 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200416};
417
418/**
419 * @brief YANG feature-stmt
420 */
421struct lysp_feature {
422 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200423 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200424 const char *dsc; /**< description statement */
425 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200426 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200427 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
428};
429
430/**
431 * @brief YANG identity-stmt
432 */
433struct lysp_ident {
434 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200435 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
436 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200437 const char *dsc; /**< description statement */
438 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200439 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200440 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
441};
442
Michal Vasko71e64ca2018-09-07 16:30:29 +0200443/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200444 * @brief Covers restrictions: range, length, pattern, must
445 */
446struct lysp_restr {
447 const char *arg; /**< The restriction expression/value (mandatory);
448 in case of pattern restriction, the first byte has a special meaning:
449 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
450 const char *emsg; /**< error-message */
451 const char *eapptag; /**< error-app-tag value */
452 const char *dsc; /**< description */
453 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200454 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200455};
456
457/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200458 * @brief YANG revision-stmt
459 */
460struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200461 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200462 const char *dsc; /**< description statement */
463 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200464 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200465};
466
467/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200468 * @brief Enumeration/Bit value definition
469 */
470struct lysp_type_enum {
471 const char *name; /**< name (mandatory) */
472 const char *dsc; /**< description statement */
473 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200474 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200475 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200476 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200477 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
478 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200479};
480
481/**
482 * @brief YANG type-stmt
483 *
484 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
485 */
486struct lysp_type {
487 const char *name; /**< name of the type (mandatory) */
488 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
489 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200490 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
491 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
492 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200493 const char *path; /**< path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200494 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200495 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
496 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200497
Radek Krejci2167ee12018-11-02 16:09:07 +0100498 struct lysc_type *compiled; /**< pointer to the compiled type */
499
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200500 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
501 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100502 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200503};
504
505/**
506 * @brief YANG typedef-stmt
507 */
508struct lysp_tpdf {
509 const char *name; /**< name of the newly defined type (mandatory) */
510 const char *units; /**< units of the newly defined type */
511 const char *dflt; /**< default value of the newly defined type */
512 const char *dsc; /**< description statement */
513 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200514 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200515 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100516 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200517};
518
519/**
520 * @brief YANG grouping-stmt
521 */
522struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100523 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
524 uint16_t nodetype; /**< LYS_GROUPING */
525 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200526 const char *name; /**< grouping name (mandatory) */
527 const char *dsc; /**< description statement */
528 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200529 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
530 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200531 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200532 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
533 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
534 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200535};
536
537/**
538 * @brief YANG when-stmt
539 */
540struct lysp_when {
541 const char *cond; /**< specified condition (mandatory) */
542 const char *dsc; /**< description statement */
543 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200544 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200545};
546
547/**
548 * @brief YANG refine-stmt
549 */
550struct lysp_refine {
551 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
552 const char *dsc; /**< description statement */
553 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200554 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200555 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200556 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200557 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200558 uint32_t min; /**< min-elements constraint */
559 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200560 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200561 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
562};
563
564/**
Michal Vasko82a83432019-11-14 12:33:04 +0100565 * @brief YANG uses-augment-stmt and augment-stmt (compatible with struct lysp_node )
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200566 */
567struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100568 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
569 uint16_t nodetype; /**< LYS_AUGMENT */
570 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Michal Vasko82a83432019-11-14 12:33:04 +0100571 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200572 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
573 const char *dsc; /**< description statement */
574 const char *ref; /**< reference statement */
575 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200576 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Michal Vasko82a83432019-11-14 12:33:04 +0100577 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200578 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
579 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200580};
581
582/**
583 * @defgroup deviatetypes Deviate types
584 * @{
585 */
586#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
587#define LYS_DEV_ADD 2 /**< deviate type add */
588#define LYS_DEV_DELETE 3 /**< deviate type delete */
589#define LYS_DEV_REPLACE 4 /**< deviate type replace */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200590/** @} deviatetypes */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200591
592/**
593 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
594 */
595struct lysp_deviate {
596 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
597 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200598 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200599};
600
601struct lysp_deviate_add {
602 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
603 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200604 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200605 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200606 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200607 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
608 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200609 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
610 uint32_t min; /**< min-elements constraint */
611 uint32_t max; /**< max-elements constraint, 0 means unbounded */
612};
613
614struct lysp_deviate_del {
615 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
616 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200617 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200618 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200619 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200620 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
621 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200622};
623
624struct lysp_deviate_rpl {
625 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
626 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200627 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200628 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200629 const char *units; /**< units of the values */
630 const char *dflt; /**< default value */
631 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
632 uint32_t min; /**< min-elements constraint */
633 uint32_t max; /**< max-elements constraint, 0 means unbounded */
634};
635
636struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200637 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200638 const char *dsc; /**< description statement */
639 const char *ref; /**< reference statement */
640 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200641 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200642};
643
Radek Krejci4f28eda2018-11-12 11:46:16 +0100644/**
645 * @defgroup spnodeflags Parsed schema nodes flags
646 * @ingroup snodeflags
647 *
648 * Various flags for parsed schema nodes.
649 *
650 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
651 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200652 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100653 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
654 * 5 - list 10 - input 15 - typedef 20 - deviate
655 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200656 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
657 * 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
658 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
659 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
660 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
661 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
662 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
663 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
664 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
665 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
666 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
667 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
668 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
669 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
670 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
671 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
672 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
673 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
674 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
675 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
676 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
677 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
678 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
679 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
680 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
681 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
682 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
683 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
684 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
685 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
686 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
687 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
688 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
689 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
690 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
691 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
692 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
693 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
694 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200695 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
David Sedlákae4b4512019-08-14 10:45:56 +0200696 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejcid3ca0632019-04-16 16:54:54 +0200697 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejcif56e2a42019-09-09 14:15:25 +0200698 * 12 LYS_YIN_ARGUMENT | | | | | | | | | | | | | | | | | | | | | | |x|
699 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100700 *
701 */
702
703/**
704 * @defgroup scnodeflags Compiled schema nodes flags
705 * @ingroup snodeflags
706 *
707 * Various flags for compiled schema nodes.
708 *
Radek Krejci61e042e2019-09-10 15:53:09 +0200709 * 1 - container 6 - anydata/anyxml 11 - identity
710 * 2 - choice 7 - case 12 - extension
711 * 3 - leaf 8 - notification 13 - bitenum
Michal Vasko03ff5a72019-09-11 13:49:33 +0200712 * 4 - leaflist 9 - rpc/action 14 - when
Michal Vaskoecd62de2019-11-13 12:35:11 +0100713 * 5 - list 10 - feature
Radek Krejci4f28eda2018-11-12 11:46:16 +0100714 *
Michal Vaskoecd62de2019-11-13 12:35:11 +0100715 * 1 1 1 1 1
716 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
717 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
718 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | |
719 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
720 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | |
721 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
722 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x|x|x|x| |x|
723 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
724 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x|x|x|x| |x|
725 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
726 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x|x|x|x| |x|
727 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
728 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
729 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
730 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
731 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | |
732 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
733 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
734 * LYS_PRESENCE |x| | | | | | | | | | | | | |
735 * LYS_UNIQUE | | |x| | | | | | | | | | | |
736 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
737 * 9 LYS_KEY | | |x| | | | | | | | | | | |
738 * LYS_FENABLED | | | | | | | | | |x| | | | |
739 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
740 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
741 * LYS_ISENUM | | | | | | | | | | | | |x| |
742 * LYS_KEYLESS | | | | |x| | | | | | | | | |
743 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
744 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
745 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
746 * 12 LYS_SET_CONFIG |x|x|x|x|x|x| | | | | | | | |
747 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100748 *
749 */
750
751/**
752 * @defgroup snodeflags Schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100753 * @{
754 */
Michal Vasko1bf09392020-03-27 12:38:10 +0100755#define LYS_CONFIG_W 0x01 /**< config true; also set for input children nodes */
756#define LYS_CONFIG_R 0x02 /**< config false; also set for output and notification children nodes */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200757#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100758#define LYS_STATUS_CURR 0x04 /**< status current; */
759#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
760#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
761#define LYS_STATUS_MASK 0x1C /**< mask for status value */
762#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100763 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
764 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
765 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
766 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100767#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
768 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
769 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100770#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100771#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, applicable only to ::lysc_node_container */
772#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
773#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 +0200774#define LYS_KEYLESS 0x200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100775#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysc_feature */
Radek Krejcife909632019-02-12 15:34:42 +0100776#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 +0100777 ::lysc_node_list/::lysp_node_list */
778#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
779 ::lysc_node_list/::lysp_node_list */
780#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
781#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
782#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
783#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200784#define LYS_USED_GRP 0x400 /**< internal flag for validating not-instantiated groupings
785 (resp. do not validate again the instantiated groupings). */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100786#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100787#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200788#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100789
790#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
791#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
792#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
793#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
794#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
795#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
796#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
797#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
798#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
799#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100800#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 +0100801 cases of choice. This information is important for refines, since it is prohibited to make leafs
802 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100803 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
804 between own default or the default values taken from the type. */
805#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 +0100806#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 +0100807
Radek Krejcif56e2a42019-09-09 14:15:25 +0200808#define LYS_SINGLEQUOTED 0x100 /**< flag for single-quoted argument of an extension instance's substatement, only when the source is YANG */
809#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 +0200810
Radek Krejcif56e2a42019-09-09 14:15:25 +0200811#define LYS_YIN_ATTR 0x400 /**< flag to identify YIN attribute parsed as extension's substatement, only when the source is YIN */
812#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 +0200813
Radek Krejci693262f2019-04-29 15:23:20 +0200814#define LYS_ISENUM 0x200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
815
Radek Krejcife909632019-02-12 15:34:42 +0100816#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200817/** @} snodeflags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200818
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200819/**
820 * @brief Generic YANG data node
821 */
822struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100823 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200824 uint16_t nodetype; /**< type of the node (mandatory) */
825 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100826 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200827 const char *name; /**< node name (mandatory) */
828 const char *dsc; /**< description statement */
829 const char *ref; /**< reference statement */
830 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200831 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200832 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200833};
834
835/**
836 * @brief Extension structure of the lysp_node for YANG container
837 */
838struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100839 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200840 uint16_t nodetype; /**< LYS_CONTAINER */
841 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
842 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
843 const char *name; /**< node name (mandatory) */
844 const char *dsc; /**< description statement */
845 const char *ref; /**< reference statement */
846 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200847 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200848 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200849
850 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200851 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200852 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200853 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
854 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200855 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200856 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
857 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200858};
859
860struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100861 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200862 uint16_t nodetype; /**< LYS_LEAF */
863 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
864 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
865 const char *name; /**< node name (mandatory) */
866 const char *dsc; /**< description statement */
867 const char *ref; /**< reference statement */
868 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200869 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200870 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200871
872 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200873 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200874 struct lysp_type type; /**< type of the leaf node (mandatory) */
875 const char *units; /**< units of the leaf's type */
876 const char *dflt; /**< default value */
877};
878
879struct lysp_node_leaflist {
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_LEAFLIST */
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 /* leaf-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 struct lysp_type type; /**< type of the leaf node (mandatory) */
894 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200895 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200896 uint32_t min; /**< min-elements constraint */
897 uint32_t max; /**< max-elements constraint, 0 means unbounded */
898};
899
900struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100901 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200902 uint16_t nodetype; /**< LYS_LIST */
903 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
904 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
905 const char *name; /**< node name (mandatory) */
906 const char *dsc; /**< description statement */
907 const char *ref; /**< reference statement */
908 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200909 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200910 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200911
912 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200913 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200914 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200915 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
916 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200917 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200918 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
919 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200920 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200921 uint32_t min; /**< min-elements constraint */
922 uint32_t max; /**< max-elements constraint, 0 means unbounded */
923};
924
925struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100926 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200927 uint16_t nodetype; /**< LYS_CHOICE */
928 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
929 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
930 const char *name; /**< node name (mandatory) */
931 const char *dsc; /**< description statement */
932 const char *ref; /**< reference statement */
933 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200934 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200935 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200936
937 /* choice */
938 struct lysp_node *child; /**< list of data nodes (linked list) */
939 const char* dflt; /**< default case */
940};
941
942struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100943 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200944 uint16_t nodetype; /**< LYS_CASE */
945 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
946 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
947 const char *name; /**< node name (mandatory) */
948 const char *dsc; /**< description statement */
949 const char *ref; /**< reference statement */
950 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200951 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200952 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200953
954 /* case */
955 struct lysp_node *child; /**< list of data nodes (linked list) */
956};
957
958struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100959 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200960 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
961 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
962 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
963 const char *name; /**< node name (mandatory) */
964 const char *dsc; /**< description statement */
965 const char *ref; /**< reference statement */
966 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200967 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200968 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200969
970 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200971 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200972};
973
974struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100975 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200976 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200977 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
978 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
979 const char *name; /**< grouping name reference (mandatory) */
980 const char *dsc; /**< description statement */
981 const char *ref; /**< reference statement */
982 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200983 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200984 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200985
986 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200987 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
988 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200989};
990
991/**
992 * @brief YANG input-stmt and output-stmt
993 */
994struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100995 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
996 uint16_t nodetype; /**< LYS_INOUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200997 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
998 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
999 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001000 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001001 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001002};
1003
1004/**
1005 * @brief YANG rpc-stmt and action-stmt
1006 */
1007struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001008 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko1bf09392020-03-27 12:38:10 +01001009 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001010 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001011 const char *name; /**< grouping name reference (mandatory) */
1012 const char *dsc; /**< description statement */
1013 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +02001014 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001015 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1016 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001017 struct lysp_action_inout input; /**< RPC's/Action's input */
1018 struct lysp_action_inout output; /**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001019 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001020};
1021
1022/**
1023 * @brief YANG notification-stmt
1024 */
1025struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001026 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1027 uint16_t nodetype; /**< LYS_NOTIF */
1028 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001029 const char *name; /**< grouping name reference (mandatory) */
1030 const char *dsc; /**< description statement */
1031 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +02001032 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001033 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1034 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1035 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001036 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001037 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001038};
1039
1040/**
Radek Krejcif0fceb62018-09-05 14:58:45 +02001041 * @brief supported YANG schema version values
1042 */
1043typedef enum LYS_VERSION {
1044 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
1045 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
1046 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
1047} LYS_VERSION;
1048
1049/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001050 * @brief Printable YANG schema tree structure representing YANG module.
1051 *
1052 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
1053 */
1054struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001055 struct lys_module *mod; /**< covering module structure */
1056
Radek Krejcib7db73a2018-10-24 14:18:40 +02001057 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1058 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001059 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1060 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001061 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1062 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1063 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1064 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1065 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001066 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001067 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1068 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1069 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1070 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
1071 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001072
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001073 uint8_t parsing:1; /**< flag for circular check */
1074};
1075
1076struct lysp_submodule {
1077 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
1078
1079 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1080 in the list is always the last (newest) revision of the module */
1081 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1082 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
1083 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1084 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1085 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1086 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1087 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
1088 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
1089 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1090 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1091 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1092 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
1093 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1094
1095 uint8_t parsing:1; /**< flag for circular check */
1096
Radek Krejci086c7132018-10-26 15:29:04 +02001097 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
1098 1 - the latest revision in searchdirs was not searched yet and this is the
1099 latest revision in the current context
1100 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001101 const char *name; /**< name of the module (mandatory) */
1102 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1103 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
1104 const char *org; /**< party/company responsible for the module */
1105 const char *contact; /**< contact information for the module */
1106 const char *dsc; /**< description of the module */
1107 const char *ref; /**< cross-reference for the module */
Radek Krejci086c7132018-10-26 15:29:04 +02001108 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001109};
1110
1111/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +02001112 * @brief Free the printable YANG schema tree structure.
1113 *
1114 * @param[in] module Printable YANG schema tree structure to free.
1115 */
1116void lysp_module_free(struct lysp_module *module);
1117
1118/**
Radek Krejci535ea9f2020-05-29 16:01:05 +02001119 * @defgroup scflags Schema compile flags
1120 * @ingroup schematree
1121 *
1122 * @{
1123 */
1124#define LYSC_OPT_RPC_INPUT LYS_CONFIG_W /**< Internal option when compiling schema tree of RPC/action input */
1125#define LYSC_OPT_RPC_OUTPUT LYS_CONFIG_R /**< Internal option when compiling schema tree of RPC/action output */
1126#define LYSC_OPT_RPC_MASK LYS_CONFIG_MASK /**< mask for the internal RPC options */
1127#define LYSC_OPT_FREE_SP 0x04 /**< Free the input printable schema */
1128#define LYSC_OPT_INTERNAL 0x08 /**< Internal compilation caused by dependency */
1129#define LYSC_OPT_NOTIFICATION 0x10 /**< Internal option when compiling schema tree of Notification */
1130
1131#define LYSC_OPT_GROUPING 0x20 /** Compiling (validation) of a non-instantiated grouping.
1132 In this case not all the restrictions are checked since they can be valid only
1133 in the real placement of the grouping. TODO - what specifically is not done */
1134/** @} scflags */
1135
1136/**
Radek Krejci0e59c312019-08-15 15:34:15 +02001137 * @brief Compiled YANG extension-stmt
1138 */
1139struct lysc_ext {
1140 const char *name; /**< extension name */
1141 const char *argument; /**< argument name, NULL if not specified */
Radek Krejci0e59c312019-08-15 15:34:15 +02001142 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1143 struct lyext_plugin *plugin; /**< Plugin implementing the specific extension */
Radek Krejci0935f412019-08-20 16:15:18 +02001144 struct lys_module *module; /**< module structure */
Michal Vasko6f4cbb62020-02-28 11:15:47 +01001145 uint32_t refcount; /**< reference counter since extension definition is shared among all its instances */
Radek Krejci0e59c312019-08-15 15:34:15 +02001146 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
1147};
1148
1149/**
Radek Krejcice8c1592018-10-29 15:35:51 +01001150 * @brief YANG extension instance
1151 */
1152struct lysc_ext_instance {
Radek Krejciad5963b2019-09-06 16:03:05 +02001153 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
1154 this identifies the index of the substatement for this extension instance */
Radek Krejci28681fa2019-09-06 13:08:45 +02001155 struct lys_module *module; /**< module where the extension instantiated is defined */
Radek Krejciad5963b2019-09-06 16:03:05 +02001156 struct lysc_ext *def; /**< pointer to the extension definition */
Radek Krejcice8c1592018-10-29 15:35:51 +01001157 void *parent; /**< pointer to the parent element holding the extension instance(s), use
1158 ::lysc_ext_instance#parent_type to access the schema element */
1159 const char *argument; /**< optional value of the extension's argument */
1160 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +01001161 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001162 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0e59c312019-08-15 15:34:15 +02001163 void *data; /**< private plugins's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +01001164};
1165
1166/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001167 * @brief Compiled YANG if-feature-stmt
1168 */
1169struct lysc_iffeature {
1170 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
1171 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
1172};
1173
1174/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001175 * @brief YANG import-stmt
1176 */
1177struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +01001178 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +02001179 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001180 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +02001181};
1182
1183/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001184 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001185 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001186struct lysc_when {
Radek Krejcia0f704a2019-09-09 16:12:23 +02001187 struct lys_module *module; /**< module where the must was defined */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001188 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko175012e2019-11-06 15:49:14 +01001189 struct lysc_node *context; /**< context node for evaluating the expression, NULL if the context is root node */
Radek Krejcic8b31002019-01-08 10:24:45 +01001190 const char *dsc; /**< description */
1191 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001192 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001193 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Michal Vaskoecd62de2019-11-13 12:35:11 +01001194 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS is allowed */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001195};
1196
1197/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001198 * @brief YANG identity-stmt
1199 */
1200struct lysc_ident {
1201 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +01001202 const char *dsc; /**< description */
1203 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001204 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001205 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
1206 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001207 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001208 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1209};
1210
1211/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001212 * @brief YANG feature-stmt
1213 */
1214struct lysc_feature {
1215 const char *name; /**< feature name (mandatory) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001216 const char *dsc; /**< description */
1217 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001218 struct lys_module *module; /**< module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001219 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 +01001220 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001221 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001222 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
1223 #LYS_FENABLED values allowed */
1224};
1225
Radek Krejci151a5b72018-10-19 14:21:44 +02001226/**
1227 * @defgroup ifftokens if-feature expression tokens
1228 * Tokens of if-feature expression used in ::lysc_iffeature#expr
1229 *
1230 * @{
1231 */
1232#define LYS_IFF_NOT 0x00 /**< operand "not" */
1233#define LYS_IFF_AND 0x01 /**< operand "and" */
1234#define LYS_IFF_OR 0x02 /**< operand "or" */
1235#define LYS_IFF_F 0x03 /**< feature */
Radek Krejci2ff0d572020-05-21 15:27:28 +02001236/** @} ifftokens */
Radek Krejci151a5b72018-10-19 14:21:44 +02001237
1238/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001239 * @brief Compiled YANG revision statement
1240 */
1241struct lysc_revision {
1242 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1243 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1244};
1245
Radek Krejci2167ee12018-11-02 16:09:07 +01001246struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001247 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001248 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001249 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1250 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001251 };
Radek Krejci693262f2019-04-29 15:23:20 +02001252 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001253 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1254 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001255 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001256 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001257 const char *dsc; /**< description */
1258 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001259 const char *emsg; /**< error-message */
1260 const char *eapptag; /**< error-app-tag value */
1261 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1262};
1263
1264struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001265 const char *expr; /**< original, not compiled, regular expression */
1266 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001267 const char *dsc; /**< description */
1268 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001269 const char *emsg; /**< error-message */
1270 const char *eapptag; /**< error-app-tag value */
1271 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4586a022018-11-13 11:29:26 +01001272 uint32_t inverted:1; /**< invert-match flag */
1273 uint32_t refcount:31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001274};
1275
1276struct lysc_must {
1277 struct lys_module *module; /**< module where the must was defined */
1278 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001279 const char *dsc; /**< description */
1280 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001281 const char *emsg; /**< error-message */
1282 const char *eapptag; /**< error-app-tag value */
1283 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1284};
1285
1286struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001287 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001288 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001289 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 +02001290 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 +01001291 LY_DATA_TYPE basetype; /**< Base type of the type */
1292 uint32_t refcount; /**< reference counter for type sharing */
1293};
1294
1295struct lysc_type_num {
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 *range; /**< Optional range limitation */
1303};
1304
1305struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001306 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001307 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001308 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 +02001309 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 +01001310 LY_DATA_TYPE basetype; /**< Base type of the type */
1311 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001312 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001313 struct lysc_range *range; /**< Optional range limitation */
1314};
1315
1316struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001317 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001318 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001319 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 +02001320 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 +01001321 LY_DATA_TYPE basetype; /**< Base type of the type */
1322 uint32_t refcount; /**< reference counter for type sharing */
1323 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001324 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001325};
1326
Radek Krejci693262f2019-04-29 15:23:20 +02001327struct lysc_type_bitenum_item {
1328 const char *name; /**< enumeration identifier */
1329 const char *dsc; /**< description */
1330 const char *ref; /**< reference */
1331 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1332 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1333 union {
1334 int32_t value; /**< integer value associated with the enumeration */
1335 uint32_t position; /**< non-negative integer value associated with the bit */
1336 };
1337 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1338 values are allowed */
1339};
1340
Radek Krejci2167ee12018-11-02 16:09:07 +01001341struct lysc_type_enum {
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 */
Radek Krejci693262f2019-04-29 15:23:20 +02001348 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1349};
1350
1351struct lysc_type_bits {
1352 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1353 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001354 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 +02001355 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 +02001356 LY_DATA_TYPE basetype; /**< Base type of the type */
1357 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001358 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1359 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001360};
1361
1362struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001363 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001364 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001365 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 +02001366 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 +01001367 LY_DATA_TYPE basetype; /**< Base type of the type */
1368 uint32_t refcount; /**< reference counter for type sharing */
Michal Vasko03ff5a72019-09-11 13:49:33 +02001369 const char *path; /**< target path */
Radek Krejci96a0bfd2018-11-22 15:25:06 +01001370 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 +01001371 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001372 uint8_t require_instance; /**< require-instance flag */
1373};
1374
1375struct lysc_type_identityref {
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 */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001382 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001383 mandatory (at least 1 item) */
1384};
1385
1386struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001387 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001388 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001389 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001390 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001391 LY_DATA_TYPE basetype; /**< Base type of the type */
1392 uint32_t refcount; /**< reference counter for type sharing */
1393 uint8_t require_instance; /**< require-instance flag */
1394};
1395
Radek Krejci2167ee12018-11-02 16:09:07 +01001396struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001397 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001398 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001399 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 +02001400 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 +01001401 LY_DATA_TYPE basetype; /**< Base type of the type */
1402 uint32_t refcount; /**< reference counter for type sharing */
1403 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1404};
1405
1406struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001407 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001408 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001409 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 +02001410 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 +01001411 LY_DATA_TYPE basetype; /**< Base type of the type */
1412 uint32_t refcount; /**< reference counter for type sharing */
1413 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001414};
1415
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001416struct lysc_action_inout {
1417 struct lysc_node *data; /**< first child node (linked list) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001418 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1419};
1420
Radek Krejci056d0a82018-12-06 16:57:25 +01001421struct lysc_action {
Michal Vasko1bf09392020-03-27 12:38:10 +01001422 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci056d0a82018-12-06 16:57:25 +01001423 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001424 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001425 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. */
1426 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1427
Radek Krejcifc11bd72019-04-11 16:00:05 +02001428 struct lysc_ext_instance *input_exts; /**< list of the extension instances of input ([sized array](@ref sizedarrays)) */
1429 struct lysc_ext_instance *output_exts; /**< list of the extension instances of outpu ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001430
Radek Krejci056d0a82018-12-06 16:57:25 +01001431 const char *name; /**< action/RPC name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001432 const char *dsc; /**< description */
1433 const char *ref; /**< reference */
1434
Radek Krejcifc11bd72019-04-11 16:00:05 +02001435 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1436 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1437
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001438 struct lysc_action_inout input; /**< RPC's/action's input */
1439 struct lysc_action_inout output; /**< RPC's/action's output */
1440
Radek Krejci056d0a82018-12-06 16:57:25 +01001441};
1442
1443struct lysc_notif {
1444 uint16_t nodetype; /**< LYS_NOTIF */
1445 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001446 struct lys_module *module; /**< module structure */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001447 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 +01001448 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1449
Radek Krejcifc11bd72019-04-11 16:00:05 +02001450 struct lysc_node *data; /**< first child node (linked list) */
1451 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1452
Radek Krejci056d0a82018-12-06 16:57:25 +01001453 const char *name; /**< Notification name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001454 const char *dsc; /**< description */
1455 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001456
1457 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1458 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001459};
1460
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001461/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001462 * @brief Compiled YANG data node
1463 */
1464struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001465 uint16_t nodetype; /**< type of the node (mandatory) */
1466 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001467 struct lys_module *module; /**< module structure */
Michal Vaskocc048b22020-03-27 15:52:38 +01001468 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or
1469 in case of implicit case node. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001470 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1471 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1472 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1473 never NULL. If there is no sibling node, pointer points to the node
1474 itself. In case of the first node, this pointer points to the last
1475 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001476 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001477 const char *dsc; /**< description */
1478 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001479 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001480 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001481 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001482};
1483
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001484struct lysc_node_container {
1485 uint16_t nodetype; /**< LYS_CONTAINER */
1486 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1487 struct lys_module *module; /**< module structure */
1488 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. */
1489 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1490 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1491 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1492 never NULL. If there is no sibling node, pointer points to the node
1493 itself. In case of the first node, this pointer points to the last
1494 node in the list. */
1495 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001496 const char *dsc; /**< description */
1497 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001498 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001499 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001500 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001501
1502 struct lysc_node *child; /**< first child node (linked list) */
1503 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1504 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1505 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001506};
1507
Radek Krejcia3045382018-11-22 14:30:31 +01001508struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001509 uint16_t nodetype; /**< LYS_CASE */
1510 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1511 struct lys_module *module; /**< module structure */
1512 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. */
1513 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1514 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1515 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1516 never NULL. If there is no sibling node, pointer points to the node
1517 itself. In case of the first node, this pointer points to the last
1518 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001519 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001520 const char *dsc; /**< description */
1521 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001522 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001523 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001524 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001525
Radek Krejcia3045382018-11-22 14:30:31 +01001526 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 +01001527 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001528};
1529
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001530struct lysc_node_choice {
1531 uint16_t nodetype; /**< LYS_CHOICE */
1532 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1533 struct lys_module *module; /**< module structure */
1534 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. */
1535 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1536 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1537 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1538 never NULL. If there is no sibling node, pointer points to the node
1539 itself. In case of the first node, this pointer points to the last
1540 node in the list. */
1541 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001542 const char *dsc; /**< description */
1543 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001544 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001545 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001546 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001547
Radek Krejcia9026eb2018-12-12 16:04:47 +01001548 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1549 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1550 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001551 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001552};
1553
1554struct lysc_node_leaf {
1555 uint16_t nodetype; /**< LYS_LEAF */
1556 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1557 struct lys_module *module; /**< module structure */
1558 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. */
1559 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1560 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1561 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1562 never NULL. If there is no sibling node, pointer points to the node
1563 itself. In case of the first node, this pointer points to the last
1564 node in the list. */
1565 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001566 const char *dsc; /**< description */
1567 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001568 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001569 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001570 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001571
1572 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1573 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001574
Radek Krejci4f28eda2018-11-12 11:46:16 +01001575 const char *units; /**< units of the leaf's type */
Radek Krejcia1911222019-07-22 17:24:50 +02001576 struct lyd_value *dflt; /**< default value */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001577 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 +01001578};
1579
1580struct lysc_node_leaflist {
1581 uint16_t nodetype; /**< LYS_LEAFLIST */
1582 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1583 struct lys_module *module; /**< module structure */
1584 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. */
1585 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1586 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1587 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1588 never NULL. If there is no sibling node, pointer points to the node
1589 itself. In case of the first node, this pointer points to the last
1590 node in the list. */
1591 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001592 const char *dsc; /**< description */
1593 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001594 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001595 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001596 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001597
1598 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1599 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1600
Radek Krejci0e5d8382018-11-28 16:37:53 +01001601 const char *units; /**< units of the leaf's type */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001602 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values */
1603 struct lys_module **dflts_mods; /**< list ([sized array](@ref sizedarrays)) of modules where the lysc_node_leaflist::dflts values were defined
1604 (needed to correctly map prefixes). */
Radek Krejci0e5d8382018-11-28 16:37:53 +01001605 uint32_t min; /**< min-elements constraint */
1606 uint32_t max; /**< max-elements constraint */
1607
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001608};
1609
1610struct lysc_node_list {
1611 uint16_t nodetype; /**< LYS_LIST */
1612 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1613 struct lys_module *module; /**< module structure */
1614 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. */
1615 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1616 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1617 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1618 never NULL. If there is no sibling node, pointer points to the node
1619 itself. In case of the first node, this pointer points to the last
1620 node in the list. */
1621 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001622 const char *dsc; /**< description */
1623 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001624 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001625 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001626 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001627
1628 struct lysc_node *child; /**< first child node (linked list) */
1629 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1630 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1631 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1632
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001633 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1634 uint32_t min; /**< min-elements constraint */
1635 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001636};
1637
1638struct lysc_node_anydata {
1639 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1640 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1641 struct lys_module *module; /**< module structure */
1642 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. */
1643 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1644 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1645 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1646 never NULL. If there is no sibling node, pointer points to the node
1647 itself. In case of the first node, this pointer points to the last
1648 node in the list. */
1649 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001650 const char *dsc; /**< description */
1651 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001652 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001653 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001654 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9800fb82018-12-13 14:26:23 +01001655
1656 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001657};
1658
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001659/**
1660 * @brief Compiled YANG schema tree structure representing YANG module.
1661 *
1662 * Semantically validated YANG schema tree for data tree parsing.
1663 * Contains only the necessary information for the data validation.
1664 */
1665struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001666 struct lys_module *mod; /**< covering module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001667 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001668
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001669 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001670 struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1671 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1672 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1673 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001674 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko57c10cd2020-05-27 15:57:11 +02001675 struct lys_module **deviated_by; /**< List of modules that deviate this module ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001676};
1677
1678/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001679 * @brief Get the groupings sized array of the given (parsed) schema node.
1680 * Decides the node's type and in case it has a groupings array, returns it.
1681 * @param[in] node Node to examine.
1682 * @return The node's groupings sized array if any, NULL otherwise.
1683 */
1684const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1685
1686/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001687 * @brief Get the typedefs sized array of the given (parsed) schema node.
1688 * Decides the node's type and in case it has a typedefs array, returns it.
1689 * @param[in] node Node to examine.
1690 * @return The node's typedefs sized array if any, NULL otherwise.
1691 */
1692const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1693
1694/**
1695 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1696 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1697 * @param[in] node Node to examine.
1698 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1699 */
1700const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1701
1702/**
1703 * @brief Get the Notifications sized array of the given (parsed) schema node.
1704 * Decides the node's type and in case it has a Notifications array, returns it.
1705 * @param[in] node Node to examine.
1706 * @return The node's Notifications sized array if any, NULL otherwise.
1707 */
1708const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1709
1710/**
1711 * @brief Get the children linked list of the given (parsed) schema node.
1712 * Decides the node's type and in case it has a children list, returns it.
1713 * @param[in] node Node to examine.
1714 * @return The node's children linked list if any, NULL otherwise.
1715 */
1716const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1717
1718/**
1719 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1720 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1721 * @param[in] node Node to examine.
1722 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1723 */
1724const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1725
1726/**
1727 * @brief Get the Notifications sized array of the given (compiled) schema node.
1728 * Decides the node's type and in case it has a Notifications array, returns it.
1729 * @param[in] node Node to examine.
1730 * @return The node's Notifications sized array if any, NULL otherwise.
1731 */
1732const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1733
1734/**
1735 * @brief Get the children linked list of the given (compiled) schema node.
1736 * Decides the node's type and in case it has a children list, returns it.
1737 * @param[in] node Node to examine.
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001738 * @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 +01001739 * @return The node's children linked list if any, NULL otherwise.
1740 */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001741const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Radek Krejci056d0a82018-12-06 16:57:25 +01001742
1743/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001744 * @brief Get how the if-feature statement currently evaluates.
1745 *
1746 * @param[in] iff Compiled if-feature statement to evaluate.
Michal Vasko28d78432020-05-26 13:10:53 +02001747 * @return LY_SUCCESS if the statement evaluates to true,
1748 * @return LY_ENOT if it evaluates to false,
1749 * @return LY_ERR on error.
Radek Krejci151a5b72018-10-19 14:21:44 +02001750 */
Michal Vasko28d78432020-05-26 13:10:53 +02001751LY_ERR lysc_iffeature_value(const struct lysc_iffeature *iff);
Radek Krejci151a5b72018-10-19 14:21:44 +02001752
1753/**
1754 * @brief Get the current status of the provided feature.
1755 *
1756 * @param[in] feature Compiled feature statement to examine.
Michal Vasko28d78432020-05-26 13:10:53 +02001757 * @return LY_SUCCESS if feature is enabled,
1758 * @return LY_ENOT if feature is disabled,
1759 * @return LY_ERR in case of error (invalid argument)
Radek Krejci151a5b72018-10-19 14:21:44 +02001760 */
Michal Vasko28d78432020-05-26 13:10:53 +02001761LY_ERR lysc_feature_value(const struct lysc_feature *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001762
1763/**
Michal Vasko519fd602020-05-26 12:17:39 +02001764 * @brief Get all the schema nodes (atoms) that are required for \p xpath to be evaluated.
1765 *
1766 * @param[in] ctx_node XPath schema context node.
1767 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LYD_JSON format is expected.
1768 * @param[in] options Whether to apply some node access restrictions, one of the options should always be used.
1769 * If none is set, ::LYXP_SCNODE is used.
1770 * @param[out] set Set of found atoms (schema nodes).
1771 * @return LY_SUCCESS on success, @p set is returned.
1772 * @return LY_ERR value if an error occurred.
1773 */
1774LY_ERR lys_atomize_xpath(const struct lysc_node *ctx_node, const char *xpath, int options, struct ly_set **set);
1775
1776#define LYXP_SCNODE 0x02 /**< No special tree access modifiers. */
1777#define LYXP_SCNODE_SCHEMA 0x04 /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */
1778#define LYXP_SCNODE_OUTPUT 0x08 /**< Search RPC/action output nodes instead of input ones. */
1779
1780/**
Michal Vasko03ff5a72019-09-11 13:49:33 +02001781 * @brief Types of the different schema paths.
1782 */
1783typedef enum {
1784 LYSC_PATH_LOG /**< Descriptive path format used in log messages */
1785} LYSC_PATH_TYPE;
1786
1787/**
Radek Krejci327de162019-06-14 12:52:07 +02001788 * @brief Generate path of the given node in the requested format.
1789 *
1790 * @param[in] node Schema path of this node will be generated.
1791 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001792 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
1793 * If NULL, memory for the complete path is allocated.
1794 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02001795 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001796 * 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 +02001797 */
Michal Vasko03ff5a72019-09-11 13:49:33 +02001798char *lysc_path(const struct lysc_node *node, LYSC_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02001799
1800/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001801 * @brief Available YANG schema tree structures representing YANG module.
1802 */
1803struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001804 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
1805 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01001806 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001807 const char *ns; /**< namespace of the module (module - mandatory) */
1808 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
1809 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1810 const char *org; /**< party/company responsible for the module */
1811 const char *contact; /**< contact information for the module */
1812 const char *dsc; /**< description of the module */
1813 const char *ref; /**< cross-reference for the module */
1814
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001815 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01001816 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
1817 Available only for implemented modules. */
1818 struct lysc_feature *off_features;/**< List of pre-compiled features of the module in non implemented modules ([sized array](@ref sizedarrays)).
1819 These features are always disabled and cannot be enabled until the module
1820 become implemented. The features are present in this form to allow their linkage
1821 from if-feature statements of the compiled schemas and their proper use in case
1822 the module became implemented in future (no matter if implicitly via augment/deviate
1823 or explicitly via ly_ctx_module_implement()). */
Radek Krejci95710c92019-02-11 15:49:55 +01001824 uint8_t implemented; /**< flag if the module is implemented, not just imported. The module is implemented if
1825 the flag has non-zero value. Specific values are used internally:
1826 1 - implemented module
1827 2 - recently implemented module by dependency, it can be reverted in rollback procedure */
1828 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001829 1 - the latest revision in searchdirs was not searched yet and this is the
1830 latest revision in the current context
1831 2 - searchdirs were searched and this is the latest available revision */
1832 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001833};
1834
Radek Krejci151a5b72018-10-19 14:21:44 +02001835/**
1836 * @brief Enable specified feature in the module
1837 *
1838 * By default, when the module is loaded by libyang parser, all features are disabled.
1839 *
Radek Krejcica3db002018-11-01 10:31:01 +01001840 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
1841 * enabling all features on the following feature set will fail since it is not possible to enable both features
1842 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
1843 * is untouched.
1844 *
1845 * feature f1;
1846 * feature f2 { if-feature 'not f1';}
1847 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001848 * @param[in] module Module where the feature will be enabled.
1849 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
1850 * @return LY_ERR value.
1851 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001852LY_ERR lys_feature_enable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001853
1854/**
1855 * @brief Disable specified feature in the module
1856 *
1857 * By default, when the module is loaded by libyang parser, all features are disabled.
1858 *
1859 * @param[in] module Module where the feature will be disabled.
1860 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
1861 * @return LY_ERR value
1862 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001863LY_ERR lys_feature_disable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001864
1865/**
1866 * @brief Get the current status of the specified feature in the module.
1867 *
1868 * @param[in] module Module where the feature is defined.
1869 * @param[in] feature Name of the feature to inspect.
1870 * @return
1871 * - 1 if feature is enabled,
1872 * - 0 if feature is disabled,
1873 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
1874 */
1875int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001876
1877/**
Radek Krejci86d106e2018-10-18 09:53:19 +02001878 * @brief Load a schema into the specified context.
1879 *
1880 * @param[in] ctx libyang context where to process the data model.
1881 * @param[in] data The string containing the dumped data model in the specified
1882 * format.
1883 * @param[in] format Format of the input data (YANG or YIN).
1884 * @return Pointer to the data model structure or NULL on error.
1885 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001886struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001887
1888/**
1889 * @brief Read a schema from file descriptor into the specified context.
1890 *
1891 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
1892 *
1893 * @param[in] ctx libyang context where to process the data model.
1894 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
1895 * in the specified format.
1896 * @param[in] format Format of the input data (YANG or YIN).
1897 * @return Pointer to the data model structure or NULL on error.
1898 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001899struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001900
1901/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001902 * @brief Read a schema into the specified context from a file.
Radek Krejci86d106e2018-10-18 09:53:19 +02001903 *
1904 * @param[in] ctx libyang context where to process the data model.
1905 * @param[in] path Path to the file with the model in the specified format.
1906 * @param[in] format Format of the input data (YANG or YIN).
1907 * @return Pointer to the data model structure or NULL on error.
1908 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001909struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001910
1911/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001912 * @brief Search for the schema file in the specified searchpaths.
1913 *
1914 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
1915 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
1916 * result of the ly_ctx_get_searchdirs().
1917 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
1918 * @param[in] name Name of the schema to find.
1919 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
1920 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
1921 * complying the provided restriction is found, NULL is set.
1922 * @param[out] format Optional output variable containing expected format of the schema document according to the
1923 * file suffix.
1924 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
1925 */
1926LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
1927
1928/**
Radek Krejcia3045382018-11-22 14:30:31 +01001929 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
1930 * be from an augment.
1931 *
1932 * lys_getnext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
1933 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
1934 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
1935 * \p parent and \p module parameters.
1936 *
1937 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
1938 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
1939 * all the schema nodes are iteratively returned.
1940 *
1941 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
1942 * @param[in] parent Parent of the subtree where the function starts processing.
1943 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
1944 * module must be specified.
1945 * @param[in] options [ORed options](@ref sgetnextflags).
1946 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
1947 */
1948const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
1949 const struct lysc_module *module, int options);
1950
1951/**
1952 * @defgroup sgetnextflags lys_getnext() flags
Radek Krejcia3045382018-11-22 14:30:31 +01001953 * @{
1954 */
1955#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 +01001956#define LYS_GETNEXT_NOCHOICE 0x02 /**< lys_getnext() option to ignore (kind of conditional) nodes within choice node */
Radek Krejci056d0a82018-12-06 16:57:25 +01001957#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 +01001958#define LYS_GETNEXT_INTONPCONT 0x40 /**< lys_getnext() option to look into non-presence container, instead of returning container itself */
1959#define LYS_GETNEXT_NOSTATECHECK 0x100 /**< lys_getnext() option to skip checking module validity (import-only, disabled) and
1960 relevant if-feature conditions state */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001961#define LYS_GETNEXT_OUTPUT 0x200 /**< lys_getnext() option to provide RPC's/action's output schema nodes instead of input schema nodes
1962 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01001963/** @} sgetnextflags */
1964
1965/**
1966 * @brief Get child node according to the specified criteria.
1967 *
1968 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
1969 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
1970 * @param[in] name Name of the node to find.
1971 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
1972 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
1973 * Used as a bitmask, so multiple nodetypes can be specified.
1974 * @param[in] options [ORed options](@ref sgetnextflags).
1975 * @return Found node if any.
1976 */
Michal Vaskoe444f752020-02-10 12:20:06 +01001977const struct lysc_node *lys_find_child(const struct lysc_node *parent, const struct lys_module *module,
1978 const char *name, size_t name_len, uint16_t nodetype, int options);
Radek Krejcia3045382018-11-22 14:30:31 +01001979
1980/**
Radek Krejci09e8d0a2019-11-17 12:14:15 +08001981 * @brief Get schema node specified by the schema path.
1982 *
1983 * In case the @p qpath uses prefixes (from imports or of the schema itself), the @p context_node must be specified
1984 * even if the path is absolute. In case the @p context_node is not provided, the names of the schemas are expected as the
1985 * node's prefixes in the @qpath. It also means that the relative paths are accepted only with the schema prefixes,
1986 * not the full names.
1987 *
1988 * @param[in] ctx libyang context for logging and getting the correct schema if @p contet_node not provided.
1989 * @param[in] context_node Context node for relative paths and/or as a source of the context module to resolve node's
1990 * prefixes in @qpath.
1991 * @param[in] qpath Schema path to be resolved. Not prefixed nodes inherits the prefix from its parent nodes. It means
1992 * that the first node in the path must be prefixed. Both, import prefixes as well as full schema names are accepted as
1993 * prefixes according to the @p context_node parameter presence.
1994 * @return NULL in case of invalid path.
1995 * @return found schema node.
1996 */
1997const struct lysc_node *lys_find_node(struct ly_ctx *ctx, const struct lysc_node *context_node, const char *qpath);
1998
1999/**
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002000 * @brief Make the specific module implemented.
2001 *
2002 * @param[in] mod Module to make implemented. It is not an error
2003 * to provide already implemented module, it just does nothing.
Michal Vaskoe444f752020-02-10 12:20:06 +01002004 * @return LY_SUCCESS on success.
2005 * @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 +02002006 */
2007LY_ERR lys_set_implemented(struct lys_module *mod);
2008
2009/**
Radek Krejcia3045382018-11-22 14:30:31 +01002010 * @brief Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statement
2011 * affecting the node.
2012 *
2013 * @param[in] node Schema node to check.
2014 * @param[in] recursive - 0 to check if-feature only in the \p node schema node,
2015 * - 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 +01002016 * @return NULL if enabled,
Michal Vaskoc193ce92020-03-06 11:04:48 +01002017 * @return pointer to the node with the unsatisfied (disabled) if-feature expression.
Radek Krejcia3045382018-11-22 14:30:31 +01002018 */
Michal Vaskoc193ce92020-03-06 11:04:48 +01002019const struct lysc_node *lysc_node_is_disabled(const struct lysc_node *node, int recursive);
Radek Krejcia3045382018-11-22 14:30:31 +01002020
Radek Krejci084289f2019-07-09 17:35:30 +02002021/**
2022 * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
2023 *
2024 * This function check just the type's restriction, if you want to check also the data tree context (e.g. in case of
2025 * require-instance restriction), use lyd_value_validate().
2026 *
2027 * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
2028 * @param[in] node Schema node for the @p value.
2029 * @param[in] value String value to be checked.
2030 * @param[in] value_len Length of the given @p value (mandatory).
2031 * @param[in] get_prefix Callback function to resolve prefixes used in the @p value string.
2032 * @param[in] get_prefix_data Private data for the @p get_prefix callback.
2033 * @param[in] format Input format of the @p value.
2034 * @return LY_SUCCESS on success
2035 * @return LY_ERR value if an error occurred.
2036 */
Michal Vasko44685da2020-03-17 15:38:06 +01002037LY_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 +02002038 ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format);
2039
Radek Krejci0935f412019-08-20 16:15:18 +02002040/**
2041 * @brief Stringify schema nodetype.
2042 * @param[in] nodetype Nodetype to stringify.
2043 * @return Constant string with the name of the node's type.
2044 */
2045const char *lys_nodetype2str(uint16_t nodetype);
2046
Radek Krejci2ff0d572020-05-21 15:27:28 +02002047/** @} schematree */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002048
Radek Krejci70853c52018-10-15 14:46:16 +02002049#ifdef __cplusplus
2050}
2051#endif
2052
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002053#endif /* LY_TREE_SCHEMA_H_ */