blob: f27df916d32e6e7b71422829cdbe38f816439250 [file] [log] [blame]
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001/**
2 * @file tree_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief libyang representation of YANG schema trees.
5 *
6 * Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_TREE_SCHEMA_H_
16#define LY_TREE_SCHEMA_H_
17
Radek Krejci54579462019-04-30 12:47:06 +020018#define PCRE2_CODE_UNIT_WIDTH 8
19
20#include <pcre2.h>
Radek Krejci535ea9f2020-05-29 16:01:05 +020021
Radek Krejci5aeea3a2018-09-05 13:29:36 +020022#include <stdint.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020023#include <stdio.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020024
Radek Krejcie7b95092019-05-15 11:03:07 +020025#include "log.h"
26#include "tree.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020027#include "tree_data.h"
Radek Krejcice8c1592018-10-29 15:35:51 +010028
Radek Krejci70853c52018-10-15 14:46:16 +020029#ifdef __cplusplus
30extern "C" {
31#endif
32
Radek Krejcica376bd2020-06-11 16:04:06 +020033struct ly_ctx;
34struct ly_set;
35
Radek Krejci5aeea3a2018-09-05 13:29:36 +020036/**
Radek Krejci2ff0d572020-05-21 15:27:28 +020037 * @defgroup schematree Schema Tree
38 * @ingroup trees
39 * @{
40 *
41 * Data structures and functions to manipulate and access schema tree.
42 */
43
Michal Vasko64246d82020-08-19 12:35:00 +020044/* *INDENT-OFF* */
45
Radek Krejci2ff0d572020-05-21 15:27:28 +020046/**
Radek Krejci0935f412019-08-20 16:15:18 +020047 * @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 +020048 * (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 +020049 *
50 * The function follows deep-first search algorithm:
51 * <pre>
52 * 1
53 * / \
54 * 2 4
55 * / / \
56 * 3 5 6
57 * </pre>
58 *
59 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
60 * START can be any of the lysc_node* types (including lysc_action and lysc_notif),
61 * ELEM variable must be of the struct lysc_node* type.
62 *
63 * To skip a particular subtree, instead of the continue statement, set LYSC_TREE_DFS_continue
64 * variable to non-zero value.
65 *
66 * Use with opening curly bracket '{' after the macro.
67 *
68 * @param START Pointer to the starting element processed first.
69 * @param ELEM Iterator intended for use in the block.
70 */
71#define LYSC_TREE_DFS_BEGIN(START, ELEM) \
Radek Krejci857189e2020-09-01 13:26:36 +020072 { ly_bool LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
Michal Vasko1c9e79f2020-08-10 11:08:03 +020073 for ((ELEM) = (LYSC_TREE_DFS_next) = (struct lysc_node*)(START); \
Radek Krejci0935f412019-08-20 16:15:18 +020074 (ELEM); \
75 (ELEM) = (LYSC_TREE_DFS_next), LYSC_TREE_DFS_continue = 0)
76
77/**
78 * @brief Macro to iterate via all elements in a (sub)tree. This is the closing part
79 * to the #LYSC_TREE_DFS_BEGIN - they always have to be used together.
80 *
81 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
82 * START can be a pointer to any of the lysc_node* types (including lysc_action and lysc_notif),
83 * ELEM variable must be pointer to the lysc_node type.
84 *
85 * Use with closing curly bracket '}' after the macro.
86 *
87 * @param START Pointer to the starting element processed first.
88 * @param ELEM Iterator intended for use in the block.
89 */
90
91#define LYSC_TREE_DFS_END(START, ELEM) \
92 /* select element for the next run - children first */ \
93 if (LYSC_TREE_DFS_continue) { \
94 (LYSC_TREE_DFS_next) = NULL; \
95 } else { \
96 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, 0); \
97 }\
98 if (!(LYSC_TREE_DFS_next)) { \
99 /* in case of RPC/action, get also the output children */ \
Michal Vasko1bf09392020-03-27 12:38:10 +0100100 if (!LYSC_TREE_DFS_continue && (ELEM)->nodetype & (LYS_RPC | LYS_ACTION)) { \
Radek Krejci0935f412019-08-20 16:15:18 +0200101 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, LYS_CONFIG_R); \
102 } \
103 if (!(LYSC_TREE_DFS_next)) { \
104 /* no children */ \
105 if ((ELEM) == (struct lysc_node*)(START)) { \
106 /* we are done, (START) has no children */ \
107 break; \
108 } \
109 /* try siblings */ \
110 (LYSC_TREE_DFS_next) = (ELEM)->next; \
111 } \
112 } \
113 while (!(LYSC_TREE_DFS_next)) { \
114 /* parent is already processed, go to its sibling */ \
115 (ELEM) = (ELEM)->parent; \
116 /* no siblings, go back through parents */ \
117 if ((ELEM) == (struct lysc_node*)(START)) { \
118 /* we are done, no next element to process */ \
119 break; \
120 } \
Michal Vasko1bf09392020-03-27 12:38:10 +0100121 if ((ELEM)->nodetype & (LYS_RPC | LYS_ACTION)) { \
Radek Krejci0935f412019-08-20 16:15:18 +0200122 /* there is actually next node as a child of action's output */ \
123 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, LYS_CONFIG_R); \
124 } \
125 if (!(LYSC_TREE_DFS_next)) { \
126 (LYSC_TREE_DFS_next) = (ELEM)->next; \
127 } \
128 } } \
129
Michal Vasko64246d82020-08-19 12:35:00 +0200130/* *INDENT-ON* */
131
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200132#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
133
Michal Vasko7f45cf22020-10-01 12:49:44 +0200134#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
135#define LYS_CONTAINER 0x0001 /**< container statement node */
136#define LYS_CHOICE 0x0002 /**< choice statement node */
137#define LYS_LEAF 0x0004 /**< leaf statement node */
138#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
139#define LYS_LIST 0x0010 /**< list statement node */
140#define LYS_ANYXML 0x0020 /**< anyxml statement node */
141#define LYS_ANYDATA 0x0060 /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
142#define LYS_CASE 0x0080 /**< case statement node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200143
Michal Vasko7f45cf22020-10-01 12:49:44 +0200144#define LYS_RPC 0x0100 /**< RPC statement node */
145#define LYS_ACTION 0x0200 /**< action statement node */
146#define LYS_NOTIF 0x0400 /**< notification statement node */
Radek Krejcie7b95092019-05-15 11:03:07 +0200147
Michal Vasko7f45cf22020-10-01 12:49:44 +0200148#define LYS_USES 0x0800 /**< uses statement node */
149#define LYS_INPUT 0x1000 /**< RPC/action input node */
150#define LYS_OUTPUT 0x2000 /**< RPC/action output node */
151#define LYS_GROUPING 0x4000
152#define LYS_AUGMENT 0x8000
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100153
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200154/**
Radek Krejcid6b76452019-09-03 17:03:03 +0200155 * @brief List of YANG statements
156 */
157enum ly_stmt {
158 LY_STMT_NONE = 0,
Radek Krejciad5963b2019-09-06 16:03:05 +0200159 LY_STMT_STATUS, /**< in lysc_ext_substmt::storage stored as a pointer to `uint16_t`, only cardinality < #LY_STMT_CARD_SOME is allowed */
160 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 +0200161 LY_STMT_MANDATORY,
Radek Krejciad5963b2019-09-06 16:03:05 +0200162 LY_STMT_UNITS, /**< in lysc_ext_substmt::storage stored as a pointer to `const char *` (cardinality < #LY_STMT_CARD_SOME)
163 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200164 LY_STMT_DEFAULT,
Radek Krejciad5963b2019-09-06 16:03:05 +0200165 LY_STMT_TYPE, /**< in lysc_ext_substmt::storage stored as a pointer to `struct lysc_type *` (cardinality < #LY_STMT_CARD_SOME)
166 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_type **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200167
Radek Krejcid6b76452019-09-03 17:03:03 +0200168 LY_STMT_ACTION,
169 LY_STMT_ANYDATA,
170 LY_STMT_ANYXML,
171 LY_STMT_ARGUMENT,
172 LY_STMT_AUGMENT,
173 LY_STMT_BASE,
174 LY_STMT_BELONGS_TO,
175 LY_STMT_BIT,
176 LY_STMT_CASE,
177 LY_STMT_CHOICE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200178 LY_STMT_CONTACT,
179 LY_STMT_CONTAINER,
Radek Krejcid6b76452019-09-03 17:03:03 +0200180 LY_STMT_DESCRIPTION,
181 LY_STMT_DEVIATE,
182 LY_STMT_DEVIATION,
183 LY_STMT_ENUM,
184 LY_STMT_ERROR_APP_TAG,
185 LY_STMT_ERROR_MESSAGE,
186 LY_STMT_EXTENSION,
187 LY_STMT_FEATURE,
188 LY_STMT_FRACTION_DIGITS,
189 LY_STMT_GROUPING,
190 LY_STMT_IDENTITY,
Radek Krejciad5963b2019-09-06 16:03:05 +0200191 LY_STMT_IF_FEATURE, /**< in lysc_ext_substmt::storage stored as a pointer to `struct lysc_iffeature` (cardinality < #LY_STMT_CARD_SOME)
192 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_iffeature *` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200193 LY_STMT_IMPORT,
194 LY_STMT_INCLUDE,
195 LY_STMT_INPUT,
196 LY_STMT_KEY,
197 LY_STMT_LEAF,
198 LY_STMT_LEAF_LIST,
199 LY_STMT_LENGTH,
200 LY_STMT_LIST,
Radek Krejcid6b76452019-09-03 17:03:03 +0200201 LY_STMT_MAX_ELEMENTS,
202 LY_STMT_MIN_ELEMENTS,
203 LY_STMT_MODIFIER,
204 LY_STMT_MODULE,
205 LY_STMT_MUST,
206 LY_STMT_NAMESPACE,
207 LY_STMT_NOTIFICATION,
208 LY_STMT_ORDERED_BY,
209 LY_STMT_ORGANIZATION,
210 LY_STMT_OUTPUT,
211 LY_STMT_PATH,
212 LY_STMT_PATTERN,
213 LY_STMT_POSITION,
214 LY_STMT_PREFIX,
215 LY_STMT_PRESENCE,
216 LY_STMT_RANGE,
217 LY_STMT_REFERENCE,
218 LY_STMT_REFINE,
219 LY_STMT_REQUIRE_INSTANCE,
220 LY_STMT_REVISION,
221 LY_STMT_REVISION_DATE,
222 LY_STMT_RPC,
Radek Krejcid6b76452019-09-03 17:03:03 +0200223 LY_STMT_SUBMODULE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200224 LY_STMT_TYPEDEF,
225 LY_STMT_UNIQUE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200226 LY_STMT_USES,
227 LY_STMT_VALUE,
228 LY_STMT_WHEN,
229 LY_STMT_YANG_VERSION,
230 LY_STMT_YIN_ELEMENT,
231 LY_STMT_EXTENSION_INSTANCE,
232
233 LY_STMT_SYNTAX_SEMICOLON,
234 LY_STMT_SYNTAX_LEFT_BRACE,
235 LY_STMT_SYNTAX_RIGHT_BRACE,
236
237 LY_STMT_ARG_TEXT,
238 LY_STMT_ARG_VALUE
239};
240
241/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200242 * @brief Extension instance structure parent enumeration
243 */
244typedef enum {
Radek Krejci0935f412019-08-20 16:15:18 +0200245 LYEXT_PAR_MODULE, /**< ::lysc_module */
246 LYEXT_PAR_NODE, /**< ::lysc_node (and the derived structures including ::lysc_action and ::lysc_notif) */
247 LYEXT_PAR_INPUT, /**< ::lysc_action_inout */
248 LYEXT_PAR_OUTPUT, /**< ::lysc_action_inout */
249 LYEXT_PAR_TYPE, /**< ::lysc_type */
250 LYEXT_PAR_TYPE_BIT, /**< ::lysc_type_bitenum_item */
251 LYEXT_PAR_TYPE_ENUM, /**< ::lysc_type_bitenum_item */
252 LYEXT_PAR_FEATURE, /**< ::lysc_feature */
253 LYEXT_PAR_MUST, /**< ::lysc_must */
254 LYEXT_PAR_PATTERN, /**< ::lysc_pattern */
255 LYEXT_PAR_LENGTH, /**< ::lysc_range */
256 LYEXT_PAR_RANGE, /**< ::lysc_range */
257 LYEXT_PAR_WHEN, /**< ::lysc_when */
258 LYEXT_PAR_IDENT, /**< ::lysc_ident */
259 LYEXT_PAR_EXT, /**< ::lysc_ext */
Michal Vasko7c8439f2020-08-05 13:25:19 +0200260 LYEXT_PAR_IMPORT, /**< ::lysp_import */
Michal Vasko033278d2020-08-24 11:24:52 +0200261// LYEXT_PAR_TPDF, /**< ::lysp_tpdf */
262// LYEXT_PAR_EXTINST, /**< ::lysp_ext_instance */
263// LYEXT_PAR_REFINE, /**< ::lysp_refine */
264// LYEXT_PAR_DEVIATION, /**< ::lysp_deviation */
265// LYEXT_PAR_DEVIATE, /**< ::lysp_deviate */
266// LYEXT_PAR_INCLUDE, /**< ::lysp_include */
267// LYEXT_PAR_REVISION, /**< ::lysp_revision */
Radek Krejci0e59c312019-08-15 15:34:15 +0200268} LYEXT_PARENT;
269
270/**
Radek Krejci0935f412019-08-20 16:15:18 +0200271 * @brief Stringify extension instance parent type.
272 * @param[in] type Parent type to stringify.
273 * @return Constant string with the name of the parent statement.
274 */
275const char *lyext_parent2str(LYEXT_PARENT type);
276
277/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200278 * @brief Enum of substatements in which extension instances can appear.
279 */
280typedef enum {
281 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
282 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
283 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
284 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
285 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
286 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
287 lys_node_choice and lys_deviate */
288 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
289 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
290 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
291 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
292 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
293 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
294 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
295 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
296 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
297 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
298 belongs-to's prefix) and lys_import */
299 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
300 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
301 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
302 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
303 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
304 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
305 lys_node_leaflist and lys_deviate */
306 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
307 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
308 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
309 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
310 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
311 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
312 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
313 lys_node_anydata and lys_deviate */
314 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
315 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
316 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
317 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
318 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
319 lys_node_leaflist and lys_deviate */
320 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
321 lys_node_leaflist and lys_deviate */
322 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
323 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
324 LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */
325} LYEXT_SUBSTMT;
326
327/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200328 * @brief YANG import-stmt
329 */
330struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200331 struct lys_module *module; /**< pointer to the imported module
332 (mandatory, but resolved when the referring module is completely parsed) */
333 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200334 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200335 const char *dsc; /**< description */
336 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200337 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200338 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
339};
340
341/**
342 * @brief YANG include-stmt
343 */
344struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100345 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200346 (mandatory, but resolved when the referring module is completely parsed) */
347 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200348 const char *dsc; /**< description */
349 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200350 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200351 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
352};
353
354/**
355 * @brief YANG extension-stmt
356 */
357struct lysp_ext {
358 const char *name; /**< extension name */
359 const char *argument; /**< argument name, NULL if not specified */
360 const char *dsc; /**< description statement */
361 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200362 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200363 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */
Michal Vasko5fe75f12020-03-02 13:52:37 +0100364
365 struct lysc_ext *compiled; /**< pointer to the compiled extension definition */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200366};
367
368/**
369 * @brief Helper structure for generic storage of the extension instances content.
370 */
371struct lysp_stmt {
372 const char *stmt; /**< identifier of the statement */
373 const char *arg; /**< statement's argument */
374 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200375 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
David Sedlákb9d75c42019-08-14 10:49:42 +0200376 uint16_t flags; /**< statement flags, can be set to LYS_YIN_ATTR */
Radek Krejci335332a2019-09-05 13:03:35 +0200377 enum ly_stmt kw; /**< numeric respresentation of the stmt value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200378};
379
David Sedlákae4b4512019-08-14 10:45:56 +0200380#define LYS_YIN 0x1 /**< used to specify input format of extension instance */
381
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200382/**
383 * @brief YANG extension instance
384 */
385struct lysp_ext_instance {
David Sedlákbbd06ca2019-06-27 14:15:38 +0200386 const char *name; /**< extension identifier, including possible prefix */
387 const char *argument; /**< optional value of the extension's argument */
Radek Krejci335332a2019-09-05 13:03:35 +0200388 void *parent; /**< pointer to the parent element holding the extension instance(s), use
389 ::lysp_ext_instance#parent_type to access the schema element */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200390 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200391 struct lysc_ext_instance *compiled; /**< pointer to the compiled data if any - in case the source format is YIN,
392 some of the information (argument) are available only after compilation */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200393 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200394 LY_ARRAY_COUNT_TYPE insubstmt_index; /**< in case the instance is in a substatement, this identifies
David Sedlákbbd06ca2019-06-27 14:15:38 +0200395 the index of that substatement */
David Sedlákae4b4512019-08-14 10:45:56 +0200396 uint8_t yin; /** flag for YIN source format, can be set to LYS_YIN */
Radek Krejci335332a2019-09-05 13:03:35 +0200397 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200398};
399
400/**
401 * @brief YANG feature-stmt
402 */
403struct lysp_feature {
404 const char *name; /**< feature name (mandatory) */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200405 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200406 const char *dsc; /**< description statement */
407 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200408 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200409 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
410};
411
412/**
Michal Vasko7f45cf22020-10-01 12:49:44 +0200413 * @brief Qualified name (optional prefix followed by an identifier).
414 */
415struct lysp_qname {
416 const char *str; /**< qualified name string */
417 const struct lys_module *mod; /**< local module for any prefixes found in the string, it must be
418 stored explicitly because of deviations/refines */
419};
420
421/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200422 * @brief YANG identity-stmt
423 */
424struct lysp_ident {
425 const char *name; /**< identity name (mandatory), including possible prefix */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200426 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200427 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200428 const char *dsc; /**< description statement */
429 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200430 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200431 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
432};
433
Michal Vasko71e64ca2018-09-07 16:30:29 +0200434/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200435 * @brief Covers restrictions: range, length, pattern, must
436 */
437struct lysp_restr {
Michal Vasko7f45cf22020-10-01 12:49:44 +0200438 struct lysp_qname arg; /**< The restriction expression/value (mandatory);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200439 in case of pattern restriction, the first byte has a special meaning:
440 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
441 const char *emsg; /**< error-message */
442 const char *eapptag; /**< error-app-tag value */
443 const char *dsc; /**< description */
444 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200445 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200446};
447
448/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200449 * @brief YANG revision-stmt
450 */
451struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200452 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200453 const char *dsc; /**< description statement */
454 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200455 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200456};
457
458/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200459 * @brief Enumeration/Bit value definition
460 */
461struct lysp_type_enum {
462 const char *name; /**< name (mandatory) */
463 const char *dsc; /**< description statement */
464 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200465 int64_t value; /**< enum's value or bit's position */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200466 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200467 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200468 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
469 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200470};
471
472/**
473 * @brief YANG type-stmt
474 *
475 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
476 */
477struct lysp_type {
478 const char *name; /**< name of the type (mandatory) */
479 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
480 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200481 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
482 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
483 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Michal Vasko004d3152020-06-11 19:59:22 +0200484 struct lyxp_expr *path; /**< parsed path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200485 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200486 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
487 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200488
Radek Krejci2167ee12018-11-02 16:09:07 +0100489 struct lysc_type *compiled; /**< pointer to the compiled type */
490
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200491 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
492 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100493 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200494};
495
496/**
497 * @brief YANG typedef-stmt
498 */
499struct lysp_tpdf {
500 const char *name; /**< name of the newly defined type (mandatory) */
501 const char *units; /**< units of the newly defined type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200502 struct lysp_qname dflt; /**< default value of the newly defined type, it may or may not be a qualified name */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200503 const char *dsc; /**< description statement */
504 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200505 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200506 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100507 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200508};
509
510/**
511 * @brief YANG grouping-stmt
512 */
513struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100514 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
515 uint16_t nodetype; /**< LYS_GROUPING */
516 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200517 const char *name; /**< grouping name (mandatory) */
518 const char *dsc; /**< description statement */
519 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200520 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
521 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200522 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200523 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
524 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
525 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200526};
527
528/**
529 * @brief YANG when-stmt
530 */
531struct lysp_when {
532 const char *cond; /**< specified condition (mandatory) */
533 const char *dsc; /**< description statement */
534 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200535 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200536};
537
538/**
539 * @brief YANG refine-stmt
540 */
541struct lysp_refine {
542 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
543 const char *dsc; /**< description statement */
544 const char *ref; /**< reference statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200545 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200546 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200547 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200548 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200549 uint32_t min; /**< min-elements constraint */
550 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200551 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200552 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
553};
554
555/**
Michal Vasko82a83432019-11-14 12:33:04 +0100556 * @brief YANG uses-augment-stmt and augment-stmt (compatible with struct lysp_node )
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200557 */
558struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100559 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
560 uint16_t nodetype; /**< LYS_AUGMENT */
561 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Michal Vasko82a83432019-11-14 12:33:04 +0100562 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200563 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
564 const char *dsc; /**< description statement */
565 const char *ref; /**< reference statement */
566 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200567 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Michal Vasko82a83432019-11-14 12:33:04 +0100568 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200569 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
570 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200571};
572
573/**
574 * @defgroup deviatetypes Deviate types
575 * @{
576 */
577#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
578#define LYS_DEV_ADD 2 /**< deviate type add */
579#define LYS_DEV_DELETE 3 /**< deviate type delete */
580#define LYS_DEV_REPLACE 4 /**< deviate type replace */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200581/** @} deviatetypes */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200582
583/**
584 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
585 */
586struct lysp_deviate {
587 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
588 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200589 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200590};
591
592struct lysp_deviate_add {
593 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
594 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200595 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200596 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200597 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200598 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
599 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200600 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
601 uint32_t min; /**< min-elements constraint */
602 uint32_t max; /**< max-elements constraint, 0 means unbounded */
603};
604
605struct lysp_deviate_del {
606 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
607 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200608 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200609 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200610 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200611 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
612 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200613};
614
615struct lysp_deviate_rpl {
616 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
617 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200618 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200619 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200620 const char *units; /**< units of the values */
621 const char *dflt; /**< default value */
622 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
623 uint32_t min; /**< min-elements constraint */
624 uint32_t max; /**< max-elements constraint, 0 means unbounded */
625};
626
627struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200628 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200629 const char *dsc; /**< description statement */
630 const char *ref; /**< reference statement */
Michal Vasko22df3f02020-08-24 13:29:22 +0200631 struct lysp_deviate *deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200632 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200633};
634
Radek Krejci4f28eda2018-11-12 11:46:16 +0100635/**
636 * @defgroup spnodeflags Parsed schema nodes flags
637 * @ingroup snodeflags
638 *
639 * Various flags for parsed schema nodes.
640 *
641 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
642 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200643 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100644 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
645 * 5 - list 10 - input 15 - typedef 20 - deviate
646 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200647 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
648 * 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
649 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200650 * 1 LYS_CONFIG_W |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200651 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
652 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200653 * 2 LYS_CONFIG_R |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200654 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
655 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
656 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
657 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
658 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
659 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
660 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
661 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
662 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
663 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
664 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
665 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
666 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
667 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
668 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
669 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
670 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
671 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
672 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
673 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
674 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
675 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
676 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
677 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
678 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
679 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
680 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
681 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
682 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
683 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
684 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
685 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200686 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
David Sedlákae4b4512019-08-14 10:45:56 +0200687 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x|
Michal Vasko5297a432020-08-31 12:27:51 +0200688 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
689 * 12 LYS_YIN_ARGUMENT | | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejcif56e2a42019-09-09 14:15:25 +0200690 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100691 *
692 */
693
694/**
695 * @defgroup scnodeflags Compiled schema nodes flags
696 * @ingroup snodeflags
697 *
698 * Various flags for compiled schema nodes.
699 *
Radek Krejci61e042e2019-09-10 15:53:09 +0200700 * 1 - container 6 - anydata/anyxml 11 - identity
701 * 2 - choice 7 - case 12 - extension
702 * 3 - leaf 8 - notification 13 - bitenum
Michal Vasko03ff5a72019-09-11 13:49:33 +0200703 * 4 - leaflist 9 - rpc/action 14 - when
Michal Vaskoecd62de2019-11-13 12:35:11 +0100704 * 5 - list 10 - feature
Radek Krejci4f28eda2018-11-12 11:46:16 +0100705 *
Michal Vaskoecd62de2019-11-13 12:35:11 +0100706 * 1 1 1 1 1
707 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
708 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
709 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | |
710 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
711 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | |
712 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
713 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x|x|x|x| |x|
714 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
715 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x|x|x|x| |x|
716 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
717 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x|x|x|x| |x|
718 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
719 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
720 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
721 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
722 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | |
723 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
724 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
725 * LYS_PRESENCE |x| | | | | | | | | | | | | |
726 * LYS_UNIQUE | | |x| | | | | | | | | | | |
727 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
728 * 9 LYS_KEY | | |x| | | | | | | | | | | |
729 * LYS_FENABLED | | | | | | | | | |x| | | | |
730 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
731 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
732 * LYS_ISENUM | | | | | | | | | | | | |x| |
733 * LYS_KEYLESS | | | | |x| | | | | | | | | |
734 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
735 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
736 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
737 * 12 LYS_SET_CONFIG |x|x|x|x|x|x| | | | | | | | |
738 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100739 *
740 */
741
742/**
743 * @defgroup snodeflags Schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100744 * @{
745 */
Michal Vasko1bf09392020-03-27 12:38:10 +0100746#define LYS_CONFIG_W 0x01 /**< config true; also set for input children nodes */
747#define LYS_CONFIG_R 0x02 /**< config false; also set for output and notification children nodes */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200748#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100749#define LYS_STATUS_CURR 0x04 /**< status current; */
750#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
751#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
752#define LYS_STATUS_MASK 0x1C /**< mask for status value */
753#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100754 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
755 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
756 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
757 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100758#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
759 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
760 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100761#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Michal Vaskoc118ae22020-08-06 14:51:09 +0200762#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, but it is not only for explicit presence
763 containers, but also for NP containers with some meaning, applicable only to
764 ::lysc_node_container */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100765#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
766#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 +0200767#define LYS_KEYLESS 0x200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100768#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysc_feature */
Radek Krejcife909632019-02-12 15:34:42 +0100769#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 +0100770 ::lysc_node_list/::lysp_node_list */
771#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
772 ::lysc_node_list/::lysp_node_list */
773#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
774#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
775#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
776#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200777#define LYS_USED_GRP 0x400 /**< internal flag for validating not-instantiated groupings
778 (resp. do not validate again the instantiated groupings). */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100779#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100780#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200781#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100782
783#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
784#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
785#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
786#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
787#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
788#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
789#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
790#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
791#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
792#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100793#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 +0100794 cases of choice. This information is important for refines, since it is prohibited to make leafs
795 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100796 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
797 between own default or the default values taken from the type. */
798#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 +0100799#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 +0100800
Radek Krejcif56e2a42019-09-09 14:15:25 +0200801#define LYS_SINGLEQUOTED 0x100 /**< flag for single-quoted argument of an extension instance's substatement, only when the source is YANG */
802#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 +0200803
Radek Krejcif56e2a42019-09-09 14:15:25 +0200804#define LYS_YIN_ATTR 0x400 /**< flag to identify YIN attribute parsed as extension's substatement, only when the source is YIN */
805#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 +0200806
Radek Krejci693262f2019-04-29 15:23:20 +0200807#define LYS_ISENUM 0x200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
808
Radek Krejcife909632019-02-12 15:34:42 +0100809#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200810/** @} snodeflags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200811
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200812/**
813 * @brief Generic YANG data node
814 */
815struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100816 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200817 uint16_t nodetype; /**< type of the node (mandatory) */
818 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100819 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200820 const char *name; /**< node name (mandatory) */
821 const char *dsc; /**< description statement */
822 const char *ref; /**< reference statement */
823 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200824 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)),
825 must be qname because of refines */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200826 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200827};
828
829/**
830 * @brief Extension structure of the lysp_node for YANG container
831 */
832struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100833 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200834 uint16_t nodetype; /**< LYS_CONTAINER */
835 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
836 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
837 const char *name; /**< node name (mandatory) */
838 const char *dsc; /**< description statement */
839 const char *ref; /**< reference statement */
840 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200841 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200842 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200843
844 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200845 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200846 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200847 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
848 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200849 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200850 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
851 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200852};
853
854struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100855 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200856 uint16_t nodetype; /**< LYS_LEAF */
857 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
858 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
859 const char *name; /**< node name (mandatory) */
860 const char *dsc; /**< description statement */
861 const char *ref; /**< reference statement */
862 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200863 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200864 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200865
866 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200867 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200868 struct lysp_type type; /**< type of the leaf node (mandatory) */
869 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200870 struct lysp_qname dflt; /**< default value, it may or may not be a qualified name */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200871};
872
873struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100874 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200875 uint16_t nodetype; /**< LYS_LEAFLIST */
876 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
877 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
878 const char *name; /**< node name (mandatory) */
879 const char *dsc; /**< description statement */
880 const char *ref; /**< reference statement */
881 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200882 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200883 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200884
885 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200886 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200887 struct lysp_type type; /**< type of the leaf node (mandatory) */
888 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200889 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)), they may or
890 may not be qualified names */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200891 uint32_t min; /**< min-elements constraint */
892 uint32_t max; /**< max-elements constraint, 0 means unbounded */
893};
894
895struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100896 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200897 uint16_t nodetype; /**< LYS_LIST */
898 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
899 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
900 const char *name; /**< node name (mandatory) */
901 const char *dsc; /**< description statement */
902 const char *ref; /**< reference statement */
903 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200904 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200905 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200906
907 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200908 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200909 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200910 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
911 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200912 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200913 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
914 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200915 struct lysp_qname *uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200916 uint32_t min; /**< min-elements constraint */
917 uint32_t max; /**< max-elements constraint, 0 means unbounded */
918};
919
920struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100921 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200922 uint16_t nodetype; /**< LYS_CHOICE */
923 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
924 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
925 const char *name; /**< node name (mandatory) */
926 const char *dsc; /**< description statement */
927 const char *ref; /**< reference statement */
928 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200929 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200930 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200931
932 /* choice */
933 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200934 struct lysp_qname dflt; /**< default case */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200935};
936
937struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100938 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200939 uint16_t nodetype; /**< LYS_CASE */
940 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
941 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
942 const char *name; /**< node name (mandatory) */
943 const char *dsc; /**< description statement */
944 const char *ref; /**< reference statement */
945 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200946 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200947 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200948
949 /* case */
950 struct lysp_node *child; /**< list of data nodes (linked list) */
951};
952
953struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100954 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200955 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200956 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
957 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
958 const char *name; /**< node name (mandatory) */
959 const char *dsc; /**< description statement */
960 const char *ref; /**< reference statement */
961 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200962 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200963 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200964
965 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200966 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200967};
968
969struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100970 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200971 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200972 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
973 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
974 const char *name; /**< grouping name reference (mandatory) */
975 const char *dsc; /**< description statement */
976 const char *ref; /**< reference statement */
977 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200978 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200979 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200980
981 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200982 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
983 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200984};
985
986/**
987 * @brief YANG input-stmt and output-stmt
988 */
989struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100990 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200991 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200992 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
993 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
994 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200995 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200996 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200997};
998
999/**
1000 * @brief YANG rpc-stmt and action-stmt
1001 */
1002struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001003 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko1bf09392020-03-27 12:38:10 +01001004 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001005 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001006 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001007 const char *name; /**< grouping name reference (mandatory) */
1008 const char *dsc; /**< description statement */
1009 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001010 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001011 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1012 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1013
1014 /* action */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001015 struct lysp_action_inout input; /**< RPC's/Action's input */
1016 struct lysp_action_inout output; /**< RPC's/Action's output */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001017};
1018
1019/**
1020 * @brief YANG notification-stmt
1021 */
1022struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001023 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1024 uint16_t nodetype; /**< LYS_NOTIF */
1025 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001026 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001027 const char *name; /**< grouping name reference (mandatory) */
1028 const char *dsc; /**< description statement */
1029 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001030 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001031 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001032 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001033
1034 /* notif */
1035 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1036 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001037};
1038
1039/**
Radek Krejcif0fceb62018-09-05 14:58:45 +02001040 * @brief supported YANG schema version values
1041 */
1042typedef enum LYS_VERSION {
1043 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
Radek Krejci96e48da2020-09-04 13:18:06 +02001044 LYS_VERSION_1_0 = 1, /**< YANG 1 (1.0) */
Radek Krejcif0fceb62018-09-05 14:58:45 +02001045 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
1046} LYS_VERSION;
1047
1048/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001049 * @brief Printable YANG schema tree structure representing YANG module.
1050 *
1051 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
1052 */
1053struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001054 struct lys_module *mod; /**< covering module structure */
1055
Radek Krejcib7db73a2018-10-24 14:18:40 +02001056 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1057 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001058 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1059 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001060 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1061 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1062 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1063 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1064 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001065 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001066 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1067 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1068 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1069 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
1070 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001071
Radek Krejci0f969882020-08-21 16:56:47 +02001072 uint8_t parsing : 1; /**< flag for circular check */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001073};
1074
1075struct lysp_submodule {
1076 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
1077
1078 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1079 in the list is always the last (newest) revision of the module */
1080 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1081 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
1082 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1083 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1084 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1085 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1086 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
1087 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
1088 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1089 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1090 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1091 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
1092 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1093
Radek Krejci0f969882020-08-21 16:56:47 +02001094 uint8_t parsing : 1; /**< flag for circular check */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001095
Radek Krejci0f969882020-08-21 16:56:47 +02001096 uint8_t latest_revision : 2; /**< flag to mark the latest available revision:
Radek Krejci086c7132018-10-26 15:29:04 +02001097 1 - the latest revision in searchdirs was not searched yet and this is the
1098 latest revision in the current context
1099 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001100 const char *name; /**< name of the module (mandatory) */
1101 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1102 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
1103 const char *org; /**< party/company responsible for the module */
1104 const char *contact; /**< contact information for the module */
1105 const char *dsc; /**< description of the module */
1106 const char *ref; /**< cross-reference for the module */
Radek Krejci086c7132018-10-26 15:29:04 +02001107 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001108};
1109
1110/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +02001111 * @brief Free the printable YANG schema tree structure.
1112 *
1113 * @param[in] module Printable YANG schema tree structure to free.
1114 */
1115void lysp_module_free(struct lysp_module *module);
1116
1117/**
Radek Krejci535ea9f2020-05-29 16:01:05 +02001118 * @defgroup scflags Schema compile flags
1119 * @ingroup schematree
1120 *
1121 * @{
1122 */
1123#define LYSC_OPT_RPC_INPUT LYS_CONFIG_W /**< Internal option when compiling schema tree of RPC/action input */
1124#define LYSC_OPT_RPC_OUTPUT LYS_CONFIG_R /**< Internal option when compiling schema tree of RPC/action output */
1125#define LYSC_OPT_RPC_MASK LYS_CONFIG_MASK /**< mask for the internal RPC options */
1126#define LYSC_OPT_FREE_SP 0x04 /**< Free the input printable schema */
Michal Vasko89b5c072020-10-06 13:52:44 +02001127#define LYSC_OPT_NOTIFICATION 0x08 /**< Internal option when compiling schema tree of Notification */
Radek Krejci535ea9f2020-05-29 16:01:05 +02001128
Michal Vasko89b5c072020-10-06 13:52:44 +02001129#define LYSC_OPT_GROUPING 0x10 /** Compiling (validation) of a non-instantiated grouping.
Radek Krejci535ea9f2020-05-29 16:01:05 +02001130 In this case not all the restrictions are checked since they can be valid only
1131 in the real placement of the grouping. TODO - what specifically is not done */
1132/** @} scflags */
1133
1134/**
Radek Krejci0e59c312019-08-15 15:34:15 +02001135 * @brief Compiled YANG extension-stmt
1136 */
1137struct lysc_ext {
1138 const char *name; /**< extension name */
1139 const char *argument; /**< argument name, NULL if not specified */
Radek Krejci0e59c312019-08-15 15:34:15 +02001140 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1141 struct lyext_plugin *plugin; /**< Plugin implementing the specific extension */
Radek Krejci0935f412019-08-20 16:15:18 +02001142 struct lys_module *module; /**< module structure */
Michal Vasko6f4cbb62020-02-28 11:15:47 +01001143 uint32_t refcount; /**< reference counter since extension definition is shared among all its instances */
Radek Krejci0e59c312019-08-15 15:34:15 +02001144 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
1145};
1146
1147/**
Radek Krejcice8c1592018-10-29 15:35:51 +01001148 * @brief YANG extension instance
1149 */
1150struct lysc_ext_instance {
Radek Krejciad5963b2019-09-06 16:03:05 +02001151 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
1152 this identifies the index of the substatement for this extension instance */
Radek Krejci28681fa2019-09-06 13:08:45 +02001153 struct lys_module *module; /**< module where the extension instantiated is defined */
Radek Krejciad5963b2019-09-06 16:03:05 +02001154 struct lysc_ext *def; /**< pointer to the extension definition */
Radek Krejcice8c1592018-10-29 15:35:51 +01001155 void *parent; /**< pointer to the parent element holding the extension instance(s), use
1156 ::lysc_ext_instance#parent_type to access the schema element */
1157 const char *argument; /**< optional value of the extension's argument */
1158 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +01001159 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001160 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0e59c312019-08-15 15:34:15 +02001161 void *data; /**< private plugins's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +01001162};
1163
1164/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001165 * @brief Compiled YANG if-feature-stmt
1166 */
1167struct lysc_iffeature {
1168 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
1169 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
1170};
1171
1172/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001173 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001174 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001175struct lysc_when {
Radek Krejcia0f704a2019-09-09 16:12:23 +02001176 struct lys_module *module; /**< module where the must was defined */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001177 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko175012e2019-11-06 15:49:14 +01001178 struct lysc_node *context; /**< context node for evaluating the expression, NULL if the context is root node */
Radek Krejcic8b31002019-01-08 10:24:45 +01001179 const char *dsc; /**< description */
1180 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001181 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001182 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Michal Vaskoecd62de2019-11-13 12:35:11 +01001183 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS is allowed */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001184};
1185
1186/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001187 * @brief YANG identity-stmt
1188 */
1189struct lysc_ident {
1190 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +01001191 const char *dsc; /**< description */
1192 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001193 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001194 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
1195 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001196 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001197 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1198};
1199
1200/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001201 * @brief YANG feature-stmt
1202 */
1203struct lysc_feature {
1204 const char *name; /**< feature name (mandatory) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001205 const char *dsc; /**< description */
1206 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001207 struct lys_module *module; /**< module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001208 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 +01001209 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001210 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001211 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
1212 #LYS_FENABLED values allowed */
1213};
1214
Radek Krejci151a5b72018-10-19 14:21:44 +02001215/**
1216 * @defgroup ifftokens if-feature expression tokens
1217 * Tokens of if-feature expression used in ::lysc_iffeature#expr
1218 *
1219 * @{
1220 */
1221#define LYS_IFF_NOT 0x00 /**< operand "not" */
1222#define LYS_IFF_AND 0x01 /**< operand "and" */
1223#define LYS_IFF_OR 0x02 /**< operand "or" */
1224#define LYS_IFF_F 0x03 /**< feature */
Radek Krejci2ff0d572020-05-21 15:27:28 +02001225/** @} ifftokens */
Radek Krejci151a5b72018-10-19 14:21:44 +02001226
1227/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001228 * @brief Compiled YANG revision statement
1229 */
1230struct lysc_revision {
1231 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1232 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1233};
1234
Radek Krejci2167ee12018-11-02 16:09:07 +01001235struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001236 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001237 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001238 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1239 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001240 };
Radek Krejci693262f2019-04-29 15:23:20 +02001241 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001242 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1243 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001244 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001245 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001246 const char *dsc; /**< description */
1247 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001248 const char *emsg; /**< error-message */
1249 const char *eapptag; /**< error-app-tag value */
1250 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1251};
1252
1253struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001254 const char *expr; /**< original, not compiled, regular expression */
1255 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001256 const char *dsc; /**< description */
1257 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001258 const char *emsg; /**< error-message */
1259 const char *eapptag; /**< error-app-tag value */
1260 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0f969882020-08-21 16:56:47 +02001261 uint32_t inverted : 1; /**< invert-match flag */
1262 uint32_t refcount : 31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001263};
1264
1265struct lysc_must {
1266 struct lys_module *module; /**< module where the must was defined */
1267 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001268 const char *dsc; /**< description */
1269 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001270 const char *emsg; /**< error-message */
1271 const char *eapptag; /**< error-app-tag value */
1272 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1273};
1274
1275struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001276 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001277 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 +01001278 LY_DATA_TYPE basetype; /**< Base type of the type */
1279 uint32_t refcount; /**< reference counter for type sharing */
1280};
1281
1282struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001283 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001284 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 +01001285 LY_DATA_TYPE basetype; /**< Base type of the type */
1286 uint32_t refcount; /**< reference counter for type sharing */
1287 struct lysc_range *range; /**< Optional range limitation */
1288};
1289
1290struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001291 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001292 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 +01001293 LY_DATA_TYPE basetype; /**< Base type of the type */
1294 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001295 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001296 struct lysc_range *range; /**< Optional range limitation */
1297};
1298
1299struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001300 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001301 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 +01001302 LY_DATA_TYPE basetype; /**< Base type of the type */
1303 uint32_t refcount; /**< reference counter for type sharing */
1304 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001305 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001306};
1307
Radek Krejci693262f2019-04-29 15:23:20 +02001308struct lysc_type_bitenum_item {
1309 const char *name; /**< enumeration identifier */
1310 const char *dsc; /**< description */
1311 const char *ref; /**< reference */
1312 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1313 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1314 union {
1315 int32_t value; /**< integer value associated with the enumeration */
1316 uint32_t position; /**< non-negative integer value associated with the bit */
1317 };
1318 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1319 values are allowed */
1320};
1321
Radek Krejci2167ee12018-11-02 16:09:07 +01001322struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001323 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001324 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001325 LY_DATA_TYPE basetype; /**< Base type of the type */
1326 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001327 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1328};
1329
1330struct lysc_type_bits {
1331 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001332 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 +02001333 LY_DATA_TYPE basetype; /**< Base type of the type */
1334 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001335 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1336 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001337};
1338
1339struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001340 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001341 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 +01001342 LY_DATA_TYPE basetype; /**< Base type of the type */
1343 uint32_t refcount; /**< reference counter for type sharing */
Michal Vasko004d3152020-06-11 19:59:22 +02001344 struct lyxp_expr *path; /**< parsed target path, compiled path cannot be stored because of type sharing */
Radek Krejci96a0bfd2018-11-22 15:25:06 +01001345 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 +01001346 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001347 uint8_t require_instance; /**< require-instance flag */
1348};
1349
1350struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001351 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001352 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 +01001353 LY_DATA_TYPE basetype; /**< Base type of the type */
1354 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001355 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001356 mandatory (at least 1 item) */
1357};
1358
1359struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001360 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001361 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 +01001362 LY_DATA_TYPE basetype; /**< Base type of the type */
1363 uint32_t refcount; /**< reference counter for type sharing */
1364 uint8_t require_instance; /**< require-instance flag */
1365};
1366
Radek Krejci2167ee12018-11-02 16:09:07 +01001367struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001368 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001369 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001370 LY_DATA_TYPE basetype; /**< Base type of the type */
1371 uint32_t refcount; /**< reference counter for type sharing */
1372 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1373};
1374
1375struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001376 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001377 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 +01001378 LY_DATA_TYPE basetype; /**< Base type of the type */
1379 uint32_t refcount; /**< reference counter for type sharing */
1380 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001381};
1382
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001383struct lysc_action_inout {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001384 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001385 struct lysc_node *data; /**< first child node (linked list) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001386 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1387};
1388
Michal Vasko60ea6352020-06-29 13:39:39 +02001389/**
1390 * @brief Maximum number of hashes stored in a schema node.
1391 */
1392#define LYS_NODE_HASH_COUNT 4
1393
Radek Krejci056d0a82018-12-06 16:57:25 +01001394struct lysc_action {
Michal Vasko1bf09392020-03-27 12:38:10 +01001395 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci056d0a82018-12-06 16:57:25 +01001396 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001397 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejci95710c92019-02-11 15:49:55 +01001398 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001399 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. */
1400 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1401
Radek Krejcifc11bd72019-04-11 16:00:05 +02001402 struct lysc_ext_instance *input_exts; /**< list of the extension instances of input ([sized array](@ref sizedarrays)) */
1403 struct lysc_ext_instance *output_exts; /**< list of the extension instances of outpu ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001404
Radek Krejci056d0a82018-12-06 16:57:25 +01001405 const char *name; /**< action/RPC name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001406 const char *dsc; /**< description */
1407 const char *ref; /**< reference */
1408
Radek Krejcifc11bd72019-04-11 16:00:05 +02001409 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1410 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1411
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001412 struct lysc_action_inout input; /**< RPC's/action's input */
1413 struct lysc_action_inout output; /**< RPC's/action's output */
1414
Michal Vasko2fd91b92020-07-17 16:39:02 +02001415 void *priv; /** private arbitrary user data, not used by libyang */
1416
Radek Krejci056d0a82018-12-06 16:57:25 +01001417};
1418
1419struct lysc_notif {
1420 uint16_t nodetype; /**< LYS_NOTIF */
1421 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001422 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejci95710c92019-02-11 15:49:55 +01001423 struct lys_module *module; /**< module structure */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001424 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 +01001425 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1426
Radek Krejcifc11bd72019-04-11 16:00:05 +02001427 struct lysc_node *data; /**< first child node (linked list) */
1428 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1429
Radek Krejci056d0a82018-12-06 16:57:25 +01001430 const char *name; /**< Notification name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001431 const char *dsc; /**< description */
1432 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001433
1434 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1435 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001436
1437 void *priv; /** private arbitrary user data, not used by libyang */
Radek Krejci056d0a82018-12-06 16:57:25 +01001438};
1439
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001440/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001441 * @brief Compiled YANG data node
1442 */
1443struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001444 uint16_t nodetype; /**< type of the node (mandatory) */
1445 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001446 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001447 struct lys_module *module; /**< module structure */
Michal Vaskocc048b22020-03-27 15:52:38 +01001448 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or
1449 in case of implicit case node. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001450 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1451 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1452 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1453 never NULL. If there is no sibling node, pointer points to the node
1454 itself. In case of the first node, this pointer points to the last
1455 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001456 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001457 const char *dsc; /**< description */
1458 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001459 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001460 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001461 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001462 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001463};
1464
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001465struct lysc_node_container {
1466 uint16_t nodetype; /**< LYS_CONTAINER */
1467 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001468 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001469 struct lys_module *module; /**< module structure */
1470 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. */
1471 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1472 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1473 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1474 never NULL. If there is no sibling node, pointer points to the node
1475 itself. In case of the first node, this pointer points to the last
1476 node in the list. */
1477 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001478 const char *dsc; /**< description */
1479 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001480 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001481 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001482 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001483 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001484
1485 struct lysc_node *child; /**< first child node (linked list) */
1486 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1487 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1488 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001489};
1490
Radek Krejcia3045382018-11-22 14:30:31 +01001491struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001492 uint16_t nodetype; /**< LYS_CASE */
1493 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001494 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
Radek Krejci056d0a82018-12-06 16:57:25 +01001495 struct lys_module *module; /**< module structure */
1496 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. */
1497 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1498 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1499 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1500 never NULL. If there is no sibling node, pointer points to the node
1501 itself. In case of the first node, this pointer points to the last
1502 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001503 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001504 const char *dsc; /**< description */
1505 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001506 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001507 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001508 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001509 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci056d0a82018-12-06 16:57:25 +01001510
Radek Krejcia3045382018-11-22 14:30:31 +01001511 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 +01001512 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001513};
1514
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001515struct lysc_node_choice {
1516 uint16_t nodetype; /**< LYS_CHOICE */
1517 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001518 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001519 struct lys_module *module; /**< module structure */
1520 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. */
1521 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1522 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1523 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1524 never NULL. If there is no sibling node, pointer points to the node
1525 itself. In case of the first node, this pointer points to the last
1526 node in the list. */
1527 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001528 const char *dsc; /**< description */
1529 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001530 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001531 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001532 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001533 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001534
Radek Krejcia9026eb2018-12-12 16:04:47 +01001535 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1536 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1537 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001538 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001539};
1540
1541struct lysc_node_leaf {
1542 uint16_t nodetype; /**< LYS_LEAF */
1543 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001544 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001545 struct lys_module *module; /**< module structure */
1546 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. */
1547 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1548 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1549 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1550 never NULL. If there is no sibling node, pointer points to the node
1551 itself. In case of the first node, this pointer points to the last
1552 node in the list. */
1553 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001554 const char *dsc; /**< description */
1555 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001556 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001557 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001558 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001559 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001560
1561 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1562 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001563
Radek Krejci4f28eda2018-11-12 11:46:16 +01001564 const char *units; /**< units of the leaf's type */
Radek Krejcia1911222019-07-22 17:24:50 +02001565 struct lyd_value *dflt; /**< default value */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001566};
1567
1568struct lysc_node_leaflist {
1569 uint16_t nodetype; /**< LYS_LEAFLIST */
1570 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001571 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001572 struct lys_module *module; /**< module structure */
1573 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. */
1574 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1575 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1576 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1577 never NULL. If there is no sibling node, pointer points to the node
1578 itself. In case of the first node, this pointer points to the last
1579 node in the list. */
1580 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001581 const char *dsc; /**< description */
1582 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001583 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001584 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001585 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001586 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001587
1588 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1589 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1590
Radek Krejci0e5d8382018-11-28 16:37:53 +01001591 const char *units; /**< units of the leaf's type */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001592 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values */
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001593
Radek Krejci0e5d8382018-11-28 16:37:53 +01001594 uint32_t min; /**< min-elements constraint */
1595 uint32_t max; /**< max-elements constraint */
1596
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001597};
1598
1599struct lysc_node_list {
1600 uint16_t nodetype; /**< LYS_LIST */
1601 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001602 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001603 struct lys_module *module; /**< module structure */
1604 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. */
1605 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1606 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1607 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1608 never NULL. If there is no sibling node, pointer points to the node
1609 itself. In case of the first node, this pointer points to the last
1610 node in the list. */
1611 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001612 const char *dsc; /**< description */
1613 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001614 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001615 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001616 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001617 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001618
1619 struct lysc_node *child; /**< first child node (linked list) */
1620 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1621 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1622 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1623
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001624 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1625 uint32_t min; /**< min-elements constraint */
1626 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001627};
1628
1629struct lysc_node_anydata {
1630 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1631 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001632 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001633 struct lys_module *module; /**< module structure */
1634 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. */
1635 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1636 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1637 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1638 never NULL. If there is no sibling node, pointer points to the node
1639 itself. In case of the first node, this pointer points to the last
1640 node in the list. */
1641 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001642 const char *dsc; /**< description */
1643 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001644 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001645 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001646 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001647 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci9800fb82018-12-13 14:26:23 +01001648
1649 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001650};
1651
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001652/**
1653 * @brief Compiled YANG schema tree structure representing YANG module.
1654 *
1655 * Semantically validated YANG schema tree for data tree parsing.
1656 * Contains only the necessary information for the data validation.
1657 */
1658struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001659 struct lys_module *mod; /**< covering module structure */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001660
Radek Krejci2a408df2018-10-29 16:32:26 +01001661 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1662 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1663 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001664 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001665};
1666
1667/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001668 * @brief Get the groupings sized array of the given (parsed) schema node.
1669 * Decides the node's type and in case it has a groupings array, returns it.
1670 * @param[in] node Node to examine.
1671 * @return The node's groupings sized array if any, NULL otherwise.
1672 */
1673const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1674
1675/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001676 * @brief Get the typedefs sized array of the given (parsed) schema node.
1677 * Decides the node's type and in case it has a typedefs array, returns it.
1678 * @param[in] node Node to examine.
1679 * @return The node's typedefs sized array if any, NULL otherwise.
1680 */
1681const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1682
1683/**
1684 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1685 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1686 * @param[in] node Node to examine.
1687 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1688 */
1689const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1690
1691/**
1692 * @brief Get the Notifications sized array of the given (parsed) schema node.
1693 * Decides the node's type and in case it has a Notifications array, returns it.
1694 * @param[in] node Node to examine.
1695 * @return The node's Notifications sized array if any, NULL otherwise.
1696 */
1697const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1698
1699/**
1700 * @brief Get the children linked list of the given (parsed) schema node.
1701 * Decides the node's type and in case it has a children list, returns it.
1702 * @param[in] node Node to examine.
1703 * @return The node's children linked list if any, NULL otherwise.
1704 */
1705const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1706
1707/**
1708 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1709 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1710 * @param[in] node Node to examine.
1711 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1712 */
1713const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1714
1715/**
1716 * @brief Get the Notifications sized array of the given (compiled) schema node.
1717 * Decides the node's type and in case it has a Notifications array, returns it.
1718 * @param[in] node Node to examine.
1719 * @return The node's Notifications sized array if any, NULL otherwise.
1720 */
1721const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1722
1723/**
1724 * @brief Get the children linked list of the given (compiled) schema node.
1725 * Decides the node's type and in case it has a children list, returns it.
1726 * @param[in] node Node to examine.
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001727 * @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 +01001728 * @return The node's children linked list if any, NULL otherwise.
1729 */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001730const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Radek Krejci056d0a82018-12-06 16:57:25 +01001731
1732/**
Michal Vaskod975f862020-06-23 13:29:28 +02001733 * @brief Examine whether a node is user-ordered list or leaf-list.
1734 *
1735 * @param[in] node Node to examine.
1736 * @return non-zero if it is,
Radek Krejci857189e2020-09-01 13:26:36 +02001737 * @return Boolean value whether the @p node is user-ordered or not.
Michal Vaskod975f862020-06-23 13:29:28 +02001738 */
Radek Krejci857189e2020-09-01 13:26:36 +02001739ly_bool lysc_is_userordered(const struct lysc_node *schema);
Michal Vaskod975f862020-06-23 13:29:28 +02001740
1741/**
Michal Vasko2fd91b92020-07-17 16:39:02 +02001742 * @brief Set a schema private pointer to a user pointer.
1743 *
1744 * @param[in] node Node, whose private field will be assigned. Works also for RPCs, actions, and notifications.
1745 * @param[in] priv Arbitrary user-specified pointer.
1746 * @param[out] prev Optional previous private object of the \p node. Note, that
1747 * the caller is in this case responsible (if it is necessary) for freeing the replaced private object.
1748 * @return LY_ERR value.
1749 */
1750LY_ERR lysc_set_private(const struct lysc_node *node, void *priv, void **prev);
1751
1752/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001753 * @brief Get how the if-feature statement currently evaluates.
1754 *
1755 * @param[in] iff Compiled if-feature statement to evaluate.
Michal Vasko28d78432020-05-26 13:10:53 +02001756 * @return LY_SUCCESS if the statement evaluates to true,
1757 * @return LY_ENOT if it evaluates to false,
1758 * @return LY_ERR on error.
Radek Krejci151a5b72018-10-19 14:21:44 +02001759 */
Michal Vasko28d78432020-05-26 13:10:53 +02001760LY_ERR lysc_iffeature_value(const struct lysc_iffeature *iff);
Radek Krejci151a5b72018-10-19 14:21:44 +02001761
1762/**
1763 * @brief Get the current status of the provided feature.
1764 *
1765 * @param[in] feature Compiled feature statement to examine.
Michal Vasko28d78432020-05-26 13:10:53 +02001766 * @return LY_SUCCESS if feature is enabled,
1767 * @return LY_ENOT if feature is disabled,
1768 * @return LY_ERR in case of error (invalid argument)
Radek Krejci151a5b72018-10-19 14:21:44 +02001769 */
Michal Vasko28d78432020-05-26 13:10:53 +02001770LY_ERR lysc_feature_value(const struct lysc_feature *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001771
Michal Vasko072de482020-08-05 13:27:21 +02001772#define LYXP_SCNODE 0x02 /**< No special tree access modifiers. */
1773#define LYXP_SCNODE_SCHEMA 0x04 /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */
1774#define LYXP_SCNODE_OUTPUT 0x08 /**< Search RPC/action output nodes instead of input ones. */
1775
Radek Krejci151a5b72018-10-19 14:21:44 +02001776/**
Michal Vasko519fd602020-05-26 12:17:39 +02001777 * @brief Get all the schema nodes (atoms) that are required for \p xpath to be evaluated.
1778 *
1779 * @param[in] ctx_node XPath schema context node.
1780 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LYD_JSON format is expected.
1781 * @param[in] options Whether to apply some node access restrictions, one of the options should always be used.
1782 * If none is set, ::LYXP_SCNODE is used.
1783 * @param[out] set Set of found atoms (schema nodes).
1784 * @return LY_SUCCESS on success, @p set is returned.
1785 * @return LY_ERR value if an error occurred.
1786 */
Radek Krejci1deb5be2020-08-26 16:43:36 +02001787LY_ERR lys_atomize_xpath(const struct lysc_node *ctx_node, const char *xpath, uint32_t options, struct ly_set **set);
Michal Vasko519fd602020-05-26 12:17:39 +02001788
Michal Vasko072de482020-08-05 13:27:21 +02001789/**
1790 * @brief Evaluate an \p xpath expression on schema nodes.
1791 *
1792 * @param[in] ctx_node XPath schema context node.
1793 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LYD_JSON format is expected.
1794 * @param[in] options Whether to apply some node access restrictions, one of the options should always be used.
1795 * If none is set, ::LYXP_SCNODE is used.
1796 * @param[out] set Set of found schema nodes.
1797 * @return LY_SUCCESS on success, @p set is returned.
1798 * @return LY_ERR value if an error occurred.
1799 */
Radek Krejci1deb5be2020-08-26 16:43:36 +02001800LY_ERR lys_find_xpath(const struct lysc_node *ctx_node, const char *xpath, uint32_t options, struct ly_set **set);
Michal Vasko519fd602020-05-26 12:17:39 +02001801
1802/**
Michal Vasko03ff5a72019-09-11 13:49:33 +02001803 * @brief Types of the different schema paths.
1804 */
1805typedef enum {
Michal Vasko65de0402020-08-03 16:34:19 +02001806 LYSC_PATH_LOG, /**< Descriptive path format used in log messages */
1807 LYSC_PATH_DATA /**< Similar to ::LYSC_PATH_LOG except that schema-only nodes (choice, case) are skipped */
Michal Vasko03ff5a72019-09-11 13:49:33 +02001808} LYSC_PATH_TYPE;
1809
1810/**
Radek Krejci327de162019-06-14 12:52:07 +02001811 * @brief Generate path of the given node in the requested format.
1812 *
1813 * @param[in] node Schema path of this node will be generated.
1814 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001815 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
1816 * If NULL, memory for the complete path is allocated.
1817 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02001818 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001819 * 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 +02001820 */
Michal Vasko03ff5a72019-09-11 13:49:33 +02001821char *lysc_path(const struct lysc_node *node, LYSC_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02001822
1823/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001824 * @brief Available YANG schema tree structures representing YANG module.
1825 */
1826struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001827 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
1828 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01001829 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001830 const char *ns; /**< namespace of the module (module - mandatory) */
1831 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
1832 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1833 const char *org; /**< party/company responsible for the module */
1834 const char *contact; /**< contact information for the module */
1835 const char *dsc; /**< description of the module */
1836 const char *ref; /**< cross-reference for the module */
1837
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001838 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01001839 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
1840 Available only for implemented modules. */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001841
Radek Krejci14915cc2020-09-14 17:28:13 +02001842 struct lysc_feature *features; /**< List of compiled features of the module ([sized array](@ref sizedarrays)).
1843 Features are outside the compiled tree since they are needed even the module is not
1844 compiled. In such a case, the features are always disabled and cannot be enabled until
1845 the module is implemented. The features are present in this form to allow their linkage
Radek Krejci0af46292019-01-11 16:02:31 +01001846 from if-feature statements of the compiled schemas and their proper use in case
1847 the module became implemented in future (no matter if implicitly via augment/deviate
Radek Krejci14915cc2020-09-14 17:28:13 +02001848 or explicitly via ::lys_set_implemented()). */
Radek Krejci80d281e2020-09-14 17:42:54 +02001849 struct lysc_ident *identities; /**< List of compiled identities of the module ([sized array](@ref sizedarrays))
1850 Identities are outside the compiled tree to allow their linkage to the identities from
1851 the implemented modules. This avoids problems when the module became implemented in
1852 future (no matter if implicitly via augment/deviate or explicitly via
1853 ::lys_set_implemented()). Note that if the module is not implemented (compiled), the
1854 identities cannot be instantiated in data (in identityrefs). */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001855
1856 struct lys_module **augmented_by;/**< List of modules that augment this module ([sized array](@ref sizedarrays)) */
1857 struct lys_module **deviated_by; /**< List of modules that deviate this module ([sized array](@ref sizedarrays)) */
1858
Michal Vasko89b5c072020-10-06 13:52:44 +02001859 ly_bool implemented; /**< flag if the module is implemented, not just imported */
Radek Krejci95710c92019-02-11 15:49:55 +01001860 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001861 1 - the latest revision in searchdirs was not searched yet and this is the
1862 latest revision in the current context
1863 2 - searchdirs were searched and this is the latest available revision */
1864 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001865};
1866
Radek Krejci151a5b72018-10-19 14:21:44 +02001867/**
1868 * @brief Enable specified feature in the module
1869 *
1870 * By default, when the module is loaded by libyang parser, all features are disabled.
1871 *
Radek Krejcica3db002018-11-01 10:31:01 +01001872 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
1873 * enabling all features on the following feature set will fail since it is not possible to enable both features
1874 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
1875 * is untouched.
1876 *
1877 * feature f1;
1878 * feature f2 { if-feature 'not f1';}
1879 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001880 * @param[in] module Module where the feature will be enabled.
1881 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
Michal Vasko82c31e62020-07-17 15:30:40 +02001882 * @return LY_SUCCESS on success,
1883 * @return LY_EINVAL if @p module is not implemented,
1884 * @return LY_ENOTFOUND if @p feature was not found,
1885 * @return LY_EDENIED if @p feature could not be enabled because it has some false if-feature statements.
Radek Krejci151a5b72018-10-19 14:21:44 +02001886 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001887LY_ERR lys_feature_enable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001888
1889/**
1890 * @brief Disable specified feature in the module
1891 *
1892 * By default, when the module is loaded by libyang parser, all features are disabled.
1893 *
Michal Vasko82c31e62020-07-17 15:30:40 +02001894 * If disabling a feature causes some other features that depend on this feature to become disabled.
1895 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001896 * @param[in] module Module where the feature will be disabled.
1897 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
Michal Vasko82c31e62020-07-17 15:30:40 +02001898 * @return LY_SUCCESS on success,
1899 * @return LY_EINVAL if @p module is not implemented,
1900 * @return LY_ENOTFOUND if @p feature was not found.
Radek Krejci151a5b72018-10-19 14:21:44 +02001901 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001902LY_ERR lys_feature_disable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001903
1904/**
Michal Vasko82c31e62020-07-17 15:30:40 +02001905 * @brief Enable specified feature in the module disregarding its if-features.
1906 *
1907 * @param[in] module Module where the feature will be enabled.
1908 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk character.
1909 * @return LY_SUCCESS on success,
1910 * @return LY_EINVAL if @p module is not implemented,
1911 * @return LY_ENOTFOUND if @p feature was not found.
1912 */
1913LY_ERR lys_feature_enable_force(const struct lys_module *module, const char *feature);
1914
1915/**
1916 * @brief Disable specified feature in the module disregarding dependant features.
1917 *
1918 * By default, when the module is loaded by libyang parser, all features are disabled.
1919 *
1920 * @param[in] module Module where the feature will be disabled.
1921 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk character.
1922 * @return LY_SUCCESS on success,
1923 * @return LY_EINVAL if @p module is not implemented,
1924 * @return LY_ENOTFOUND if @p feature was not found.
1925 */
1926LY_ERR lys_feature_disable_force(const struct lys_module *module, const char *feature);
1927
1928/**
1929 * @brief Get the current real status of the specified feature in the module.
1930 *
1931 * If the feature is enabled, but some of its if-features are false, the feature is considered
1932 * disabled.
Radek Krejci151a5b72018-10-19 14:21:44 +02001933 *
1934 * @param[in] module Module where the feature is defined.
1935 * @param[in] feature Name of the feature to inspect.
Michal Vasko82c31e62020-07-17 15:30:40 +02001936 * @return LY_SUCCESS if the feature is enabled,
1937 * @return LY_ENOT if the feature is disabled,
1938 * @return LY_ENOTFOUND if the feature was not found.
Radek Krejci151a5b72018-10-19 14:21:44 +02001939 */
Michal Vasko82c31e62020-07-17 15:30:40 +02001940LY_ERR lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001941
1942/**
Radek Krejcia3045382018-11-22 14:30:31 +01001943 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
1944 * be from an augment.
1945 *
1946 * lys_getnext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
1947 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
1948 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
1949 * \p parent and \p module parameters.
1950 *
1951 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
1952 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
1953 * all the schema nodes are iteratively returned.
1954 *
1955 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
1956 * @param[in] parent Parent of the subtree where the function starts processing.
1957 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
1958 * module must be specified.
1959 * @param[in] options [ORed options](@ref sgetnextflags).
1960 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
1961 */
1962const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
Radek Krejci1deb5be2020-08-26 16:43:36 +02001963 const struct lysc_module *module, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01001964
1965/**
1966 * @defgroup sgetnextflags lys_getnext() flags
Radek Krejcia3045382018-11-22 14:30:31 +01001967 * @{
1968 */
1969#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 +01001970#define LYS_GETNEXT_NOCHOICE 0x02 /**< lys_getnext() option to ignore (kind of conditional) nodes within choice node */
Radek Krejci056d0a82018-12-06 16:57:25 +01001971#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 +01001972#define LYS_GETNEXT_INTONPCONT 0x40 /**< lys_getnext() option to look into non-presence container, instead of returning container itself */
1973#define LYS_GETNEXT_NOSTATECHECK 0x100 /**< lys_getnext() option to skip checking module validity (import-only, disabled) and
1974 relevant if-feature conditions state */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001975#define LYS_GETNEXT_OUTPUT 0x200 /**< lys_getnext() option to provide RPC's/action's output schema nodes instead of input schema nodes
1976 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01001977/** @} sgetnextflags */
1978
1979/**
1980 * @brief Get child node according to the specified criteria.
1981 *
1982 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
1983 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
1984 * @param[in] name Name of the node to find.
1985 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
1986 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
1987 * Used as a bitmask, so multiple nodetypes can be specified.
1988 * @param[in] options [ORed options](@ref sgetnextflags).
1989 * @return Found node if any.
1990 */
Michal Vaskoe444f752020-02-10 12:20:06 +01001991const struct lysc_node *lys_find_child(const struct lysc_node *parent, const struct lys_module *module,
Radek Krejci1deb5be2020-08-26 16:43:36 +02001992 const char *name, size_t name_len, uint16_t nodetype, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01001993
1994/**
Radek Krejci09e8d0a2019-11-17 12:14:15 +08001995 * @brief Get schema node specified by the schema path.
1996 *
1997 * In case the @p qpath uses prefixes (from imports or of the schema itself), the @p context_node must be specified
1998 * even if the path is absolute. In case the @p context_node is not provided, the names of the schemas are expected as the
1999 * node's prefixes in the @qpath. It also means that the relative paths are accepted only with the schema prefixes,
2000 * not the full names.
2001 *
2002 * @param[in] ctx libyang context for logging and getting the correct schema if @p contet_node not provided.
2003 * @param[in] context_node Context node for relative paths and/or as a source of the context module to resolve node's
2004 * prefixes in @qpath.
2005 * @param[in] qpath Schema path to be resolved. Not prefixed nodes inherits the prefix from its parent nodes. It means
2006 * that the first node in the path must be prefixed. Both, import prefixes as well as full schema names are accepted as
2007 * prefixes according to the @p context_node parameter presence.
2008 * @return NULL in case of invalid path.
2009 * @return found schema node.
2010 */
2011const struct lysc_node *lys_find_node(struct ly_ctx *ctx, const struct lysc_node *context_node, const char *qpath);
2012
2013/**
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002014 * @brief Make the specific module implemented.
2015 *
2016 * @param[in] mod Module to make implemented. It is not an error
2017 * to provide already implemented module, it just does nothing.
Michal Vaskoe444f752020-02-10 12:20:06 +01002018 * @return LY_SUCCESS on success.
2019 * @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 +02002020 */
2021LY_ERR lys_set_implemented(struct lys_module *mod);
2022
2023/**
Radek Krejcia3045382018-11-22 14:30:31 +01002024 * @brief Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statement
2025 * affecting the node.
2026 *
2027 * @param[in] node Schema node to check.
2028 * @param[in] recursive - 0 to check if-feature only in the \p node schema node,
2029 * - 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 +01002030 * @return NULL if enabled,
Michal Vaskoc193ce92020-03-06 11:04:48 +01002031 * @return pointer to the node with the unsatisfied (disabled) if-feature expression.
Radek Krejcia3045382018-11-22 14:30:31 +01002032 */
Radek Krejci857189e2020-09-01 13:26:36 +02002033const struct lysc_node *lysc_node_is_disabled(const struct lysc_node *node, ly_bool recursive);
Radek Krejcia3045382018-11-22 14:30:31 +01002034
Radek Krejci084289f2019-07-09 17:35:30 +02002035/**
Radek Krejci19cf8052020-08-18 15:02:38 +02002036 * @brief Set a schema private pointer to a user pointer.
2037 *
2038 * @param[in] node Node, whose private field will be assigned.
2039 * @param[in] priv Arbitrary user-specified pointer.
2040 * @param[out] prev_priv_p Pointer to the previous private data being returned after replacinf by @p priv.
2041 * @return LY_EINVAL in case of invalid @p node.
2042 * @return LY_SUCCESS on success.
2043 */
2044LY_ERR lysc_node_set_private(const struct lysc_node *node, void *priv, void **prev_priv_p);
2045
2046/**
Radek Krejci084289f2019-07-09 17:35:30 +02002047 * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
2048 *
2049 * This function check just the type's restriction, if you want to check also the data tree context (e.g. in case of
2050 * require-instance restriction), use lyd_value_validate().
2051 *
2052 * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
2053 * @param[in] node Schema node for the @p value.
Michal Vaskof937cfe2020-08-03 16:07:12 +02002054 * @param[in] value String value to be checked, expected to be in JSON format.
Radek Krejci084289f2019-07-09 17:35:30 +02002055 * @param[in] value_len Length of the given @p value (mandatory).
Radek Krejci084289f2019-07-09 17:35:30 +02002056 * @return LY_SUCCESS on success
2057 * @return LY_ERR value if an error occurred.
2058 */
Michal Vaskof937cfe2020-08-03 16:07:12 +02002059LY_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 +02002060
Radek Krejci0935f412019-08-20 16:15:18 +02002061/**
2062 * @brief Stringify schema nodetype.
Michal Vaskod43d71a2020-08-07 14:54:58 +02002063 *
Radek Krejci0935f412019-08-20 16:15:18 +02002064 * @param[in] nodetype Nodetype to stringify.
2065 * @return Constant string with the name of the node's type.
2066 */
2067const char *lys_nodetype2str(uint16_t nodetype);
2068
Michal Vaskod43d71a2020-08-07 14:54:58 +02002069/**
2070 * @brief Getter for original XPath expression from a parsed expression.
2071 *
2072 * @param[in] path Parsed expression.
2073 * @return Original string expression.
2074 */
2075const char *lyxp_get_expr(const struct lyxp_expr *path);
2076
Radek Krejci2ff0d572020-05-21 15:27:28 +02002077/** @} schematree */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002078
Radek Krejci70853c52018-10-15 14:46:16 +02002079#ifdef __cplusplus
2080}
2081#endif
2082
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002083#endif /* LY_TREE_SCHEMA_H_ */