blob: 64f503eaee7956b9787af09dc58b066a8f813deb [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 Krejci5aeea3a2018-09-05 13:29:36 +020021#include <stdint.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020022#include <stdio.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020023
Michal Vasko52927e22020-03-16 17:26:14 +010024#include "tree_data.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020025#include "log.h"
26#include "tree.h"
Radek Krejcice8c1592018-10-29 15:35:51 +010027
Radek Krejcie7b95092019-05-15 11:03:07 +020028struct ly_ctx;
29
Radek Krejci70853c52018-10-15 14:46:16 +020030#ifdef __cplusplus
31extern "C" {
32#endif
33
Radek Krejci5aeea3a2018-09-05 13:29:36 +020034/**
Radek Krejci0935f412019-08-20 16:15:18 +020035 * @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 +020036 * (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 +020037 *
38 * The function follows deep-first search algorithm:
39 * <pre>
40 * 1
41 * / \
42 * 2 4
43 * / / \
44 * 3 5 6
45 * </pre>
46 *
47 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
48 * START can be any of the lysc_node* types (including lysc_action and lysc_notif),
49 * ELEM variable must be of the struct lysc_node* type.
50 *
51 * To skip a particular subtree, instead of the continue statement, set LYSC_TREE_DFS_continue
52 * variable to non-zero value.
53 *
54 * Use with opening curly bracket '{' after the macro.
55 *
56 * @param START Pointer to the starting element processed first.
57 * @param ELEM Iterator intended for use in the block.
58 */
59#define LYSC_TREE_DFS_BEGIN(START, ELEM) \
60 { int LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
61 for ((ELEM) = (LYSC_TREE_DFS_next) = (START); \
62 (ELEM); \
63 (ELEM) = (LYSC_TREE_DFS_next), LYSC_TREE_DFS_continue = 0)
64
65/**
66 * @brief Macro to iterate via all elements in a (sub)tree. This is the closing part
67 * to the #LYSC_TREE_DFS_BEGIN - they always have to be used together.
68 *
69 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
70 * START can be a pointer to any of the lysc_node* types (including lysc_action and lysc_notif),
71 * ELEM variable must be pointer to the lysc_node type.
72 *
73 * Use with closing curly bracket '}' after the macro.
74 *
75 * @param START Pointer to the starting element processed first.
76 * @param ELEM Iterator intended for use in the block.
77 */
78
79#define LYSC_TREE_DFS_END(START, ELEM) \
80 /* select element for the next run - children first */ \
81 if (LYSC_TREE_DFS_continue) { \
82 (LYSC_TREE_DFS_next) = NULL; \
83 } else { \
84 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, 0); \
85 }\
86 if (!(LYSC_TREE_DFS_next)) { \
87 /* in case of RPC/action, get also the output children */ \
Michal Vasko1bf09392020-03-27 12:38:10 +010088 if (!LYSC_TREE_DFS_continue && (ELEM)->nodetype & (LYS_RPC | LYS_ACTION)) { \
Radek Krejci0935f412019-08-20 16:15:18 +020089 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, LYS_CONFIG_R); \
90 } \
91 if (!(LYSC_TREE_DFS_next)) { \
92 /* no children */ \
93 if ((ELEM) == (struct lysc_node*)(START)) { \
94 /* we are done, (START) has no children */ \
95 break; \
96 } \
97 /* try siblings */ \
98 (LYSC_TREE_DFS_next) = (ELEM)->next; \
99 } \
100 } \
101 while (!(LYSC_TREE_DFS_next)) { \
102 /* parent is already processed, go to its sibling */ \
103 (ELEM) = (ELEM)->parent; \
104 /* no siblings, go back through parents */ \
105 if ((ELEM) == (struct lysc_node*)(START)) { \
106 /* we are done, no next element to process */ \
107 break; \
108 } \
Michal Vasko1bf09392020-03-27 12:38:10 +0100109 if ((ELEM)->nodetype & (LYS_RPC | LYS_ACTION)) { \
Radek Krejci0935f412019-08-20 16:15:18 +0200110 /* there is actually next node as a child of action's output */ \
111 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, LYS_CONFIG_R); \
112 } \
113 if (!(LYSC_TREE_DFS_next)) { \
114 (LYSC_TREE_DFS_next) = (ELEM)->next; \
115 } \
116 } } \
117
118/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200119 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
120 */
121typedef enum {
122 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
123 LYS_IN_YANG = 1, /**< YANG schema input format */
Radek Krejci693262f2019-04-29 15:23:20 +0200124 LYS_IN_YIN = 3 /**< YIN schema input format */
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200125} LYS_INFORMAT;
126
127/**
128 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
129 */
130typedef enum {
131 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
132 LYS_OUT_YANG = 1, /**< YANG schema output format */
Radek Krejci693262f2019-04-29 15:23:20 +0200133 LYS_OUT_YANG_COMPILED = 2, /**< YANG schema output format of the compiled schema tree */
FredGand944bdc2019-11-05 21:57:07 +0800134 LYS_OUT_YIN = 3, /**< YIN schema output format */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200135
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200136 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
137 LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
138 LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */
139} LYS_OUTFORMAT;
140
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200141#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
142
Michal Vaskob55f6c12018-09-12 11:13:15 +0200143#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
144#define LYS_CONTAINER 0x0001 /**< container statement node */
145#define LYS_CHOICE 0x0002 /**< choice statement node */
146#define LYS_LEAF 0x0004 /**< leaf statement node */
147#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
148#define LYS_LIST 0x0010 /**< list statement node */
149#define LYS_ANYXML 0x0020 /**< anyxml statement node */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200150#define LYS_ANYDATA 0x0120 /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200151
Michal Vasko1bf09392020-03-27 12:38:10 +0100152#define LYS_RPC 0x400 /**< RPC statement node */
153#define LYS_ACTION 0x800 /**< action statement node */
154#define LYS_NOTIF 0x1000 /**< notification statement node */
Radek Krejcie7b95092019-05-15 11:03:07 +0200155
Radek Krejcia3045382018-11-22 14:30:31 +0100156#define LYS_CASE 0x0040 /**< case statement node */
157#define LYS_USES 0x0080 /**< uses statement node */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200158#define LYS_INPUT 0x100
159#define LYS_OUTPUT 0x200
160#define LYS_INOUT 0x300
Michal Vasko1bf09392020-03-27 12:38:10 +0100161#define LYS_GROUPING 0x2000
162#define LYS_AUGMENT 0x4000
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100163
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200164/**
Radek Krejcid6b76452019-09-03 17:03:03 +0200165 * @brief List of YANG statements
166 */
167enum ly_stmt {
168 LY_STMT_NONE = 0,
Radek Krejciad5963b2019-09-06 16:03:05 +0200169 LY_STMT_STATUS, /**< in lysc_ext_substmt::storage stored as a pointer to `uint16_t`, only cardinality < #LY_STMT_CARD_SOME is allowed */
170 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 +0200171 LY_STMT_MANDATORY,
Radek Krejciad5963b2019-09-06 16:03:05 +0200172 LY_STMT_UNITS, /**< in lysc_ext_substmt::storage stored as a pointer to `const char *` (cardinality < #LY_STMT_CARD_SOME)
173 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200174 LY_STMT_DEFAULT,
Radek Krejciad5963b2019-09-06 16:03:05 +0200175 LY_STMT_TYPE, /**< in lysc_ext_substmt::storage stored as a pointer to `struct lysc_type *` (cardinality < #LY_STMT_CARD_SOME)
176 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_type **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200177
Radek Krejcid6b76452019-09-03 17:03:03 +0200178 LY_STMT_ACTION,
179 LY_STMT_ANYDATA,
180 LY_STMT_ANYXML,
181 LY_STMT_ARGUMENT,
182 LY_STMT_AUGMENT,
183 LY_STMT_BASE,
184 LY_STMT_BELONGS_TO,
185 LY_STMT_BIT,
186 LY_STMT_CASE,
187 LY_STMT_CHOICE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200188 LY_STMT_CONTACT,
189 LY_STMT_CONTAINER,
Radek Krejcid6b76452019-09-03 17:03:03 +0200190 LY_STMT_DESCRIPTION,
191 LY_STMT_DEVIATE,
192 LY_STMT_DEVIATION,
193 LY_STMT_ENUM,
194 LY_STMT_ERROR_APP_TAG,
195 LY_STMT_ERROR_MESSAGE,
196 LY_STMT_EXTENSION,
197 LY_STMT_FEATURE,
198 LY_STMT_FRACTION_DIGITS,
199 LY_STMT_GROUPING,
200 LY_STMT_IDENTITY,
Radek Krejciad5963b2019-09-06 16:03:05 +0200201 LY_STMT_IF_FEATURE, /**< in lysc_ext_substmt::storage stored as a pointer to `struct lysc_iffeature` (cardinality < #LY_STMT_CARD_SOME)
202 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_iffeature *` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200203 LY_STMT_IMPORT,
204 LY_STMT_INCLUDE,
205 LY_STMT_INPUT,
206 LY_STMT_KEY,
207 LY_STMT_LEAF,
208 LY_STMT_LEAF_LIST,
209 LY_STMT_LENGTH,
210 LY_STMT_LIST,
Radek Krejcid6b76452019-09-03 17:03:03 +0200211 LY_STMT_MAX_ELEMENTS,
212 LY_STMT_MIN_ELEMENTS,
213 LY_STMT_MODIFIER,
214 LY_STMT_MODULE,
215 LY_STMT_MUST,
216 LY_STMT_NAMESPACE,
217 LY_STMT_NOTIFICATION,
218 LY_STMT_ORDERED_BY,
219 LY_STMT_ORGANIZATION,
220 LY_STMT_OUTPUT,
221 LY_STMT_PATH,
222 LY_STMT_PATTERN,
223 LY_STMT_POSITION,
224 LY_STMT_PREFIX,
225 LY_STMT_PRESENCE,
226 LY_STMT_RANGE,
227 LY_STMT_REFERENCE,
228 LY_STMT_REFINE,
229 LY_STMT_REQUIRE_INSTANCE,
230 LY_STMT_REVISION,
231 LY_STMT_REVISION_DATE,
232 LY_STMT_RPC,
Radek Krejcid6b76452019-09-03 17:03:03 +0200233 LY_STMT_SUBMODULE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200234 LY_STMT_TYPEDEF,
235 LY_STMT_UNIQUE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200236 LY_STMT_USES,
237 LY_STMT_VALUE,
238 LY_STMT_WHEN,
239 LY_STMT_YANG_VERSION,
240 LY_STMT_YIN_ELEMENT,
241 LY_STMT_EXTENSION_INSTANCE,
242
243 LY_STMT_SYNTAX_SEMICOLON,
244 LY_STMT_SYNTAX_LEFT_BRACE,
245 LY_STMT_SYNTAX_RIGHT_BRACE,
246
247 LY_STMT_ARG_TEXT,
248 LY_STMT_ARG_VALUE
249};
250
251/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200252 * @brief Extension instance structure parent enumeration
253 */
254typedef enum {
Radek Krejci0935f412019-08-20 16:15:18 +0200255 LYEXT_PAR_MODULE, /**< ::lysc_module */
256 LYEXT_PAR_NODE, /**< ::lysc_node (and the derived structures including ::lysc_action and ::lysc_notif) */
257 LYEXT_PAR_INPUT, /**< ::lysc_action_inout */
258 LYEXT_PAR_OUTPUT, /**< ::lysc_action_inout */
259 LYEXT_PAR_TYPE, /**< ::lysc_type */
260 LYEXT_PAR_TYPE_BIT, /**< ::lysc_type_bitenum_item */
261 LYEXT_PAR_TYPE_ENUM, /**< ::lysc_type_bitenum_item */
262 LYEXT_PAR_FEATURE, /**< ::lysc_feature */
263 LYEXT_PAR_MUST, /**< ::lysc_must */
264 LYEXT_PAR_PATTERN, /**< ::lysc_pattern */
265 LYEXT_PAR_LENGTH, /**< ::lysc_range */
266 LYEXT_PAR_RANGE, /**< ::lysc_range */
267 LYEXT_PAR_WHEN, /**< ::lysc_when */
268 LYEXT_PAR_IDENT, /**< ::lysc_ident */
269 LYEXT_PAR_EXT, /**< ::lysc_ext */
270 LYEXT_PAR_IMPORT, /**< ::lysc_import */
271// LYEXT_PAR_TPDF, /**< ::lysp_tpdf */
272// LYEXT_PAR_EXTINST, /**< ::lysp_ext_instance */
273// LYEXT_PAR_REFINE, /**< ::lysp_refine */
274// LYEXT_PAR_DEVIATION, /**< ::lysp_deviation */
275// LYEXT_PAR_DEVIATE, /**< ::lysp_deviate */
276// LYEXT_PAR_INCLUDE, /**< ::lysp_include */
277// LYEXT_PAR_REVISION, /**< ::lysp_revision */
Radek Krejci0e59c312019-08-15 15:34:15 +0200278} LYEXT_PARENT;
279
280/**
Radek Krejci0935f412019-08-20 16:15:18 +0200281 * @brief Stringify extension instance parent type.
282 * @param[in] type Parent type to stringify.
283 * @return Constant string with the name of the parent statement.
284 */
285const char *lyext_parent2str(LYEXT_PARENT type);
286
287/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200288 * @brief Enum of substatements in which extension instances can appear.
289 */
290typedef enum {
291 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
292 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
293 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
294 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
295 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
296 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
297 lys_node_choice and lys_deviate */
298 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
299 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
300 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
301 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
302 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
303 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
304 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
305 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
306 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
307 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
308 belongs-to's prefix) and lys_import */
309 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
310 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
311 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
312 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
313 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
314 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
315 lys_node_leaflist and lys_deviate */
316 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
317 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
318 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
319 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
320 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
321 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
322 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
323 lys_node_anydata and lys_deviate */
324 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
325 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
326 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
327 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
328 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
329 lys_node_leaflist and lys_deviate */
330 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
331 lys_node_leaflist and lys_deviate */
332 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
333 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
334 LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */
335} LYEXT_SUBSTMT;
336
337/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200338 * @brief YANG import-stmt
339 */
340struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200341 struct lys_module *module; /**< pointer to the imported module
342 (mandatory, but resolved when the referring module is completely parsed) */
343 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200344 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200345 const char *dsc; /**< description */
346 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200347 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200348 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
349};
350
351/**
352 * @brief YANG include-stmt
353 */
354struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100355 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200356 (mandatory, but resolved when the referring module is completely parsed) */
357 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200358 const char *dsc; /**< description */
359 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200360 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200361 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
362};
363
364/**
365 * @brief YANG extension-stmt
366 */
367struct lysp_ext {
368 const char *name; /**< extension name */
369 const char *argument; /**< argument name, NULL if not specified */
370 const char *dsc; /**< description statement */
371 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200372 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200373 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */
Michal Vasko5fe75f12020-03-02 13:52:37 +0100374
375 struct lysc_ext *compiled; /**< pointer to the compiled extension definition */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200376};
377
378/**
379 * @brief Helper structure for generic storage of the extension instances content.
380 */
381struct lysp_stmt {
382 const char *stmt; /**< identifier of the statement */
383 const char *arg; /**< statement's argument */
384 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200385 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
David Sedlákb9d75c42019-08-14 10:49:42 +0200386 uint16_t flags; /**< statement flags, can be set to LYS_YIN_ATTR */
Radek Krejci335332a2019-09-05 13:03:35 +0200387 enum ly_stmt kw; /**< numeric respresentation of the stmt value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200388};
389
David Sedlákae4b4512019-08-14 10:45:56 +0200390#define LYS_YIN 0x1 /**< used to specify input format of extension instance */
391
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200392/**
393 * @brief YANG extension instance
394 */
395struct lysp_ext_instance {
David Sedlákbbd06ca2019-06-27 14:15:38 +0200396 const char *name; /**< extension identifier, including possible prefix */
397 const char *argument; /**< optional value of the extension's argument */
Radek Krejci335332a2019-09-05 13:03:35 +0200398 void *parent; /**< pointer to the parent element holding the extension instance(s), use
399 ::lysp_ext_instance#parent_type to access the schema element */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200400 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200401 struct lysc_ext_instance *compiled; /**< pointer to the compiled data if any - in case the source format is YIN,
402 some of the information (argument) are available only after compilation */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200403 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
404 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
405 the index of that substatement */
David Sedlákae4b4512019-08-14 10:45:56 +0200406 uint8_t yin; /** flag for YIN source format, can be set to LYS_YIN */
Radek Krejci335332a2019-09-05 13:03:35 +0200407 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200408};
409
410/**
411 * @brief YANG feature-stmt
412 */
413struct lysp_feature {
414 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200415 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200416 const char *dsc; /**< description statement */
417 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200418 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200419 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
420};
421
422/**
423 * @brief YANG identity-stmt
424 */
425struct lysp_ident {
426 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200427 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
428 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200429 const char *dsc; /**< description statement */
430 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200431 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200432 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
433};
434
Michal Vasko71e64ca2018-09-07 16:30:29 +0200435/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200436 * @brief Covers restrictions: range, length, pattern, must
437 */
438struct lysp_restr {
439 const char *arg; /**< The restriction expression/value (mandatory);
440 in case of pattern restriction, the first byte has a special meaning:
441 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
442 const char *emsg; /**< error-message */
443 const char *eapptag; /**< error-app-tag value */
444 const char *dsc; /**< description */
445 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200446 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200447};
448
449/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200450 * @brief YANG revision-stmt
451 */
452struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200453 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200454 const char *dsc; /**< description statement */
455 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200456 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200457};
458
459/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200460 * @brief Enumeration/Bit value definition
461 */
462struct lysp_type_enum {
463 const char *name; /**< name (mandatory) */
464 const char *dsc; /**< description statement */
465 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200466 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200467 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200468 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200469 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
470 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200471};
472
473/**
474 * @brief YANG type-stmt
475 *
476 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
477 */
478struct lysp_type {
479 const char *name; /**< name of the type (mandatory) */
480 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
481 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200482 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
483 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
484 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200485 const char *path; /**< path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200486 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200487 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
488 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200489
Radek Krejci2167ee12018-11-02 16:09:07 +0100490 struct lysc_type *compiled; /**< pointer to the compiled type */
491
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200492 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
493 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100494 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200495};
496
497/**
498 * @brief YANG typedef-stmt
499 */
500struct lysp_tpdf {
501 const char *name; /**< name of the newly defined type (mandatory) */
502 const char *units; /**< units of the newly defined type */
503 const char *dflt; /**< default value of the newly defined type */
504 const char *dsc; /**< description statement */
505 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200506 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200507 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100508 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200509};
510
511/**
512 * @brief YANG grouping-stmt
513 */
514struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100515 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
516 uint16_t nodetype; /**< LYS_GROUPING */
517 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200518 const char *name; /**< grouping name (mandatory) */
519 const char *dsc; /**< description statement */
520 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200521 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
522 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200523 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200524 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
525 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
526 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200527};
528
529/**
530 * @brief YANG when-stmt
531 */
532struct lysp_when {
533 const char *cond; /**< specified condition (mandatory) */
534 const char *dsc; /**< description statement */
535 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200536 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200537};
538
539/**
540 * @brief YANG refine-stmt
541 */
542struct lysp_refine {
543 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
544 const char *dsc; /**< description statement */
545 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200546 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200547 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200548 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200549 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200550 uint32_t min; /**< min-elements constraint */
551 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200552 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200553 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
554};
555
556/**
Michal Vasko82a83432019-11-14 12:33:04 +0100557 * @brief YANG uses-augment-stmt and augment-stmt (compatible with struct lysp_node )
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200558 */
559struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100560 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
561 uint16_t nodetype; /**< LYS_AUGMENT */
562 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Michal Vasko82a83432019-11-14 12:33:04 +0100563 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200564 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
565 const char *dsc; /**< description statement */
566 const char *ref; /**< reference statement */
567 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200568 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Michal Vasko82a83432019-11-14 12:33:04 +0100569 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200570 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
571 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200572};
573
574/**
575 * @defgroup deviatetypes Deviate types
576 * @{
577 */
578#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
579#define LYS_DEV_ADD 2 /**< deviate type add */
580#define LYS_DEV_DELETE 3 /**< deviate type delete */
581#define LYS_DEV_REPLACE 4 /**< deviate type replace */
582/** @} */
583
584/**
585 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
586 */
587struct lysp_deviate {
588 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
589 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200590 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200591};
592
593struct lysp_deviate_add {
594 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
595 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200596 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200597 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200598 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200599 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
600 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200601 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
602 uint32_t min; /**< min-elements constraint */
603 uint32_t max; /**< max-elements constraint, 0 means unbounded */
604};
605
606struct lysp_deviate_del {
607 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
608 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200609 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200610 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200611 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200612 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
613 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200614};
615
616struct lysp_deviate_rpl {
617 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
618 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200619 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200620 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200621 const char *units; /**< units of the values */
622 const char *dflt; /**< default value */
623 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
624 uint32_t min; /**< min-elements constraint */
625 uint32_t max; /**< max-elements constraint, 0 means unbounded */
626};
627
628struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200629 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200630 const char *dsc; /**< description statement */
631 const char *ref; /**< reference statement */
632 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200633 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200634};
635
Radek Krejci4f28eda2018-11-12 11:46:16 +0100636/**
637 * @defgroup spnodeflags Parsed schema nodes flags
638 * @ingroup snodeflags
639 *
640 * Various flags for parsed schema nodes.
641 *
642 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
643 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200644 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100645 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
646 * 5 - list 10 - input 15 - typedef 20 - deviate
647 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200648 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
649 * 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
650 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
651 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
652 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
653 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
654 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
655 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
656 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
657 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
658 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
659 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
660 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
661 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
662 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
663 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
664 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
665 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
666 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
667 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
668 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
669 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
670 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
671 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
672 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
673 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
674 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
675 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
676 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
677 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
678 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
679 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
680 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
681 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
682 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
683 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
684 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
685 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
686 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200687 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
David Sedlákae4b4512019-08-14 10:45:56 +0200688 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejcid3ca0632019-04-16 16:54:54 +0200689 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejcif56e2a42019-09-09 14:15:25 +0200690 * 12 LYS_YIN_ARGUMENT | | | | | | | | | | | | | | | | | | | | | | |x|
691 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100692 *
693 */
694
695/**
696 * @defgroup scnodeflags Compiled schema nodes flags
697 * @ingroup snodeflags
698 *
699 * Various flags for compiled schema nodes.
700 *
Radek Krejci61e042e2019-09-10 15:53:09 +0200701 * 1 - container 6 - anydata/anyxml 11 - identity
702 * 2 - choice 7 - case 12 - extension
703 * 3 - leaf 8 - notification 13 - bitenum
Michal Vasko03ff5a72019-09-11 13:49:33 +0200704 * 4 - leaflist 9 - rpc/action 14 - when
Michal Vaskoecd62de2019-11-13 12:35:11 +0100705 * 5 - list 10 - feature
Radek Krejci4f28eda2018-11-12 11:46:16 +0100706 *
Michal Vaskoecd62de2019-11-13 12:35:11 +0100707 * 1 1 1 1 1
708 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
709 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
710 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | |
711 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
712 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | |
713 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
714 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x|x|x|x| |x|
715 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
716 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x|x|x|x| |x|
717 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
718 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x|x|x|x| |x|
719 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
720 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
721 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
722 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
723 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | |
724 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
725 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
726 * LYS_PRESENCE |x| | | | | | | | | | | | | |
727 * LYS_UNIQUE | | |x| | | | | | | | | | | |
728 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
729 * 9 LYS_KEY | | |x| | | | | | | | | | | |
730 * LYS_FENABLED | | | | | | | | | |x| | | | |
731 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
732 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
733 * LYS_ISENUM | | | | | | | | | | | | |x| |
734 * LYS_KEYLESS | | | | |x| | | | | | | | | |
735 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
736 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
737 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
738 * 12 LYS_SET_CONFIG |x|x|x|x|x|x| | | | | | | | |
739 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100740 *
741 */
742
743/**
744 * @defgroup snodeflags Schema nodes flags
745 * @ingroup schematree
746 * @{
747 */
Michal Vasko1bf09392020-03-27 12:38:10 +0100748#define LYS_CONFIG_W 0x01 /**< config true; also set for input children nodes */
749#define LYS_CONFIG_R 0x02 /**< config false; also set for output and notification children nodes */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200750#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100751#define LYS_STATUS_CURR 0x04 /**< status current; */
752#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
753#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
754#define LYS_STATUS_MASK 0x1C /**< mask for status value */
755#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100756 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
757 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
758 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
759 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100760#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
761 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
762 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100763#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100764#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, applicable only to ::lysc_node_container */
765#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 Krejci4f28eda2018-11-12 11:46:16 +0100810/** @} */
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 */
Radek Krejci151a5b72018-10-19 14:21:44 +0200824 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200825 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200826};
827
828/**
829 * @brief Extension structure of the lysp_node for YANG container
830 */
831struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100832 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200833 uint16_t nodetype; /**< LYS_CONTAINER */
834 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
835 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
836 const char *name; /**< node name (mandatory) */
837 const char *dsc; /**< description statement */
838 const char *ref; /**< reference statement */
839 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200840 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200841 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200842
843 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200844 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200845 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200846 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
847 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200848 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200849 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
850 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200851};
852
853struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100854 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200855 uint16_t nodetype; /**< LYS_LEAF */
856 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
857 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
858 const char *name; /**< node name (mandatory) */
859 const char *dsc; /**< description statement */
860 const char *ref; /**< reference statement */
861 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200862 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200863 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200864
865 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200866 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200867 struct lysp_type type; /**< type of the leaf node (mandatory) */
868 const char *units; /**< units of the leaf's type */
869 const char *dflt; /**< default value */
870};
871
872struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100873 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200874 uint16_t nodetype; /**< LYS_LEAFLIST */
875 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
876 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
877 const char *name; /**< node name (mandatory) */
878 const char *dsc; /**< description statement */
879 const char *ref; /**< reference statement */
880 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200881 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200882 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200883
884 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200885 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200886 struct lysp_type type; /**< type of the leaf node (mandatory) */
887 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200888 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200889 uint32_t min; /**< min-elements constraint */
890 uint32_t max; /**< max-elements constraint, 0 means unbounded */
891};
892
893struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100894 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200895 uint16_t nodetype; /**< LYS_LIST */
896 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
897 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
898 const char *name; /**< node name (mandatory) */
899 const char *dsc; /**< description statement */
900 const char *ref; /**< reference statement */
901 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200902 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200903 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200904
905 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200906 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200907 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200908 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
909 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200910 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200911 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
912 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200913 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200914 uint32_t min; /**< min-elements constraint */
915 uint32_t max; /**< max-elements constraint, 0 means unbounded */
916};
917
918struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100919 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200920 uint16_t nodetype; /**< LYS_CHOICE */
921 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
922 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
923 const char *name; /**< node name (mandatory) */
924 const char *dsc; /**< description statement */
925 const char *ref; /**< reference statement */
926 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200927 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200928 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200929
930 /* choice */
931 struct lysp_node *child; /**< list of data nodes (linked list) */
932 const char* dflt; /**< default case */
933};
934
935struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100936 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200937 uint16_t nodetype; /**< LYS_CASE */
938 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
939 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
940 const char *name; /**< node name (mandatory) */
941 const char *dsc; /**< description statement */
942 const char *ref; /**< reference statement */
943 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200944 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200945 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200946
947 /* case */
948 struct lysp_node *child; /**< list of data nodes (linked list) */
949};
950
951struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100952 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200953 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
954 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
955 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
956 const char *name; /**< node name (mandatory) */
957 const char *dsc; /**< description statement */
958 const char *ref; /**< reference statement */
959 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200960 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200961 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200962
963 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200964 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200965};
966
967struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100968 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200969 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200970 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
971 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
972 const char *name; /**< grouping name reference (mandatory) */
973 const char *dsc; /**< description statement */
974 const char *ref; /**< reference statement */
975 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200976 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200977 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200978
979 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200980 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
981 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200982};
983
984/**
985 * @brief YANG input-stmt and output-stmt
986 */
987struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100988 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
989 uint16_t nodetype; /**< LYS_INOUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200990 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
991 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
992 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200993 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200994 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200995};
996
997/**
998 * @brief YANG rpc-stmt and action-stmt
999 */
1000struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001001 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko1bf09392020-03-27 12:38:10 +01001002 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001003 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001004 const char *name; /**< grouping name reference (mandatory) */
1005 const char *dsc; /**< description statement */
1006 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +02001007 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001008 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1009 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001010 struct lysp_action_inout input; /**< RPC's/Action's input */
1011 struct lysp_action_inout output; /**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001012 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001013};
1014
1015/**
1016 * @brief YANG notification-stmt
1017 */
1018struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001019 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1020 uint16_t nodetype; /**< LYS_NOTIF */
1021 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001022 const char *name; /**< grouping name reference (mandatory) */
1023 const char *dsc; /**< description statement */
1024 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +02001025 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001026 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1027 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1028 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001029 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001030 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001031};
1032
1033/**
Radek Krejcif0fceb62018-09-05 14:58:45 +02001034 * @brief supported YANG schema version values
1035 */
1036typedef enum LYS_VERSION {
1037 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
1038 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
1039 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
1040} LYS_VERSION;
1041
1042/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001043 * @brief Printable YANG schema tree structure representing YANG module.
1044 *
1045 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
1046 */
1047struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001048 struct lys_module *mod; /**< covering module structure */
1049
Radek Krejcib7db73a2018-10-24 14:18:40 +02001050 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1051 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001052 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1053 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001054 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1055 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1056 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1057 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1058 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001059 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001060 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1061 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1062 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1063 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
1064 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001065
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001066 uint8_t parsing:1; /**< flag for circular check */
1067};
1068
1069struct lysp_submodule {
1070 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
1071
1072 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1073 in the list is always the last (newest) revision of the module */
1074 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1075 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
1076 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1077 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1078 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1079 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1080 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
1081 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
1082 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1083 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1084 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1085 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
1086 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1087
1088 uint8_t parsing:1; /**< flag for circular check */
1089
Radek Krejci086c7132018-10-26 15:29:04 +02001090 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
1091 1 - the latest revision in searchdirs was not searched yet and this is the
1092 latest revision in the current context
1093 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001094 const char *name; /**< name of the module (mandatory) */
1095 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1096 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
1097 const char *org; /**< party/company responsible for the module */
1098 const char *contact; /**< contact information for the module */
1099 const char *dsc; /**< description of the module */
1100 const char *ref; /**< cross-reference for the module */
Radek Krejci086c7132018-10-26 15:29:04 +02001101 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001102};
1103
1104/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +02001105 * @brief Free the printable YANG schema tree structure.
1106 *
1107 * @param[in] module Printable YANG schema tree structure to free.
1108 */
1109void lysp_module_free(struct lysp_module *module);
1110
1111/**
Radek Krejci0e59c312019-08-15 15:34:15 +02001112 * @brief Compiled YANG extension-stmt
1113 */
1114struct lysc_ext {
1115 const char *name; /**< extension name */
1116 const char *argument; /**< argument name, NULL if not specified */
Radek Krejci0e59c312019-08-15 15:34:15 +02001117 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1118 struct lyext_plugin *plugin; /**< Plugin implementing the specific extension */
Radek Krejci0935f412019-08-20 16:15:18 +02001119 struct lys_module *module; /**< module structure */
Michal Vasko6f4cbb62020-02-28 11:15:47 +01001120 uint32_t refcount; /**< reference counter since extension definition is shared among all its instances */
Radek Krejci0e59c312019-08-15 15:34:15 +02001121 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
1122};
1123
1124/**
Radek Krejcice8c1592018-10-29 15:35:51 +01001125 * @brief YANG extension instance
1126 */
1127struct lysc_ext_instance {
Radek Krejciad5963b2019-09-06 16:03:05 +02001128 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
1129 this identifies the index of the substatement for this extension instance */
Radek Krejci28681fa2019-09-06 13:08:45 +02001130 struct lys_module *module; /**< module where the extension instantiated is defined */
Radek Krejciad5963b2019-09-06 16:03:05 +02001131 struct lysc_ext *def; /**< pointer to the extension definition */
Radek Krejcice8c1592018-10-29 15:35:51 +01001132 void *parent; /**< pointer to the parent element holding the extension instance(s), use
1133 ::lysc_ext_instance#parent_type to access the schema element */
1134 const char *argument; /**< optional value of the extension's argument */
1135 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +01001136 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001137 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0e59c312019-08-15 15:34:15 +02001138 void *data; /**< private plugins's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +01001139};
1140
1141/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001142 * @brief Compiled YANG if-feature-stmt
1143 */
1144struct lysc_iffeature {
1145 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
1146 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
1147};
1148
1149/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001150 * @brief YANG import-stmt
1151 */
1152struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +01001153 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +02001154 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001155 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +02001156};
1157
1158/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001159 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001160 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001161struct lysc_when {
Radek Krejcia0f704a2019-09-09 16:12:23 +02001162 struct lys_module *module; /**< module where the must was defined */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001163 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko175012e2019-11-06 15:49:14 +01001164 struct lysc_node *context; /**< context node for evaluating the expression, NULL if the context is root node */
Radek Krejcic8b31002019-01-08 10:24:45 +01001165 const char *dsc; /**< description */
1166 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001167 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001168 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Michal Vaskoecd62de2019-11-13 12:35:11 +01001169 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS is allowed */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001170};
1171
1172/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001173 * @brief YANG identity-stmt
1174 */
1175struct lysc_ident {
1176 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +01001177 const char *dsc; /**< description */
1178 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001179 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001180 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
1181 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001182 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001183 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1184};
1185
1186/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001187 * @brief YANG feature-stmt
1188 */
1189struct lysc_feature {
1190 const char *name; /**< feature name (mandatory) */
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 Krejci151a5b72018-10-19 14:21:44 +02001194 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 +01001195 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 Krejcidd4e8d42018-10-16 14:55:43 +02001197 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
1198 #LYS_FENABLED values allowed */
1199};
1200
Radek Krejci151a5b72018-10-19 14:21:44 +02001201/**
1202 * @defgroup ifftokens if-feature expression tokens
1203 * Tokens of if-feature expression used in ::lysc_iffeature#expr
1204 *
1205 * @{
1206 */
1207#define LYS_IFF_NOT 0x00 /**< operand "not" */
1208#define LYS_IFF_AND 0x01 /**< operand "and" */
1209#define LYS_IFF_OR 0x02 /**< operand "or" */
1210#define LYS_IFF_F 0x03 /**< feature */
1211/**
1212 * @}
1213 */
1214
1215/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001216 * @brief Compiled YANG revision statement
1217 */
1218struct lysc_revision {
1219 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1220 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1221};
1222
Radek Krejci2167ee12018-11-02 16:09:07 +01001223struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001224 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001225 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001226 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1227 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001228 };
Radek Krejci693262f2019-04-29 15:23:20 +02001229 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001230 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1231 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001232 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001233 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001234 const char *dsc; /**< description */
1235 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001236 const char *emsg; /**< error-message */
1237 const char *eapptag; /**< error-app-tag value */
1238 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1239};
1240
1241struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001242 const char *expr; /**< original, not compiled, regular expression */
1243 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001244 const char *dsc; /**< description */
1245 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001246 const char *emsg; /**< error-message */
1247 const char *eapptag; /**< error-app-tag value */
1248 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4586a022018-11-13 11:29:26 +01001249 uint32_t inverted:1; /**< invert-match flag */
1250 uint32_t refcount:31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001251};
1252
1253struct lysc_must {
1254 struct lys_module *module; /**< module where the must was defined */
1255 struct lyxp_expr *cond; /**< XPath when condition */
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)) */
1261};
1262
1263struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001264 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001265 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001266 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001267 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 +01001268 LY_DATA_TYPE basetype; /**< Base type of the type */
1269 uint32_t refcount; /**< reference counter for type sharing */
1270};
1271
1272struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001273 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001274 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001275 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001276 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 +01001277 LY_DATA_TYPE basetype; /**< Base type of the type */
1278 uint32_t refcount; /**< reference counter for type sharing */
1279 struct lysc_range *range; /**< Optional range limitation */
1280};
1281
1282struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001283 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001284 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001285 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001286 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 +01001287 LY_DATA_TYPE basetype; /**< Base type of the type */
1288 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001289 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001290 struct lysc_range *range; /**< Optional range limitation */
1291};
1292
1293struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001294 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001295 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001296 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001297 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 +01001298 LY_DATA_TYPE basetype; /**< Base type of the type */
1299 uint32_t refcount; /**< reference counter for type sharing */
1300 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001301 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001302};
1303
Radek Krejci693262f2019-04-29 15:23:20 +02001304struct lysc_type_bitenum_item {
1305 const char *name; /**< enumeration identifier */
1306 const char *dsc; /**< description */
1307 const char *ref; /**< reference */
1308 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1309 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1310 union {
1311 int32_t value; /**< integer value associated with the enumeration */
1312 uint32_t position; /**< non-negative integer value associated with the bit */
1313 };
1314 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1315 values are allowed */
1316};
1317
Radek Krejci2167ee12018-11-02 16:09:07 +01001318struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001319 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001320 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001321 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001322 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 +01001323 LY_DATA_TYPE basetype; /**< Base type of the type */
1324 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001325 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1326};
1327
1328struct lysc_type_bits {
1329 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1330 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001331 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +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 Krejci01342af2019-01-03 15:18:08 +01001341 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001342 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001343 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 +01001344 LY_DATA_TYPE basetype; /**< Base type of the type */
1345 uint32_t refcount; /**< reference counter for type sharing */
Michal Vasko03ff5a72019-09-11 13:49:33 +02001346 const char *path; /**< target path */
Radek Krejci96a0bfd2018-11-22 15:25:06 +01001347 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 +01001348 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001349 uint8_t require_instance; /**< require-instance flag */
1350};
1351
1352struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001353 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001354 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001355 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001356 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 +01001357 LY_DATA_TYPE basetype; /**< Base type of the type */
1358 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001359 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001360 mandatory (at least 1 item) */
1361};
1362
1363struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001364 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001365 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001366 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001367 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 +01001368 LY_DATA_TYPE basetype; /**< Base type of the type */
1369 uint32_t refcount; /**< reference counter for type sharing */
1370 uint8_t require_instance; /**< require-instance flag */
1371};
1372
Radek Krejci2167ee12018-11-02 16:09:07 +01001373struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001374 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001375 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001376 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +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_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1381};
1382
1383struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001384 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001385 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001386 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001387 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 +01001388 LY_DATA_TYPE basetype; /**< Base type of the type */
1389 uint32_t refcount; /**< reference counter for type sharing */
1390 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001391};
1392
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001393struct lysc_action_inout {
1394 struct lysc_node *data; /**< first child node (linked list) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001395 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1396};
1397
Radek Krejci056d0a82018-12-06 16:57:25 +01001398struct lysc_action {
Michal Vasko1bf09392020-03-27 12:38:10 +01001399 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci056d0a82018-12-06 16:57:25 +01001400 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001401 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001402 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. */
1403 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1404
Radek Krejcifc11bd72019-04-11 16:00:05 +02001405 struct lysc_ext_instance *input_exts; /**< list of the extension instances of input ([sized array](@ref sizedarrays)) */
1406 struct lysc_ext_instance *output_exts; /**< list of the extension instances of outpu ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001407
Radek Krejci056d0a82018-12-06 16:57:25 +01001408 const char *name; /**< action/RPC name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001409 const char *dsc; /**< description */
1410 const char *ref; /**< reference */
1411
Radek Krejcifc11bd72019-04-11 16:00:05 +02001412 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1413 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1414
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001415 struct lysc_action_inout input; /**< RPC's/action's input */
1416 struct lysc_action_inout output; /**< RPC's/action's output */
1417
Radek Krejci056d0a82018-12-06 16:57:25 +01001418};
1419
1420struct lysc_notif {
1421 uint16_t nodetype; /**< LYS_NOTIF */
1422 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
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)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001436};
1437
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001438/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001439 * @brief Compiled YANG data node
1440 */
1441struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001442 uint16_t nodetype; /**< type of the node (mandatory) */
1443 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001444 struct lys_module *module; /**< module structure */
1445 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. */
1446 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1447 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1448 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1449 never NULL. If there is no sibling node, pointer points to the node
1450 itself. In case of the first node, this pointer points to the last
1451 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001452 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001453 const char *dsc; /**< description */
1454 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001455 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001456 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001457 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001458};
1459
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001460struct lysc_node_container {
1461 uint16_t nodetype; /**< LYS_CONTAINER */
1462 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1463 struct lys_module *module; /**< module structure */
1464 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. */
1465 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1466 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1467 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1468 never NULL. If there is no sibling node, pointer points to the node
1469 itself. In case of the first node, this pointer points to the last
1470 node in the list. */
1471 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001472 const char *dsc; /**< description */
1473 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001474 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001475 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001476 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001477
1478 struct lysc_node *child; /**< first child node (linked list) */
1479 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1480 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1481 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001482};
1483
Radek Krejcia3045382018-11-22 14:30:31 +01001484struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001485 uint16_t nodetype; /**< LYS_CASE */
1486 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1487 struct lys_module *module; /**< module structure */
1488 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1489 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1490 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1491 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1492 never NULL. If there is no sibling node, pointer points to the node
1493 itself. In case of the first node, this pointer points to the last
1494 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001495 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001496 const char *dsc; /**< description */
1497 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001498 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001499 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001500 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001501
Radek Krejcia3045382018-11-22 14:30:31 +01001502 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 +01001503 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001504};
1505
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001506struct lysc_node_choice {
1507 uint16_t nodetype; /**< LYS_CHOICE */
1508 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1509 struct lys_module *module; /**< module structure */
1510 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. */
1511 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1512 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1513 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1514 never NULL. If there is no sibling node, pointer points to the node
1515 itself. In case of the first node, this pointer points to the last
1516 node in the list. */
1517 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001518 const char *dsc; /**< description */
1519 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001520 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001521 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001522 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001523
Radek Krejcia9026eb2018-12-12 16:04:47 +01001524 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1525 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1526 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001527 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001528};
1529
1530struct lysc_node_leaf {
1531 uint16_t nodetype; /**< LYS_LEAF */
1532 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1533 struct lys_module *module; /**< module structure */
1534 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1535 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1536 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1537 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1538 never NULL. If there is no sibling node, pointer points to the node
1539 itself. In case of the first node, this pointer points to the last
1540 node in the list. */
1541 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001542 const char *dsc; /**< description */
1543 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001544 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001545 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001546 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001547
1548 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1549 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001550
Radek Krejci4f28eda2018-11-12 11:46:16 +01001551 const char *units; /**< units of the leaf's type */
Radek Krejcia1911222019-07-22 17:24:50 +02001552 struct lyd_value *dflt; /**< default value */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001553 struct lys_module *dflt_mod; /**< module where the lysc_node_leaf::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001554};
1555
1556struct lysc_node_leaflist {
1557 uint16_t nodetype; /**< LYS_LEAFLIST */
1558 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1559 struct lys_module *module; /**< module structure */
1560 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. */
1561 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1562 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1563 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1564 never NULL. If there is no sibling node, pointer points to the node
1565 itself. In case of the first node, this pointer points to the last
1566 node in the list. */
1567 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001568 const char *dsc; /**< description */
1569 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001570 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001571 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001572 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001573
1574 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1575 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1576
Radek Krejci0e5d8382018-11-28 16:37:53 +01001577 const char *units; /**< units of the leaf's type */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001578 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values */
1579 struct lys_module **dflts_mods; /**< list ([sized array](@ref sizedarrays)) of modules where the lysc_node_leaflist::dflts values were defined
1580 (needed to correctly map prefixes). */
Radek Krejci0e5d8382018-11-28 16:37:53 +01001581 uint32_t min; /**< min-elements constraint */
1582 uint32_t max; /**< max-elements constraint */
1583
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001584};
1585
1586struct lysc_node_list {
1587 uint16_t nodetype; /**< LYS_LIST */
1588 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1589 struct lys_module *module; /**< module structure */
1590 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. */
1591 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1592 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1593 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1594 never NULL. If there is no sibling node, pointer points to the node
1595 itself. In case of the first node, this pointer points to the last
1596 node in the list. */
1597 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001598 const char *dsc; /**< description */
1599 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001600 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001601 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001602 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001603
1604 struct lysc_node *child; /**< first child node (linked list) */
1605 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1606 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1607 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1608
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001609 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1610 uint32_t min; /**< min-elements constraint */
1611 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001612};
1613
1614struct lysc_node_anydata {
1615 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1616 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1617 struct lys_module *module; /**< module structure */
1618 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. */
1619 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1620 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1621 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1622 never NULL. If there is no sibling node, pointer points to the node
1623 itself. In case of the first node, this pointer points to the last
1624 node in the list. */
1625 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001626 const char *dsc; /**< description */
1627 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001628 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001629 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001630 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9800fb82018-12-13 14:26:23 +01001631
1632 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001633};
1634
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001635/**
1636 * @brief Compiled YANG schema tree structure representing YANG module.
1637 *
1638 * Semantically validated YANG schema tree for data tree parsing.
1639 * Contains only the necessary information for the data validation.
1640 */
1641struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001642 struct lys_module *mod; /**< covering module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001643 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001644
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001645 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001646 struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1647 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1648 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1649 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001650 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001651};
1652
1653/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001654 * @brief Get the groupings sized array of the given (parsed) schema node.
1655 * Decides the node's type and in case it has a groupings array, returns it.
1656 * @param[in] node Node to examine.
1657 * @return The node's groupings sized array if any, NULL otherwise.
1658 */
1659const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1660
1661/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001662 * @brief Get the typedefs sized array of the given (parsed) schema node.
1663 * Decides the node's type and in case it has a typedefs array, returns it.
1664 * @param[in] node Node to examine.
1665 * @return The node's typedefs sized array if any, NULL otherwise.
1666 */
1667const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1668
1669/**
1670 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1671 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1672 * @param[in] node Node to examine.
1673 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1674 */
1675const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1676
1677/**
1678 * @brief Get the Notifications sized array of the given (parsed) schema node.
1679 * Decides the node's type and in case it has a Notifications array, returns it.
1680 * @param[in] node Node to examine.
1681 * @return The node's Notifications sized array if any, NULL otherwise.
1682 */
1683const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1684
1685/**
1686 * @brief Get the children linked list of the given (parsed) schema node.
1687 * Decides the node's type and in case it has a children list, returns it.
1688 * @param[in] node Node to examine.
1689 * @return The node's children linked list if any, NULL otherwise.
1690 */
1691const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1692
1693/**
1694 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1695 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1696 * @param[in] node Node to examine.
1697 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1698 */
1699const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1700
1701/**
1702 * @brief Get the Notifications sized array of the given (compiled) schema node.
1703 * Decides the node's type and in case it has a Notifications array, returns it.
1704 * @param[in] node Node to examine.
1705 * @return The node's Notifications sized array if any, NULL otherwise.
1706 */
1707const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1708
1709/**
1710 * @brief Get the children linked list of the given (compiled) schema node.
1711 * Decides the node's type and in case it has a children list, returns it.
1712 * @param[in] node Node to examine.
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001713 * @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 +01001714 * @return The node's children linked list if any, NULL otherwise.
1715 */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001716const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Radek Krejci056d0a82018-12-06 16:57:25 +01001717
1718/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001719 * @brief Get how the if-feature statement currently evaluates.
1720 *
1721 * @param[in] iff Compiled if-feature statement to evaluate.
1722 * @return If the statement evaluates to true, 1 is returned. 0 is returned when the statement evaluates to false.
1723 */
1724int lysc_iffeature_value(const struct lysc_iffeature *iff);
1725
1726/**
1727 * @brief Get the current status of the provided feature.
1728 *
1729 * @param[in] feature Compiled feature statement to examine.
1730 * @return
1731 * - 1 if feature is enabled,
1732 * - 0 if feature is disabled,
1733 * - -1 in case of error (invalid argument)
1734 */
1735int lysc_feature_value(const struct lysc_feature *feature);
1736
1737/**
Michal Vasko03ff5a72019-09-11 13:49:33 +02001738 * @brief Types of the different schema paths.
1739 */
1740typedef enum {
1741 LYSC_PATH_LOG /**< Descriptive path format used in log messages */
1742} LYSC_PATH_TYPE;
1743
1744/**
Radek Krejci327de162019-06-14 12:52:07 +02001745 * @brief Generate path of the given node in the requested format.
1746 *
1747 * @param[in] node Schema path of this node will be generated.
1748 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001749 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
1750 * If NULL, memory for the complete path is allocated.
1751 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02001752 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001753 * 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 +02001754 */
Michal Vasko03ff5a72019-09-11 13:49:33 +02001755char *lysc_path(const struct lysc_node *node, LYSC_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02001756
1757/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001758 * @brief Available YANG schema tree structures representing YANG module.
1759 */
1760struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001761 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
1762 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01001763 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001764 const char *ns; /**< namespace of the module (module - mandatory) */
1765 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
1766 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1767 const char *org; /**< party/company responsible for the module */
1768 const char *contact; /**< contact information for the module */
1769 const char *dsc; /**< description of the module */
1770 const char *ref; /**< cross-reference for the module */
1771
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001772 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01001773 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
1774 Available only for implemented modules. */
1775 struct lysc_feature *off_features;/**< List of pre-compiled features of the module in non implemented modules ([sized array](@ref sizedarrays)).
1776 These features are always disabled and cannot be enabled until the module
1777 become implemented. The features are present in this form to allow their linkage
1778 from if-feature statements of the compiled schemas and their proper use in case
1779 the module became implemented in future (no matter if implicitly via augment/deviate
1780 or explicitly via ly_ctx_module_implement()). */
Radek Krejci95710c92019-02-11 15:49:55 +01001781 uint8_t implemented; /**< flag if the module is implemented, not just imported. The module is implemented if
1782 the flag has non-zero value. Specific values are used internally:
1783 1 - implemented module
1784 2 - recently implemented module by dependency, it can be reverted in rollback procedure */
1785 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001786 1 - the latest revision in searchdirs was not searched yet and this is the
1787 latest revision in the current context
1788 2 - searchdirs were searched and this is the latest available revision */
1789 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001790};
1791
Radek Krejci151a5b72018-10-19 14:21:44 +02001792/**
1793 * @brief Enable specified feature in the module
1794 *
1795 * By default, when the module is loaded by libyang parser, all features are disabled.
1796 *
Radek Krejcica3db002018-11-01 10:31:01 +01001797 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
1798 * enabling all features on the following feature set will fail since it is not possible to enable both features
1799 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
1800 * is untouched.
1801 *
1802 * feature f1;
1803 * feature f2 { if-feature 'not f1';}
1804 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001805 * @param[in] module Module where the feature will be enabled.
1806 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
1807 * @return LY_ERR value.
1808 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001809LY_ERR lys_feature_enable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001810
1811/**
1812 * @brief Disable specified feature in the module
1813 *
1814 * By default, when the module is loaded by libyang parser, all features are disabled.
1815 *
1816 * @param[in] module Module where the feature will be disabled.
1817 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
1818 * @return LY_ERR value
1819 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001820LY_ERR lys_feature_disable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001821
1822/**
1823 * @brief Get the current status of the specified feature in the module.
1824 *
1825 * @param[in] module Module where the feature is defined.
1826 * @param[in] feature Name of the feature to inspect.
1827 * @return
1828 * - 1 if feature is enabled,
1829 * - 0 if feature is disabled,
1830 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
1831 */
1832int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001833
1834/**
Radek Krejci86d106e2018-10-18 09:53:19 +02001835 * @brief Load a schema into the specified context.
1836 *
1837 * @param[in] ctx libyang context where to process the data model.
1838 * @param[in] data The string containing the dumped data model in the specified
1839 * format.
1840 * @param[in] format Format of the input data (YANG or YIN).
1841 * @return Pointer to the data model structure or NULL on error.
1842 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001843struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001844
1845/**
1846 * @brief Read a schema from file descriptor into the specified context.
1847 *
1848 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
1849 *
1850 * @param[in] ctx libyang context where to process the data model.
1851 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
1852 * in the specified format.
1853 * @param[in] format Format of the input data (YANG or YIN).
1854 * @return Pointer to the data model structure or NULL on error.
1855 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001856struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001857
1858/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001859 * @brief Read a schema into the specified context from a file.
Radek Krejci86d106e2018-10-18 09:53:19 +02001860 *
1861 * @param[in] ctx libyang context where to process the data model.
1862 * @param[in] path Path to the file with the model in the specified format.
1863 * @param[in] format Format of the input data (YANG or YIN).
1864 * @return Pointer to the data model structure or NULL on error.
1865 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001866struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001867
1868/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001869 * @brief Search for the schema file in the specified searchpaths.
1870 *
1871 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
1872 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
1873 * result of the ly_ctx_get_searchdirs().
1874 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
1875 * @param[in] name Name of the schema to find.
1876 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
1877 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
1878 * complying the provided restriction is found, NULL is set.
1879 * @param[out] format Optional output variable containing expected format of the schema document according to the
1880 * file suffix.
1881 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
1882 */
1883LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
1884
1885/**
Radek Krejcia3045382018-11-22 14:30:31 +01001886 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
1887 * be from an augment.
1888 *
1889 * lys_getnext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
1890 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
1891 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
1892 * \p parent and \p module parameters.
1893 *
1894 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
1895 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
1896 * all the schema nodes are iteratively returned.
1897 *
1898 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
1899 * @param[in] parent Parent of the subtree where the function starts processing.
1900 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
1901 * module must be specified.
1902 * @param[in] options [ORed options](@ref sgetnextflags).
1903 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
1904 */
1905const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
1906 const struct lysc_module *module, int options);
1907
1908/**
1909 * @defgroup sgetnextflags lys_getnext() flags
1910 * @ingroup schematree
1911 *
1912 * @{
1913 */
1914#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 +01001915#define LYS_GETNEXT_NOCHOICE 0x02 /**< lys_getnext() option to ignore (kind of conditional) nodes within choice node */
Radek Krejci056d0a82018-12-06 16:57:25 +01001916#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 +01001917#define LYS_GETNEXT_INTONPCONT 0x40 /**< lys_getnext() option to look into non-presence container, instead of returning container itself */
1918#define LYS_GETNEXT_NOSTATECHECK 0x100 /**< lys_getnext() option to skip checking module validity (import-only, disabled) and
1919 relevant if-feature conditions state */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001920#define LYS_GETNEXT_OUTPUT 0x200 /**< lys_getnext() option to provide RPC's/action's output schema nodes instead of input schema nodes
1921 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01001922/** @} sgetnextflags */
1923
1924/**
1925 * @brief Get child node according to the specified criteria.
1926 *
1927 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
1928 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
1929 * @param[in] name Name of the node to find.
1930 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
1931 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
1932 * Used as a bitmask, so multiple nodetypes can be specified.
1933 * @param[in] options [ORed options](@ref sgetnextflags).
1934 * @return Found node if any.
1935 */
Michal Vaskoe444f752020-02-10 12:20:06 +01001936const struct lysc_node *lys_find_child(const struct lysc_node *parent, const struct lys_module *module,
1937 const char *name, size_t name_len, uint16_t nodetype, int options);
Radek Krejcia3045382018-11-22 14:30:31 +01001938
1939/**
Radek Krejci77a8bcd2019-09-11 11:20:02 +02001940 * @brief Make the specific module implemented.
1941 *
1942 * @param[in] mod Module to make implemented. It is not an error
1943 * to provide already implemented module, it just does nothing.
Michal Vaskoe444f752020-02-10 12:20:06 +01001944 * @return LY_SUCCESS on success.
1945 * @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 +02001946 */
1947LY_ERR lys_set_implemented(struct lys_module *mod);
1948
1949/**
Radek Krejcia3045382018-11-22 14:30:31 +01001950 * @brief Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statement
1951 * affecting the node.
1952 *
1953 * @param[in] node Schema node to check.
1954 * @param[in] recursive - 0 to check if-feature only in the \p node schema node,
1955 * - 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 +01001956 * @return NULL if enabled,
Michal Vaskoc193ce92020-03-06 11:04:48 +01001957 * @return pointer to the node with the unsatisfied (disabled) if-feature expression.
Radek Krejcia3045382018-11-22 14:30:31 +01001958 */
Michal Vaskoc193ce92020-03-06 11:04:48 +01001959const struct lysc_node *lysc_node_is_disabled(const struct lysc_node *node, int recursive);
Radek Krejcia3045382018-11-22 14:30:31 +01001960
Radek Krejci084289f2019-07-09 17:35:30 +02001961/**
1962 * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
1963 *
1964 * This function check just the type's restriction, if you want to check also the data tree context (e.g. in case of
1965 * require-instance restriction), use lyd_value_validate().
1966 *
1967 * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
1968 * @param[in] node Schema node for the @p value.
1969 * @param[in] value String value to be checked.
1970 * @param[in] value_len Length of the given @p value (mandatory).
1971 * @param[in] get_prefix Callback function to resolve prefixes used in the @p value string.
1972 * @param[in] get_prefix_data Private data for the @p get_prefix callback.
1973 * @param[in] format Input format of the @p value.
1974 * @return LY_SUCCESS on success
1975 * @return LY_ERR value if an error occurred.
1976 */
Michal Vasko44685da2020-03-17 15:38:06 +01001977LY_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 +02001978 ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format);
1979
Radek Krejci0935f412019-08-20 16:15:18 +02001980/**
1981 * @brief Stringify schema nodetype.
1982 * @param[in] nodetype Nodetype to stringify.
1983 * @return Constant string with the name of the node's type.
1984 */
1985const char *lys_nodetype2str(uint16_t nodetype);
1986
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001987/** @} */
1988
Radek Krejci70853c52018-10-15 14:46:16 +02001989#ifdef __cplusplus
1990}
1991#endif
1992
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001993#endif /* LY_TREE_SCHEMA_H_ */