blob: eb0f60918fcacdf3cff9588da7d066ee5d650daf [file] [log] [blame]
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001/**
2 * @file tree_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief libyang representation of YANG schema trees.
5 *
6 * Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_TREE_SCHEMA_H_
16#define LY_TREE_SCHEMA_H_
17
Radek Krejci54579462019-04-30 12:47:06 +020018#define PCRE2_CODE_UNIT_WIDTH 8
19
20#include <pcre2.h>
Radek Krejci535ea9f2020-05-29 16:01:05 +020021
Radek Krejci5aeea3a2018-09-05 13:29:36 +020022#include <stdint.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020023#include <stdio.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020024
Radek Krejcie7b95092019-05-15 11:03:07 +020025#include "log.h"
26#include "tree.h"
Radek Krejcice8c1592018-10-29 15:35:51 +010027
Radek Krejci70853c52018-10-15 14:46:16 +020028#ifdef __cplusplus
29extern "C" {
30#endif
31
Radek Krejcica376bd2020-06-11 16:04:06 +020032struct ly_ctx;
Radek Krejci47fab892020-11-05 17:02:41 +010033struct ly_path;
Radek Krejcica376bd2020-06-11 16:04:06 +020034struct ly_set;
Radek Krejci47fab892020-11-05 17:02:41 +010035struct lys_module;
36struct lysc_node;
37struct lyxp_expr;
Radek Krejcica376bd2020-06-11 16:04:06 +020038
Radek Krejci5aeea3a2018-09-05 13:29:36 +020039/**
Radek Krejci8678fa42020-08-18 16:07:28 +020040 * @page howtoSchema YANG Modules
41 *
42 * To be able to work with YANG data instances, libyang has to represent YANG data models. All the processed modules are stored
43 * in libyang [context](@ref howtoContext) and loaded using [parser functions](@ref howtoSchemaParsers). It means, that there is
44 * no way to create/change YANG module programmatically. However, all the YANG model definitions are available and can be examined
45 * through the C structures. All the context's modules together form YANG Schema for the data being instantiated.
46 *
47 * Any YANG module is represented as ::lys_module. In fact, the module is represented in two different formats. As ::lys_module.parsed,
48 * there is a parsed schema reflecting the source YANG module. It is exactly what is read from the input. This format is good for
49 * converting from one format to another (YANG to YIN and vice versa), but it is not very useful for validating/manipulating YANG
50 * data. Therefore, there is ::lys_module.compiled storing the compiled YANG module. It is based on the parsed module, but all the
51 * references are resolved. It means that, for example, there are no `grouping`s or `typedef`s since they are supposed to be placed instead of
52 * `uses` or `type` references. This split also means, that the YANG module is fully validated after compilation of the parsed
53 * representation of the module. YANG submodules are available only in the parsed representation. When a submodule is compiled, it
54 * is fully integrated into its main module.
55 *
56 * The context can contain even modules without the compiled representation. Such modules are still useful as imports of other
57 * modules. The grouping or typedef definition can be even compiled into the importing modules. This is actually the main
58 * difference between the imported and implemented modules in the libyang context. The implemented modules are compiled while the
59 * imported modules are only parsed.
60 *
Radek Krejcib100b192020-10-26 08:37:45 +010061 * By default, the module is implemented (and compiled) in case it is explicitly loaded or referenced in another module as
62 * target of leafref, augment or deviation. This behavior can be changed via context options ::LY_CTX_ALL_IMPLEMENTED, when
63 * all the modules in the context are marked as implemented (note the problem with multiple revisions of a single module),
64 * or by ::LY_CTX_REF_IMPLEMENTED option, extending the set of references making the module implemented by when, must and
65 * default statements.
Radek Krejci8678fa42020-08-18 16:07:28 +020066 *
67 * All modules with deviation definition are always marked as implemented. The imported (not implemented) module can be set implemented by ::lys_set_implemented(). But
68 * the implemented module cannot be changed back to just imported module. Note also that only one revision of a specific module
69 * can be implemented in a single context. The imported modules are used only as a
70 * source of definitions for types and groupings for uses statements. The data in such modules are ignored - caller
71 * is not allowed to create the data (including instantiating identities) defined in the model via data parsers,
72 * the default nodes are not added into any data tree and mandatory nodes are not checked in the data trees.
73 *
74 * The compiled schema tree nodes are able to hold private objects (::lysc_node.priv as a pointer to a structure, function, variable, ...) used by
75 * a caller application. Such an object can be assigned to a specific node using ::lysc_set_private() function.
76 * Note that the object is not freed by libyang when the context is being destroyed. So the caller is responsible
77 * for freeing the provided structure after the context is destroyed or the private pointer is set to NULL in
78 * appropriate schema nodes where the object was previously set. This can be automated via destructor function
79 * to free these private objects. The destructor is passed to the ::ly_ctx_destroy() function.
80 *
81 * Despite all the schema structures and their members are available as part of the libyang API and callers can use
82 * it to navigate through the schema tree structure or to obtain various information, we recommend to use the following
83 * macros for the specific actions.
84 * - ::LYSC_TREE_DFS_BEGIN and ::LYSC_TREE_DFS_END to traverse the schema tree (depth-first).
85 * - ::LY_LIST_FOR and ::LY_ARRAY_FOR as described on @ref howtoStructures page.
86 *
87 * Further information about modules handling can be found on the following pages:
88 * - @subpage howtoSchemaParsers
89 * - @subpage howtoSchemaFeatures
90 * - @subpage howtoPlugins
91 * - @subpage howtoSchemaPrinters
92 *
93 * \note There are many functions to access information from the schema trees. Details are available in
94 * the [Schema Tree module](@ref schematree).
95 *
96 * For information about difference between implemented and imported modules, see the
97 * [context description](@ref howtoContext).
98 *
99 * Functions List (not assigned to above subsections)
100 * --------------------------------------------------
101 * - ::lys_getnext()
102 * - ::lys_nodetype2str()
103 * - ::lys_set_implemented()
104 * - ::lys_value_validate()
105 *
106 * - ::lysc_set_private()
107 *
Michal Vaskod5cfa6e2020-11-23 16:56:08 +0100108 * - ::lysc_has_when()
109 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200110 * - ::lysc_node_children()
Michal Vasko208a04a2020-10-21 15:17:12 +0200111 * - ::lysc_node_parent_full()
Radek Krejci8678fa42020-08-18 16:07:28 +0200112 * - ::lysc_node_actions()
113 * - ::lysc_node_notifs()
114 *
115 * - ::lysp_node_children()
116 * - ::lysp_node_actions()
117 * - ::lysp_node_notifs()
118 * - ::lysp_node_groupings()
119 * - ::lysp_node_typedefs()
120 */
121
122/**
123 * @page howtoSchemaFeatures YANG Features
124 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100125 * YANG feature statement is an important part of the language which can significantly affect the meaning of the schemas.
126 * Modifying features may have similar effects as loading/removing schema from the context so it is limited to context
127 * preparation period before working with data. YANG features, respectively their use in if-feature
128 * statements, are evaluated as part of schema compilation so a feature-specific compiled schema tree is generated
129 * as a result.
Radek Krejci8678fa42020-08-18 16:07:28 +0200130 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100131 * To enable any features, they must currently be specified when implementing a new schema with ::lys_parse() or
132 * ::ly_ctx_load_module(). To later examine what the status of a feature is, check its ::LYS_FENABLED flag or
133 * search for it first with ::lys_feature_value(). Lastly, to evaluate compiled if-features, use ::lysc_iffeature_value().
Radek Krejci8678fa42020-08-18 16:07:28 +0200134 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100135 * To iterate over all features of a particular YANG module, use ::lysp_feature_next().
Radek Krejci8678fa42020-08-18 16:07:28 +0200136 *
137 * Note, that the feature's state can affect some of the output formats (e.g. Tree format).
138 *
139 * Functions List
140 * --------------
Radek Krejci8678fa42020-08-18 16:07:28 +0200141 * - ::lys_feature_value()
Radek Krejci8678fa42020-08-18 16:07:28 +0200142 * - ::lysc_iffeature_value()
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100143 * - ::lysp_feature_next()
Radek Krejci8678fa42020-08-18 16:07:28 +0200144 */
145
146/**
Radek Krejci2ff0d572020-05-21 15:27:28 +0200147 * @ingroup trees
Radek Krejci8678fa42020-08-18 16:07:28 +0200148 * @defgroup schematree Schema Tree
Radek Krejci2ff0d572020-05-21 15:27:28 +0200149 * @{
150 *
151 * Data structures and functions to manipulate and access schema tree.
152 */
153
Michal Vasko64246d82020-08-19 12:35:00 +0200154/* *INDENT-OFF* */
155
Radek Krejci2ff0d572020-05-21 15:27:28 +0200156/**
Michal Vasko208a04a2020-10-21 15:17:12 +0200157 * @brief Macro to iterate via all elements in a schema (sub)tree including input and output.
158 * Note that __actions__ and __notifications__ of traversed nodes __are ignored__! To traverse
159 * on all the nodes including those, use ::lysc_tree_dfs_full() instead.
160 *
161 * 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 +0200162 *
163 * The function follows deep-first search algorithm:
164 * <pre>
165 * 1
166 * / \
167 * 2 4
168 * / / \
169 * 3 5 6
170 * </pre>
171 *
172 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
Radek Krejci2a9fc652021-01-22 17:44:34 +0100173 * START can be any of the lysc_node* types (including lysc_node_action and lysc_node_notif),
Radek Krejci0935f412019-08-20 16:15:18 +0200174 * ELEM variable must be of the struct lysc_node* type.
175 *
176 * To skip a particular subtree, instead of the continue statement, set LYSC_TREE_DFS_continue
177 * variable to non-zero value.
178 *
179 * Use with opening curly bracket '{' after the macro.
180 *
181 * @param START Pointer to the starting element processed first.
182 * @param ELEM Iterator intended for use in the block.
183 */
184#define LYSC_TREE_DFS_BEGIN(START, ELEM) \
Radek Krejci857189e2020-09-01 13:26:36 +0200185 { ly_bool LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
Michal Vasko1c9e79f2020-08-10 11:08:03 +0200186 for ((ELEM) = (LYSC_TREE_DFS_next) = (struct lysc_node*)(START); \
Radek Krejci0935f412019-08-20 16:15:18 +0200187 (ELEM); \
188 (ELEM) = (LYSC_TREE_DFS_next), LYSC_TREE_DFS_continue = 0)
189
190/**
191 * @brief Macro to iterate via all elements in a (sub)tree. This is the closing part
192 * to the #LYSC_TREE_DFS_BEGIN - they always have to be used together.
193 *
194 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
Radek Krejci2a9fc652021-01-22 17:44:34 +0100195 * START can be a pointer to any of the lysc_node* types (including lysc_node_action and lysc_node_notif),
Radek Krejci0935f412019-08-20 16:15:18 +0200196 * ELEM variable must be pointer to the lysc_node type.
197 *
198 * Use with closing curly bracket '}' after the macro.
199 *
200 * @param START Pointer to the starting element processed first.
201 * @param ELEM Iterator intended for use in the block.
202 */
Radek Krejci0935f412019-08-20 16:15:18 +0200203#define LYSC_TREE_DFS_END(START, ELEM) \
204 /* select element for the next run - children first */ \
205 if (LYSC_TREE_DFS_continue) { \
206 (LYSC_TREE_DFS_next) = NULL; \
207 } else { \
Radek Krejci2a9fc652021-01-22 17:44:34 +0100208 (LYSC_TREE_DFS_next) = (struct lysc_node *)lysc_node_children(ELEM, 0); \
Michal Vasko208a04a2020-10-21 15:17:12 +0200209 } \
Radek Krejci0935f412019-08-20 16:15:18 +0200210 if (!(LYSC_TREE_DFS_next)) { \
Michal Vasko208a04a2020-10-21 15:17:12 +0200211 /* no children, try siblings */ \
212 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
Radek Krejci0935f412019-08-20 16:15:18 +0200213 } \
214 while (!(LYSC_TREE_DFS_next)) { \
215 /* parent is already processed, go to its sibling */ \
Michal Vasko208a04a2020-10-21 15:17:12 +0200216 (ELEM) = (struct lysc_node *)lysc_node_parent_full(ELEM); \
217 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
218 } }
219
220/**
221 * @brief Helper macro for #LYSC_TREE_DFS_END, should not be used directly!
222 */
223#define _LYSC_TREE_DFS_NEXT(START, ELEM, NEXT) \
224 if ((ELEM) == (struct lysc_node *)(START)) { \
225 /* we are done, no next element to process */ \
226 break; \
227 } \
228 if ((ELEM)->nodetype == LYS_INPUT) { \
229 /* after input, get output */ \
Radek Krejci2a9fc652021-01-22 17:44:34 +0100230 (NEXT) = (struct lysc_node *)lysc_node_children(lysc_node_parent_full(ELEM), LYS_CONFIG_R); \
Michal Vasko208a04a2020-10-21 15:17:12 +0200231 } else if ((ELEM)->nodetype == LYS_OUTPUT) { \
232 /* no sibling of output */ \
233 (NEXT) = NULL; \
234 } else { \
235 (NEXT) = (ELEM)->next; \
236 }
Radek Krejci0935f412019-08-20 16:15:18 +0200237
Michal Vasko64246d82020-08-19 12:35:00 +0200238/* *INDENT-ON* */
239
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200240#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
241
Michal Vasko7f45cf22020-10-01 12:49:44 +0200242#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
243#define LYS_CONTAINER 0x0001 /**< container statement node */
244#define LYS_CHOICE 0x0002 /**< choice statement node */
245#define LYS_LEAF 0x0004 /**< leaf statement node */
246#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
247#define LYS_LIST 0x0010 /**< list statement node */
248#define LYS_ANYXML 0x0020 /**< anyxml statement node */
249#define LYS_ANYDATA 0x0060 /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
250#define LYS_CASE 0x0080 /**< case statement node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200251
Michal Vasko7f45cf22020-10-01 12:49:44 +0200252#define LYS_RPC 0x0100 /**< RPC statement node */
253#define LYS_ACTION 0x0200 /**< action statement node */
254#define LYS_NOTIF 0x0400 /**< notification statement node */
Radek Krejcie7b95092019-05-15 11:03:07 +0200255
Michal Vasko7f45cf22020-10-01 12:49:44 +0200256#define LYS_USES 0x0800 /**< uses statement node */
257#define LYS_INPUT 0x1000 /**< RPC/action input node */
258#define LYS_OUTPUT 0x2000 /**< RPC/action output node */
259#define LYS_GROUPING 0x4000
260#define LYS_AUGMENT 0x8000
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100261
Radek Krejcif13b87b2020-12-01 22:02:17 +0100262#define LYS_NODETYPE_MASK 0xffff /**< Mask for nodetypes, the value is limited for 16 bits */
263
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200264/**
Radek Krejcid6b76452019-09-03 17:03:03 +0200265 * @brief List of YANG statements
266 */
267enum ly_stmt {
268 LY_STMT_NONE = 0,
Radek Krejci8678fa42020-08-18 16:07:28 +0200269 LY_STMT_STATUS, /**< in ::lysc_ext_substmt.storage stored as a pointer to `uint16_t`, only cardinality < #LY_STMT_CARD_SOME is allowed */
270 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 +0200271 LY_STMT_MANDATORY,
Radek Krejci8678fa42020-08-18 16:07:28 +0200272 LY_STMT_UNITS, /**< in ::lysc_ext_substmt.storage stored as a pointer to `const char *` (cardinality < #LY_STMT_CARD_SOME)
Radek Krejciad5963b2019-09-06 16:03:05 +0200273 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200274 LY_STMT_DEFAULT,
Radek Krejci8678fa42020-08-18 16:07:28 +0200275 LY_STMT_TYPE, /**< in ::lysc_ext_substmt.storage stored as a pointer to `struct lysc_type *` (cardinality < #LY_STMT_CARD_SOME)
Radek Krejciad5963b2019-09-06 16:03:05 +0200276 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_type **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200277
Radek Krejcid6b76452019-09-03 17:03:03 +0200278 LY_STMT_ACTION,
279 LY_STMT_ANYDATA,
280 LY_STMT_ANYXML,
281 LY_STMT_ARGUMENT,
282 LY_STMT_AUGMENT,
283 LY_STMT_BASE,
284 LY_STMT_BELONGS_TO,
285 LY_STMT_BIT,
286 LY_STMT_CASE,
287 LY_STMT_CHOICE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200288 LY_STMT_CONTACT,
289 LY_STMT_CONTAINER,
Radek Krejcid6b76452019-09-03 17:03:03 +0200290 LY_STMT_DESCRIPTION,
291 LY_STMT_DEVIATE,
292 LY_STMT_DEVIATION,
293 LY_STMT_ENUM,
294 LY_STMT_ERROR_APP_TAG,
295 LY_STMT_ERROR_MESSAGE,
296 LY_STMT_EXTENSION,
297 LY_STMT_FEATURE,
298 LY_STMT_FRACTION_DIGITS,
299 LY_STMT_GROUPING,
300 LY_STMT_IDENTITY,
Radek Krejci8678fa42020-08-18 16:07:28 +0200301 LY_STMT_IF_FEATURE, /**< in ::lysc_ext_substmt.storage stored as a pointer to `struct lysc_iffeature` (cardinality < #LY_STMT_CARD_SOME)
Radek Krejciad5963b2019-09-06 16:03:05 +0200302 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_iffeature *` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200303 LY_STMT_IMPORT,
304 LY_STMT_INCLUDE,
305 LY_STMT_INPUT,
306 LY_STMT_KEY,
307 LY_STMT_LEAF,
308 LY_STMT_LEAF_LIST,
309 LY_STMT_LENGTH,
310 LY_STMT_LIST,
Radek Krejcid6b76452019-09-03 17:03:03 +0200311 LY_STMT_MAX_ELEMENTS,
312 LY_STMT_MIN_ELEMENTS,
313 LY_STMT_MODIFIER,
314 LY_STMT_MODULE,
315 LY_STMT_MUST,
316 LY_STMT_NAMESPACE,
317 LY_STMT_NOTIFICATION,
318 LY_STMT_ORDERED_BY,
319 LY_STMT_ORGANIZATION,
320 LY_STMT_OUTPUT,
321 LY_STMT_PATH,
322 LY_STMT_PATTERN,
323 LY_STMT_POSITION,
324 LY_STMT_PREFIX,
325 LY_STMT_PRESENCE,
326 LY_STMT_RANGE,
327 LY_STMT_REFERENCE,
328 LY_STMT_REFINE,
329 LY_STMT_REQUIRE_INSTANCE,
330 LY_STMT_REVISION,
331 LY_STMT_REVISION_DATE,
332 LY_STMT_RPC,
Radek Krejcid6b76452019-09-03 17:03:03 +0200333 LY_STMT_SUBMODULE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200334 LY_STMT_TYPEDEF,
335 LY_STMT_UNIQUE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200336 LY_STMT_USES,
337 LY_STMT_VALUE,
338 LY_STMT_WHEN,
339 LY_STMT_YANG_VERSION,
340 LY_STMT_YIN_ELEMENT,
341 LY_STMT_EXTENSION_INSTANCE,
342
343 LY_STMT_SYNTAX_SEMICOLON,
344 LY_STMT_SYNTAX_LEFT_BRACE,
345 LY_STMT_SYNTAX_RIGHT_BRACE,
346
347 LY_STMT_ARG_TEXT,
348 LY_STMT_ARG_VALUE
349};
350
351/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200352 * @brief Extension instance structure parent enumeration
353 */
354typedef enum {
Radek Krejci0935f412019-08-20 16:15:18 +0200355 LYEXT_PAR_MODULE, /**< ::lysc_module */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100356 LYEXT_PAR_NODE, /**< ::lysc_node (and the derived structures including ::lysc_node_action and ::lysc_node_notif) */
357 LYEXT_PAR_INPUT, /**< ::lysc_node_action_inout */
358 LYEXT_PAR_OUTPUT, /**< ::lysc_node_action_inout */
Radek Krejci0935f412019-08-20 16:15:18 +0200359 LYEXT_PAR_TYPE, /**< ::lysc_type */
360 LYEXT_PAR_TYPE_BIT, /**< ::lysc_type_bitenum_item */
361 LYEXT_PAR_TYPE_ENUM, /**< ::lysc_type_bitenum_item */
Radek Krejci0935f412019-08-20 16:15:18 +0200362 LYEXT_PAR_MUST, /**< ::lysc_must */
363 LYEXT_PAR_PATTERN, /**< ::lysc_pattern */
364 LYEXT_PAR_LENGTH, /**< ::lysc_range */
365 LYEXT_PAR_RANGE, /**< ::lysc_range */
366 LYEXT_PAR_WHEN, /**< ::lysc_when */
367 LYEXT_PAR_IDENT, /**< ::lysc_ident */
368 LYEXT_PAR_EXT, /**< ::lysc_ext */
Michal Vasko69730152020-10-09 16:30:07 +0200369 LYEXT_PAR_IMPORT /**< ::lysp_import */
Radek Krejcif13b87b2020-12-01 22:02:17 +0100370#if 0
371 LYEXT_PAR_TPDF, /**< ::lysp_tpdf */
372 LYEXT_PAR_EXTINST, /**< ::lysp_ext_instance */
373 LYEXT_PAR_REFINE, /**< ::lysp_refine */
374 LYEXT_PAR_DEVIATION, /**< ::lysp_deviation */
375 LYEXT_PAR_DEVIATE, /**< ::lysp_deviate */
376 LYEXT_PAR_INCLUDE, /**< ::lysp_include */
377 LYEXT_PAR_REVISION /**< ::lysp_revision */
378#endif
Radek Krejci0e59c312019-08-15 15:34:15 +0200379} LYEXT_PARENT;
380
381/**
Radek Krejci0935f412019-08-20 16:15:18 +0200382 * @brief Stringify extension instance parent type.
383 * @param[in] type Parent type to stringify.
384 * @return Constant string with the name of the parent statement.
385 */
386const char *lyext_parent2str(LYEXT_PARENT type);
387
388/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200389 * @brief Enum of substatements in which extension instances can appear.
390 */
391typedef enum {
392 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
393 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
394 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
395 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
396 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
397 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
398 lys_node_choice and lys_deviate */
399 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
400 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
401 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
402 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
403 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
404 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
405 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
406 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
407 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
408 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
409 belongs-to's prefix) and lys_import */
410 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
411 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
412 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
413 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
414 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
415 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
416 lys_node_leaflist and lys_deviate */
417 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
418 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
419 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
420 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
421 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
422 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
423 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
424 lys_node_anydata and lys_deviate */
425 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
426 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
427 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
428 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
429 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
430 lys_node_leaflist and lys_deviate */
431 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
432 lys_node_leaflist and lys_deviate */
433 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
434 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
Michal Vasko69730152020-10-09 16:30:07 +0200435 LYEXT_SUBSTMT_IFFEATURE /**< extension of the if-feature statement */
Radek Krejci0e59c312019-08-15 15:34:15 +0200436} LYEXT_SUBSTMT;
437
438/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200439 * @brief YANG import-stmt
440 */
441struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200442 struct lys_module *module; /**< pointer to the imported module
443 (mandatory, but resolved when the referring module is completely parsed) */
444 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200445 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200446 const char *dsc; /**< description */
447 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200448 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100449 uint16_t flags; /**< LYS_INTERNAL value (@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200450 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
451};
452
453/**
454 * @brief YANG include-stmt
455 */
456struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100457 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200458 (mandatory, but resolved when the referring module is completely parsed) */
459 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200460 const char *dsc; /**< description */
461 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200462 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200463 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
Radek Krejci771928a2021-01-19 13:42:36 +0100464 ly_bool injected; /**< flag to mark includes copied into main module from submodules,
465 only for backward compatibility with YANG 1.0, which does not require the
466 main module to include all submodules. */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200467};
468
469/**
470 * @brief YANG extension-stmt
471 */
472struct lysp_ext {
473 const char *name; /**< extension name */
474 const char *argument; /**< argument name, NULL if not specified */
475 const char *dsc; /**< description statement */
476 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200477 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200478 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */
Michal Vasko5fe75f12020-03-02 13:52:37 +0100479
480 struct lysc_ext *compiled; /**< pointer to the compiled extension definition */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200481};
482
483/**
484 * @brief Helper structure for generic storage of the extension instances content.
485 */
486struct lysp_stmt {
487 const char *stmt; /**< identifier of the statement */
488 const char *arg; /**< statement's argument */
489 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200490 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
David Sedlákb9d75c42019-08-14 10:49:42 +0200491 uint16_t flags; /**< statement flags, can be set to LYS_YIN_ATTR */
Radek Krejci335332a2019-09-05 13:03:35 +0200492 enum ly_stmt kw; /**< numeric respresentation of the stmt value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200493};
494
David Sedlákae4b4512019-08-14 10:45:56 +0200495#define LYS_YIN 0x1 /**< used to specify input format of extension instance */
496
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200497/**
498 * @brief YANG extension instance
499 */
500struct lysp_ext_instance {
David Sedlákbbd06ca2019-06-27 14:15:38 +0200501 const char *name; /**< extension identifier, including possible prefix */
502 const char *argument; /**< optional value of the extension's argument */
Radek Krejci335332a2019-09-05 13:03:35 +0200503 void *parent; /**< pointer to the parent element holding the extension instance(s), use
504 ::lysp_ext_instance#parent_type to access the schema element */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200505 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200506 struct lysc_ext_instance *compiled; /**< pointer to the compiled data if any - in case the source format is YIN,
507 some of the information (argument) are available only after compilation */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200508 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200509 LY_ARRAY_COUNT_TYPE insubstmt_index; /**< in case the instance is in a substatement, this identifies
David Sedlákbbd06ca2019-06-27 14:15:38 +0200510 the index of that substatement */
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100511 uint16_t flags; /**< LYS_INTERNAL value (@ref snodeflags) */
512 uint8_t yin; /**< flag for YIN source format, can be set to LYS_YIN */
Radek Krejci335332a2019-09-05 13:03:35 +0200513 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200514};
515
516/**
517 * @brief YANG feature-stmt
518 */
519struct lysp_feature {
520 const char *name; /**< feature name (mandatory) */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100521 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
522 struct lysc_iffeature *iffeatures_c; /**< compiled if-features */
523 struct lysp_feature **depfeatures; /**< list of pointers to other features depending on this one
524 ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200525 const char *dsc; /**< description statement */
526 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200527 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100528 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values and
529 LYS_FENABLED are allowed */
530};
531
532/**
533 * @brief Compiled YANG if-feature-stmt
534 */
535struct lysc_iffeature {
536 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
537 struct lysp_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200538};
539
540/**
Michal Vasko7f45cf22020-10-01 12:49:44 +0200541 * @brief Qualified name (optional prefix followed by an identifier).
542 */
543struct lysp_qname {
544 const char *str; /**< qualified name string */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200545 const struct lysp_module *mod; /**< module to resolve any prefixes found in the string, it must be
Michal Vasko7f45cf22020-10-01 12:49:44 +0200546 stored explicitly because of deviations/refines */
547};
548
549/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200550 * @brief YANG identity-stmt
551 */
552struct lysp_ident {
553 const char *name; /**< identity name (mandatory), including possible prefix */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200554 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200555 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200556 const char *dsc; /**< description statement */
557 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200558 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200559 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
560};
561
Michal Vasko71e64ca2018-09-07 16:30:29 +0200562/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200563 * @brief Covers restrictions: range, length, pattern, must
564 */
565struct lysp_restr {
Radek Krejcif13b87b2020-12-01 22:02:17 +0100566#define LYSP_RESTR_PATTERN_ACK 0x06
567#define LYSP_RESTR_PATTERN_NACK 0x15
Michal Vasko7f45cf22020-10-01 12:49:44 +0200568 struct lysp_qname arg; /**< The restriction expression/value (mandatory);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200569 in case of pattern restriction, the first byte has a special meaning:
570 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
571 const char *emsg; /**< error-message */
572 const char *eapptag; /**< error-app-tag value */
573 const char *dsc; /**< description */
574 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200575 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200576};
577
578/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200579 * @brief YANG revision-stmt
580 */
581struct lysp_revision {
Radek Krejcicb3e6472021-01-06 08:19:01 +0100582 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200583 const char *dsc; /**< description statement */
584 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200585 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200586};
587
588/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200589 * @brief Enumeration/Bit value definition
590 */
591struct lysp_type_enum {
592 const char *name; /**< name (mandatory) */
593 const char *dsc; /**< description statement */
594 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200595 int64_t value; /**< enum's value or bit's position */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200596 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200597 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200598 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
599 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200600};
601
602/**
603 * @brief YANG type-stmt
604 *
605 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
606 */
607struct lysp_type {
608 const char *name; /**< name of the type (mandatory) */
609 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
610 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200611 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
612 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
613 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Michal Vasko004d3152020-06-11 19:59:22 +0200614 struct lyxp_expr *path; /**< parsed path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200615 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200616 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
617 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200618
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200619 const struct lysp_module *pmod; /**< (sub)module where the type is defined (needed for deviations) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100620 struct lysc_type *compiled; /**< pointer to the compiled type */
621
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200622 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
623 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100624 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200625};
626
627/**
628 * @brief YANG typedef-stmt
629 */
630struct lysp_tpdf {
631 const char *name; /**< name of the newly defined type (mandatory) */
632 const char *units; /**< units of the newly defined type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200633 struct lysp_qname dflt; /**< default value of the newly defined type, it may or may not be a qualified name */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200634 const char *dsc; /**< description statement */
635 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200636 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200637 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100638 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200639};
640
641/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200642 * @brief YANG when-stmt
643 */
644struct lysp_when {
645 const char *cond; /**< specified condition (mandatory) */
646 const char *dsc; /**< description statement */
647 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200648 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200649};
650
651/**
652 * @brief YANG refine-stmt
653 */
654struct lysp_refine {
655 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
656 const char *dsc; /**< description statement */
657 const char *ref; /**< reference statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200658 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200659 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200660 const char *presence; /**< presence description */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200661 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200662 uint32_t min; /**< min-elements constraint */
663 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200664 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200665 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
666};
667
668/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200669 * @ingroup schematree
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200670 * @defgroup deviatetypes Deviate types
Radek Krejci8678fa42020-08-18 16:07:28 +0200671 *
672 * Type of the deviate operation (used as ::lysp_deviate.mod)
673 *
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200674 * @{
675 */
676#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
677#define LYS_DEV_ADD 2 /**< deviate type add */
678#define LYS_DEV_DELETE 3 /**< deviate type delete */
679#define LYS_DEV_REPLACE 4 /**< deviate type replace */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200680/** @} deviatetypes */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200681
682/**
683 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
684 */
685struct lysp_deviate {
686 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
687 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200688 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200689};
690
691struct lysp_deviate_add {
692 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
693 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200694 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200695 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200696 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200697 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
698 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200699 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
700 uint32_t min; /**< min-elements constraint */
701 uint32_t max; /**< max-elements constraint, 0 means unbounded */
702};
703
704struct lysp_deviate_del {
705 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
706 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200707 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200708 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200709 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200710 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
711 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200712};
713
714struct lysp_deviate_rpl {
715 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
716 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200717 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200718 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200719 const char *units; /**< units of the values */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200720 struct lysp_qname dflt; /**< default value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200721 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
722 uint32_t min; /**< min-elements constraint */
723 uint32_t max; /**< max-elements constraint, 0 means unbounded */
724};
725
726struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200727 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200728 const char *dsc; /**< description statement */
729 const char *ref; /**< reference statement */
Michal Vasko22df3f02020-08-24 13:29:22 +0200730 struct lysp_deviate *deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200731 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200732};
733
Radek Krejci4f28eda2018-11-12 11:46:16 +0100734/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100735 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200736 * @defgroup spnodeflags Parsed schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100737 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200738 * Various flags for parsed schema nodes (used as ::lysp_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100739 *
740 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
741 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200742 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100743 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
744 * 5 - list 10 - input 15 - typedef 20 - deviate
745 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200746 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
747 * 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
748 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200749 * 1 LYS_CONFIG_W |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200750 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
751 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200752 * 2 LYS_CONFIG_R |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200753 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
754 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
755 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
756 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
757 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
758 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
759 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
760 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
761 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
762 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
763 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
764 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
765 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100766 * LYS_FENABLED | | | | | | | | | | | |x| | | | | | | | | | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200767 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
768 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
769 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
770 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
771 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
772 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
773 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
774 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
775 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
776 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
777 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
778 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
779 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
780 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
781 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
782 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
783 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
784 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
785 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200786 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
David Sedlákae4b4512019-08-14 10:45:56 +0200787 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x|
Michal Vasko5297a432020-08-31 12:27:51 +0200788 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
789 * 12 LYS_YIN_ARGUMENT | | | | | | | | | | | | | | | | | | | | | | |x|
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100790 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
791 * 13 LYS_INTERNAL |x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|
Radek Krejcif56e2a42019-09-09 14:15:25 +0200792 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100793 *
794 */
795
796/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100797 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200798 * @defgroup scnodeflags Compiled schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100799 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200800 * Various flags for compiled schema nodes (used as ::lysc_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100801 *
Radek Krejci61e042e2019-09-10 15:53:09 +0200802 * 1 - container 6 - anydata/anyxml 11 - identity
803 * 2 - choice 7 - case 12 - extension
804 * 3 - leaf 8 - notification 13 - bitenum
Michal Vasko03ff5a72019-09-11 13:49:33 +0200805 * 4 - leaflist 9 - rpc/action 14 - when
Michal Vaskoecd62de2019-11-13 12:35:11 +0100806 * 5 - list 10 - feature
Radek Krejci4f28eda2018-11-12 11:46:16 +0100807 *
Michal Vaskoecd62de2019-11-13 12:35:11 +0100808 * 1 1 1 1 1
809 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
810 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskod09b7622021-01-26 09:14:13 +0100811 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100812 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskod09b7622021-01-26 09:14:13 +0100813 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100814 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
815 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x|x|x|x| |x|
816 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
817 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x|x|x|x| |x|
818 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
819 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x|x|x|x| |x|
820 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
821 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
822 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
823 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
824 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | |
825 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
826 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
827 * LYS_PRESENCE |x| | | | | | | | | | | | | |
828 * LYS_UNIQUE | | |x| | | | | | | | | | | |
829 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
830 * 9 LYS_KEY | | |x| | | | | | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100831 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
832 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
833 * LYS_ISENUM | | | | | | | | | | | | |x| |
834 * LYS_KEYLESS | | | | |x| | | | | | | | | |
835 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
836 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
837 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
838 * 12 LYS_SET_CONFIG |x|x|x|x|x|x| | | | | | | | |
839 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100840 *
841 */
842
843/**
844 * @defgroup snodeflags Schema nodes flags
Radek Krejci8678fa42020-08-18 16:07:28 +0200845 *
846 * Various flags for schema nodes ([parsed](@ref spnodeflags) as well as [compiled](@ref scnodeflags)).
847 *
Radek Krejci4f28eda2018-11-12 11:46:16 +0100848 * @{
849 */
Michal Vasko1bf09392020-03-27 12:38:10 +0100850#define LYS_CONFIG_W 0x01 /**< config true; also set for input children nodes */
851#define LYS_CONFIG_R 0x02 /**< config false; also set for output and notification children nodes */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200852#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100853#define LYS_STATUS_CURR 0x04 /**< status current; */
854#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
855#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
856#define LYS_STATUS_MASK 0x1C /**< mask for status value */
857#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100858 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
859 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
860 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
861 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100862#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
863 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
864 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100865#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Michal Vaskoc118ae22020-08-06 14:51:09 +0200866#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, but it is not only for explicit presence
867 containers, but also for NP containers with some meaning, applicable only to
868 ::lysc_node_container */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100869#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
870#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 +0200871#define LYS_KEYLESS 0x200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100872#define LYS_FENABLED 0x20 /**< feature enabled flag, applicable only to ::lysp_feature. */
Radek Krejcife909632019-02-12 15:34:42 +0100873#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 +0100874 ::lysc_node_list/::lysp_node_list */
875#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
876 ::lysc_node_list/::lysp_node_list */
877#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
878#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
879#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
880#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200881#define LYS_USED_GRP 0x400 /**< internal flag for validating not-instantiated groupings
882 (resp. do not validate again the instantiated groupings). */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100883#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100884#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200885#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100886
887#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
888#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
889#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
890#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
891#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
892#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
893#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
894#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
895#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
896#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100897#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 +0100898 cases of choice. This information is important for refines, since it is prohibited to make leafs
899 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100900 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
901 between own default or the default values taken from the type. */
902#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 +0100903#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 +0100904
Radek Krejcif56e2a42019-09-09 14:15:25 +0200905#define LYS_SINGLEQUOTED 0x100 /**< flag for single-quoted argument of an extension instance's substatement, only when the source is YANG */
906#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 +0200907
Radek Krejcif56e2a42019-09-09 14:15:25 +0200908#define LYS_YIN_ATTR 0x400 /**< flag to identify YIN attribute parsed as extension's substatement, only when the source is YIN */
909#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 +0200910
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100911#define LYS_INTERNAL 0x1000 /**< flag to identify internal parsed statements that should not be printed */
912
Radek Krejci693262f2019-04-29 15:23:20 +0200913#define LYS_ISENUM 0x200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
914
Radek Krejcife909632019-02-12 15:34:42 +0100915#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200916/** @} snodeflags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200917
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200918/**
919 * @brief Generic YANG data node
920 */
921struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100922 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200923 uint16_t nodetype; /**< type of the node (mandatory) */
924 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100925 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200926 const char *name; /**< node name (mandatory) */
927 const char *dsc; /**< description statement */
928 const char *ref; /**< reference statement */
929 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200930 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)),
931 must be qname because of refines */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200932 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200933};
934
935/**
936 * @brief Extension structure of the lysp_node for YANG container
937 */
938struct lysp_node_container {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100939 union {
940 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
941 struct {
942 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
943 uint16_t nodetype; /**< LYS_CONTAINER */
944 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
945 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
946 const char *name; /**< node name (mandatory) */
947 const char *dsc; /**< description statement */
948 const char *ref; /**< reference statement */
949 struct lysp_when *when; /**< when statement */
950 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
951 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
952 };
953 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200954
955 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200956 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200957 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200958 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100959 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200960 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100961 struct lysp_node_action *actions;/**< list of actions (linked list) */
962 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200963};
964
965struct lysp_node_leaf {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100966 union {
967 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
968 struct {
969 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
970 uint16_t nodetype; /**< LYS_LEAF */
971 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
972 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
973 const char *name; /**< node name (mandatory) */
974 const char *dsc; /**< description statement */
975 const char *ref; /**< reference statement */
976 struct lysp_when *when; /**< when statement */
977 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
978 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
979 };
980 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200981
982 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200983 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200984 struct lysp_type type; /**< type of the leaf node (mandatory) */
985 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200986 struct lysp_qname dflt; /**< default value, it may or may not be a qualified name */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200987};
988
989struct lysp_node_leaflist {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100990 union {
991 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
992 struct {
993 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
994 uint16_t nodetype; /**< LYS_LEAFLIST */
995 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
996 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
997 const char *name; /**< node name (mandatory) */
998 const char *dsc; /**< description statement */
999 const char *ref; /**< reference statement */
1000 struct lysp_when *when; /**< when statement */
1001 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1002 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1003 };
1004 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001005
1006 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001007 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001008 struct lysp_type type; /**< type of the leaf node (mandatory) */
1009 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001010 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)), they may or
1011 may not be qualified names */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001012 uint32_t min; /**< min-elements constraint */
1013 uint32_t max; /**< max-elements constraint, 0 means unbounded */
1014};
1015
1016struct lysp_node_list {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001017 union {
1018 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1019 struct {
1020 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1021 uint16_t nodetype; /**< LYS_LIST */
1022 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1023 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1024 const char *name; /**< node name (mandatory) */
1025 const char *dsc; /**< description statement */
1026 const char *ref; /**< reference statement */
1027 struct lysp_when *when; /**< when statement */
1028 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1029 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1030 };
1031 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001032
1033 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001034 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001035 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001036 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001037 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001038 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001039 struct lysp_node_action *actions;/**< list of actions (linked list) */
1040 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001041 struct lysp_qname *uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001042 uint32_t min; /**< min-elements constraint */
1043 uint32_t max; /**< max-elements constraint, 0 means unbounded */
1044};
1045
1046struct lysp_node_choice {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001047 union {
1048 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1049 struct {
1050 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1051 uint16_t nodetype; /**< LYS_CHOICE */
1052 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1053 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1054 const char *name; /**< node name (mandatory) */
1055 const char *dsc; /**< description statement */
1056 const char *ref; /**< reference statement */
1057 struct lysp_when *when; /**< when statement */
1058 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1059 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1060 };
1061 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001062
1063 /* choice */
1064 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001065 struct lysp_qname dflt; /**< default case */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001066};
1067
1068struct lysp_node_case {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001069 union {
1070 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1071 struct {
1072 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1073 uint16_t nodetype; /**< LYS_CASE */
1074 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1075 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1076 const char *name; /**< node name (mandatory) */
1077 const char *dsc; /**< description statement */
1078 const char *ref; /**< reference statement */
1079 struct lysp_when *when; /**< when statement */
1080 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1081 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1082 };
1083 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001084
1085 /* case */
1086 struct lysp_node *child; /**< list of data nodes (linked list) */
1087};
1088
1089struct lysp_node_anydata {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001090 union {
1091 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1092 struct {
1093 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1094 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1095 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1096 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1097 const char *name; /**< node name (mandatory) */
1098 const char *dsc; /**< description statement */
1099 const char *ref; /**< reference statement */
1100 struct lysp_when *when; /**< when statement */
1101 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1102 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1103 };
1104 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001105
1106 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001107 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001108};
1109
1110struct lysp_node_uses {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001111 union {
1112 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1113 struct {
1114 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1115 uint16_t nodetype; /**< LYS_USES */
1116 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1117 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1118 const char *name; /**< grouping name reference (mandatory) */
1119 const char *dsc; /**< description statement */
1120 const char *ref; /**< reference statement */
1121 struct lysp_when *when; /**< when statement */
1122 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1123 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1124 };
1125 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001126
1127 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001128 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001129 struct lysp_node_augment *augments; /**< list of augments (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001130};
1131
1132/**
1133 * @brief YANG input-stmt and output-stmt
1134 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001135struct lysp_node_action_inout {
1136 union {
1137 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1138 struct {
1139 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1140 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
1141 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1142 struct lysp_node *next; /**< NULL */
1143 const char *name; /**< empty string */
1144 const char *dsc; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1145 const char *ref; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1146 struct lysp_when *when; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1147 struct lysp_qname *iffeatures; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1148 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1149 };
1150 }; /**< common part corresponding to ::lysp_node */
1151
1152 /* inout */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001153 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1154 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001155 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001156 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001157};
1158
1159/**
1160 * @brief YANG rpc-stmt and action-stmt
1161 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001162struct lysp_node_action {
1163 union {
1164 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1165 struct {
1166 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1167 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
1168 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1169 struct lysp_node_action *next; /**< pointer to the next action (NULL if there is no one) */
1170 const char *name; /**< grouping name reference (mandatory) */
1171 const char *dsc; /**< description statement */
1172 const char *ref; /**< reference statement */
1173 struct lysp_when *when; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1174 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1175 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1176 };
1177 }; /**< common part corresponding to ::lysp_node */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001178
1179 /* action */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001180 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1181 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
1182
1183 struct lysp_node_action_inout input; /**< RPC's/Action's input */
1184 struct lysp_node_action_inout output; /**< RPC's/Action's output */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001185};
1186
1187/**
1188 * @brief YANG notification-stmt
1189 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001190struct lysp_node_notif {
1191 union {
1192 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1193 struct {
1194 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1195 uint16_t nodetype; /**< LYS_NOTIF */
1196 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1197 struct lysp_node_notif *next; /**< pointer to the next notification (NULL if there is no one) */
1198 const char *name; /**< grouping name reference (mandatory) */
1199 const char *dsc; /**< description statement */
1200 const char *ref; /**< reference statement */
1201 struct lysp_when *when; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1202 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1203 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1204 };
1205 }; /**< common part corresponding to ::lysp_node */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001206
1207 /* notif */
1208 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001209 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1210 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001211 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001212};
1213
1214/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001215 * @brief YANG grouping-stmt
1216 */
1217struct lysp_node_grp {
1218 union {
1219 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1220 struct {
1221 struct lysp_node *parent;/**< parent node (NULL if this is a top-level grouping) */
1222 uint16_t nodetype; /**< LYS_GROUPING */
1223 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1224 struct lysp_node_grp *next; /**< pointer to the next grouping (NULL if there is no one) */
1225 const char *name; /**< grouping name (mandatory) */
1226 const char *dsc; /**< description statement */
1227 const char *ref; /**< reference statement */
1228 struct lysp_when *when; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1229 struct lysp_qname *iffeatures; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1230 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1231 };
1232 }; /**< common part corresponding to ::lysp_node */
1233
1234 /* grp */
1235 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1236 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
1237 struct lysp_node *data; /**< list of data nodes (linked list) */
1238 struct lysp_node_action *actions; /**< list of actions (linked list) */
1239 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
1240};
1241
1242/**
1243 * @brief YANG uses-augment-stmt and augment-stmt (compatible with struct lysp_node )
1244 */
1245struct lysp_node_augment {
1246 union {
1247 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1248 struct {
1249 struct lysp_node *parent;/**< parent node (NULL if this is a top-level augment) */
1250 uint16_t nodetype; /**< LYS_AUGMENT */
1251 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1252 struct lysp_node_augment *next; /**< pointer to the next augment (NULL if there is no one) */
1253 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
1254 const char *dsc; /**< description statement */
1255 const char *ref; /**< reference statement */
1256 struct lysp_when *when; /**< when statement */
1257 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1258 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1259 };
1260 }; /**< common part corresponding to ::lysp_node */
1261
1262 struct lysp_node *child; /**< list of data nodes (linked list) */
1263 struct lysp_node_action *actions;/**< list of actions (linked list) */
1264 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
1265};
1266
1267/**
Radek Krejcif0fceb62018-09-05 14:58:45 +02001268 * @brief supported YANG schema version values
1269 */
1270typedef enum LYS_VERSION {
1271 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
Radek Krejci96e48da2020-09-04 13:18:06 +02001272 LYS_VERSION_1_0 = 1, /**< YANG 1 (1.0) */
Radek Krejcif0fceb62018-09-05 14:58:45 +02001273 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
1274} LYS_VERSION;
1275
1276/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001277 * @brief Printable YANG schema tree structure representing YANG module.
1278 *
1279 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
1280 */
1281struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001282 struct lys_module *mod; /**< covering module structure */
1283
Radek Krejcib7db73a2018-10-24 14:18:40 +02001284 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1285 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001286 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1287 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001288 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1289 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1290 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1291 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001292 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001293 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001294 struct lysp_node_augment *augments; /**< list of augments (linked list) */
1295 struct lysp_node_action *rpcs; /**< list of RPCs (linked list) */
1296 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001297 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001298 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001299
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001300 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001301 uint8_t parsing : 1; /**< flag for circular check */
1302 uint8_t is_submod : 1; /**< always 0 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001303};
1304
1305struct lysp_submodule {
Michal Vaskoc3781c32020-10-06 14:04:08 +02001306 struct lys_module *mod; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001307
1308 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1309 in the list is always the last (newest) revision of the module */
1310 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1311 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
1312 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1313 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1314 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1315 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001316 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001317 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001318 struct lysp_node_augment *augments; /**< list of augments (linked list) */
1319 struct lysp_node_action *rpcs; /**< list of RPCs (linked list) */
1320 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001321 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001322 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001323
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001324 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001325 uint8_t parsing : 1; /**< flag for circular check */
1326 uint8_t is_submod : 1; /**< always 1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001327
Michal Vaskoc3781c32020-10-06 14:04:08 +02001328 uint8_t latest_revision : 2; /**< flag to mark the latest available revision:
Radek Krejci086c7132018-10-26 15:29:04 +02001329 1 - the latest revision in searchdirs was not searched yet and this is the
1330 latest revision in the current context
1331 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001332 const char *name; /**< name of the module (mandatory) */
1333 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1334 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
1335 const char *org; /**< party/company responsible for the module */
1336 const char *contact; /**< contact information for the module */
1337 const char *dsc; /**< description of the module */
1338 const char *ref; /**< cross-reference for the module */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001339};
1340
1341/**
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001342 * @brief Get the parsed module or submodule name.
1343 *
1344 * @param[in] PMOD Parsed module or submodule.
1345 * @return Module or submodule name.
1346 */
1347#define LYSP_MODULE_NAME(PMOD) (PMOD->is_submod ? ((struct lysp_submodule *)PMOD)->name : ((struct lysp_module *)PMOD)->mod->name)
1348
1349/**
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001350 * @brief Compiled prefix data pair mapping of prefixes to modules. In case the format is ::LY_PREF_SCHEMA_RESOLVED,
1351 * the expected prefix data is a sized array of these structures.
1352 */
1353struct lysc_prefix {
1354 char *prefix; /**< used prefix */
1355 const struct lys_module *mod; /**< mapping to a module */
1356};
1357
1358/**
Radek Krejci0e59c312019-08-15 15:34:15 +02001359 * @brief Compiled YANG extension-stmt
1360 */
1361struct lysc_ext {
1362 const char *name; /**< extension name */
1363 const char *argument; /**< argument name, NULL if not specified */
Radek Krejci0e59c312019-08-15 15:34:15 +02001364 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1365 struct lyext_plugin *plugin; /**< Plugin implementing the specific extension */
Radek Krejci0935f412019-08-20 16:15:18 +02001366 struct lys_module *module; /**< module structure */
Michal Vasko6f4cbb62020-02-28 11:15:47 +01001367 uint32_t refcount; /**< reference counter since extension definition is shared among all its instances */
Radek Krejci0e59c312019-08-15 15:34:15 +02001368 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
1369};
1370
1371/**
Radek Krejcice8c1592018-10-29 15:35:51 +01001372 * @brief YANG extension instance
1373 */
1374struct lysc_ext_instance {
Radek Krejciad5963b2019-09-06 16:03:05 +02001375 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
1376 this identifies the index of the substatement for this extension instance */
Radek Krejci28681fa2019-09-06 13:08:45 +02001377 struct lys_module *module; /**< module where the extension instantiated is defined */
Radek Krejciad5963b2019-09-06 16:03:05 +02001378 struct lysc_ext *def; /**< pointer to the extension definition */
Radek Krejcice8c1592018-10-29 15:35:51 +01001379 void *parent; /**< pointer to the parent element holding the extension instance(s), use
1380 ::lysc_ext_instance#parent_type to access the schema element */
1381 const char *argument; /**< optional value of the extension's argument */
1382 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +01001383 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001384 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0e59c312019-08-15 15:34:15 +02001385 void *data; /**< private plugins's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +01001386};
1387
1388/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001389 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001390 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001391struct lysc_when {
1392 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko175012e2019-11-06 15:49:14 +01001393 struct lysc_node *context; /**< context node for evaluating the expression, NULL if the context is root node */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001394 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001395 const char *dsc; /**< description */
1396 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001397 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001398 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Michal Vaskoecd62de2019-11-13 12:35:11 +01001399 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS is allowed */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001400};
1401
1402/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001403 * @brief YANG identity-stmt
1404 */
1405struct lysc_ident {
1406 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +01001407 const char *dsc; /**< description */
1408 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001409 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001410 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
1411 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1412 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1413};
1414
1415/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001416 * @defgroup ifftokens if-feature expression tokens
Radek Krejci8678fa42020-08-18 16:07:28 +02001417 * Tokens of if-feature expression used in ::lysc_iffeature.expr.
Radek Krejci151a5b72018-10-19 14:21:44 +02001418 *
1419 * @{
1420 */
1421#define LYS_IFF_NOT 0x00 /**< operand "not" */
1422#define LYS_IFF_AND 0x01 /**< operand "and" */
1423#define LYS_IFF_OR 0x02 /**< operand "or" */
1424#define LYS_IFF_F 0x03 /**< feature */
Radek Krejci2ff0d572020-05-21 15:27:28 +02001425/** @} ifftokens */
Radek Krejci151a5b72018-10-19 14:21:44 +02001426
1427/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001428 * @brief Compiled YANG revision statement
1429 */
1430struct lysc_revision {
1431 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1432 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1433};
1434
Radek Krejci2167ee12018-11-02 16:09:07 +01001435struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001436 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001437 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001438 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1439 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001440 };
Radek Krejci693262f2019-04-29 15:23:20 +02001441 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001442 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1443 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001444 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001445 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001446 const char *dsc; /**< description */
1447 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001448 const char *emsg; /**< error-message */
1449 const char *eapptag; /**< error-app-tag value */
1450 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1451};
1452
1453struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001454 const char *expr; /**< original, not compiled, regular expression */
1455 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001456 const char *dsc; /**< description */
1457 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001458 const char *emsg; /**< error-message */
1459 const char *eapptag; /**< error-app-tag value */
1460 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0f969882020-08-21 16:56:47 +02001461 uint32_t inverted : 1; /**< invert-match flag */
1462 uint32_t refcount : 31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001463};
1464
1465struct lysc_must {
Radek Krejci2167ee12018-11-02 16:09:07 +01001466 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001467 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001468 const char *dsc; /**< description */
1469 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001470 const char *emsg; /**< error-message */
1471 const char *eapptag; /**< error-app-tag value */
1472 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1473};
1474
1475struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001476 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001477 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 +01001478 LY_DATA_TYPE basetype; /**< Base type of the type */
1479 uint32_t refcount; /**< reference counter for type sharing */
1480};
1481
1482struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001483 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001484 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 +01001485 LY_DATA_TYPE basetype; /**< Base type of the type */
1486 uint32_t refcount; /**< reference counter for type sharing */
1487 struct lysc_range *range; /**< Optional range limitation */
1488};
1489
1490struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001491 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001492 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 +01001493 LY_DATA_TYPE basetype; /**< Base type of the type */
1494 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001495 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001496 struct lysc_range *range; /**< Optional range limitation */
1497};
1498
1499struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001500 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001501 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 +01001502 LY_DATA_TYPE basetype; /**< Base type of the type */
1503 uint32_t refcount; /**< reference counter for type sharing */
1504 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001505 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001506};
1507
Radek Krejci693262f2019-04-29 15:23:20 +02001508struct lysc_type_bitenum_item {
1509 const char *name; /**< enumeration identifier */
1510 const char *dsc; /**< description */
1511 const char *ref; /**< reference */
1512 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci693262f2019-04-29 15:23:20 +02001513 union {
1514 int32_t value; /**< integer value associated with the enumeration */
1515 uint32_t position; /**< non-negative integer value associated with the bit */
1516 };
1517 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1518 values are allowed */
1519};
1520
Radek Krejci2167ee12018-11-02 16:09:07 +01001521struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001522 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001523 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 +01001524 LY_DATA_TYPE basetype; /**< Base type of the type */
1525 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001526 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1527};
1528
1529struct lysc_type_bits {
1530 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001531 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 +02001532 LY_DATA_TYPE basetype; /**< Base type of the type */
1533 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001534 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1535 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001536};
1537
1538struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001539 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001540 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 +01001541 LY_DATA_TYPE basetype; /**< Base type of the type */
1542 uint32_t refcount; /**< reference counter for type sharing */
Michal Vasko004d3152020-06-11 19:59:22 +02001543 struct lyxp_expr *path; /**< parsed target path, compiled path cannot be stored because of type sharing */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001544 struct lysc_prefix *prefixes; /**< resolved prefixes used in the path */
Michal Vaskoc0792ca2020-12-01 12:03:21 +01001545 const struct lys_module *cur_mod;/**< current module for the leafref (path) */
Radek Krejci412ddfa2018-11-23 11:44:11 +01001546 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001547 uint8_t require_instance; /**< require-instance flag */
1548};
1549
1550struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001551 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001552 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 +01001553 LY_DATA_TYPE basetype; /**< Base type of the type */
1554 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001555 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001556 mandatory (at least 1 item) */
1557};
1558
1559struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001560 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001561 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 +01001562 LY_DATA_TYPE basetype; /**< Base type of the type */
1563 uint32_t refcount; /**< reference counter for type sharing */
1564 uint8_t require_instance; /**< require-instance flag */
1565};
1566
Radek Krejci2167ee12018-11-02 16:09:07 +01001567struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001568 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001569 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 +01001570 LY_DATA_TYPE basetype; /**< Base type of the type */
1571 uint32_t refcount; /**< reference counter for type sharing */
1572 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1573};
1574
1575struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001576 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001577 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 +01001578 LY_DATA_TYPE basetype; /**< Base type of the type */
1579 uint32_t refcount; /**< reference counter for type sharing */
1580 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001581};
1582
Michal Vasko60ea6352020-06-29 13:39:39 +02001583/**
1584 * @brief Maximum number of hashes stored in a schema node.
1585 */
1586#define LYS_NODE_HASH_COUNT 4
1587
Radek Krejci2a9fc652021-01-22 17:44:34 +01001588struct lysc_node_action_inout {
1589 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
Radek Krejci056d0a82018-12-06 16:57:25 +01001590 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001591 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejci95710c92019-02-11 15:49:55 +01001592 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001593 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001594 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1595 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1596 never NULL. If there is no sibling node, pointer points to the node
1597 itself. In case of the first node, this pointer points to the last
1598 node in the list. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001599 const char *name; /**< Notification name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001600 const char *dsc; /**< description */
1601 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001602 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskoceab6dd2020-10-09 16:53:36 +02001603 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001604 void *priv; /** private arbitrary user data, not used by libyang */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001605
1606 struct lysc_node *data; /**< first child node (linked list) */
1607 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1608};
1609
1610struct lysc_node_action {
1611 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
1612 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1613 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1614 struct lys_module *module; /**< module structure */
1615 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1616 struct lysc_node_action *next; /**< next sibling node (NULL if there is no one) */
1617 struct lysc_node_action *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1618 never NULL. If there is no sibling node, pointer points to the node
1619 itself. In case of the first node, this pointer points to the last
1620 node in the list. */
1621 const char *name; /**< action/RPC name (mandatory) */
1622 const char *dsc; /**< description */
1623 const char *ref; /**< reference */
1624 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1625 struct lysc_when **when; /**< ALWAYS NULL, compatibility member with ::lysc_node */
1626 void *priv; /** private arbitrary user data, not used by libyang */
1627
1628 struct lysc_node_action_inout input; /**< RPC's/action's input */
1629 struct lysc_node_action_inout output; /**< RPC's/action's output */
1630
1631};
1632
1633struct lysc_node_notif {
1634 uint16_t nodetype; /**< LYS_NOTIF */
1635 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1636 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1637 struct lys_module *module; /**< module structure */
1638 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1639 struct lysc_node_notif *next; /**< next sibling node (NULL if there is no one) */
1640 struct lysc_node_notif *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1641 never NULL. If there is no sibling node, pointer points to the node
1642 itself. In case of the first node, this pointer points to the last
1643 node in the list. */
1644 const char *name; /**< Notification name (mandatory) */
1645 const char *dsc; /**< description */
1646 const char *ref; /**< reference */
1647 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1648 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
1649 void *priv; /** private arbitrary user data, not used by libyang */
1650
1651 struct lysc_node *data; /**< first child node (linked list) */
1652 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001653};
1654
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001655/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001656 * @brief Compiled YANG data node
1657 */
1658struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001659 uint16_t nodetype; /**< type of the node (mandatory) */
1660 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001661 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001662 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001663 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1664 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1665 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1666 never NULL. If there is no sibling node, pointer points to the node
1667 itself. In case of the first node, this pointer points to the last
1668 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001669 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001670 const char *dsc; /**< description */
1671 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001672 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001673 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001674 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001675};
1676
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001677struct lysc_node_container {
1678 uint16_t nodetype; /**< LYS_CONTAINER */
1679 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001680 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001681 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001682 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1683 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1684 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1685 never NULL. If there is no sibling node, pointer points to the node
1686 itself. In case of the first node, this pointer points to the last
1687 node in the list. */
1688 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001689 const char *dsc; /**< description */
1690 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001691 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001692 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001693 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001694
1695 struct lysc_node *child; /**< first child node (linked list) */
1696 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001697 struct lysc_node_action *actions;/**< first of actions nodes (linked list) */
1698 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001699};
1700
Radek Krejcia3045382018-11-22 14:30:31 +01001701struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001702 uint16_t nodetype; /**< LYS_CASE */
1703 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001704 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
Radek Krejci056d0a82018-12-06 16:57:25 +01001705 struct lys_module *module; /**< module structure */
Radek Krejci056d0a82018-12-06 16:57:25 +01001706 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1707 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1708 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1709 never NULL. If there is no sibling node, pointer points to the node
1710 itself. In case of the first node, this pointer points to the last
1711 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001712 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001713 const char *dsc; /**< description */
1714 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001715 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001716 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001717 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci056d0a82018-12-06 16:57:25 +01001718
Radek Krejcia3045382018-11-22 14:30:31 +01001719 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 +01001720 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001721};
1722
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001723struct lysc_node_choice {
1724 uint16_t nodetype; /**< LYS_CHOICE */
1725 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001726 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001727 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001728 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1729 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1730 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1731 never NULL. If there is no sibling node, pointer points to the node
1732 itself. In case of the first node, this pointer points to the last
1733 node in the list. */
1734 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001735 const char *dsc; /**< description */
1736 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001737 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001738 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001739 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001740
Radek Krejcia9026eb2018-12-12 16:04:47 +01001741 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1742 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1743 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001744 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001745};
1746
1747struct lysc_node_leaf {
1748 uint16_t nodetype; /**< LYS_LEAF */
1749 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001750 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001751 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001752 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1753 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1754 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1755 never NULL. If there is no sibling node, pointer points to the node
1756 itself. In case of the first node, this pointer points to the last
1757 node in the list. */
1758 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001759 const char *dsc; /**< description */
1760 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001761 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001762 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001763 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001764
1765 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1766 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001767
Radek Krejci4f28eda2018-11-12 11:46:16 +01001768 const char *units; /**< units of the leaf's type */
Radek Krejcia1911222019-07-22 17:24:50 +02001769 struct lyd_value *dflt; /**< default value */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001770};
1771
1772struct lysc_node_leaflist {
1773 uint16_t nodetype; /**< LYS_LEAFLIST */
1774 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001775 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001776 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001777 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1778 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1779 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1780 never NULL. If there is no sibling node, pointer points to the node
1781 itself. In case of the first node, this pointer points to the last
1782 node in the list. */
1783 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001784 const char *dsc; /**< description */
1785 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001786 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001787 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001788 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001789
1790 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1791 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1792
Radek Krejci0e5d8382018-11-28 16:37:53 +01001793 const char *units; /**< units of the leaf's type */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001794 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values */
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001795
Radek Krejci0e5d8382018-11-28 16:37:53 +01001796 uint32_t min; /**< min-elements constraint */
1797 uint32_t max; /**< max-elements constraint */
1798
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001799};
1800
1801struct lysc_node_list {
1802 uint16_t nodetype; /**< LYS_LIST */
1803 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001804 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001805 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001806 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1807 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1808 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1809 never NULL. If there is no sibling node, pointer points to the node
1810 itself. In case of the first node, this pointer points to the last
1811 node in the list. */
1812 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001813 const char *dsc; /**< description */
1814 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001815 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001816 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001817 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001818
1819 struct lysc_node *child; /**< first child node (linked list) */
1820 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001821 struct lysc_node_action *actions;/**< first of actions nodes (linked list) */
1822 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001823
Radek Krejci2a9fc652021-01-22 17:44:34 +01001824 struct lysc_node_leaf ***uniques;/**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001825 uint32_t min; /**< min-elements constraint */
1826 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001827};
1828
1829struct lysc_node_anydata {
1830 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1831 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001832 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001833 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001834 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1835 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1836 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1837 never NULL. If there is no sibling node, pointer points to the node
1838 itself. In case of the first node, this pointer points to the last
1839 node in the list. */
1840 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001841 const char *dsc; /**< description */
1842 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001843 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001844 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001845 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci9800fb82018-12-13 14:26:23 +01001846
1847 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001848};
1849
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001850/**
1851 * @brief Compiled YANG schema tree structure representing YANG module.
1852 *
1853 * Semantically validated YANG schema tree for data tree parsing.
1854 * Contains only the necessary information for the data validation.
1855 */
1856struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001857 struct lys_module *mod; /**< covering module structure */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001858
Radek Krejci2a408df2018-10-29 16:32:26 +01001859 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001860 struct lysc_node_action *rpcs; /**< first of actions nodes (linked list) */
1861 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001862 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001863};
1864
1865/**
Radek Krejci490a5462020-11-05 08:44:42 +01001866 * @brief Examine whether a node is user-ordered list or leaf-list.
1867 *
1868 * @param[in] lysc_node Schema node to examine.
1869 * @return Boolean value whether the @p node is user-ordered or not.
1870 */
1871#define lysc_is_userordered(lysc_node) \
1872 ((!lysc_node || !(lysc_node->nodetype & (LYS_LEAFLIST | LYS_LIST)) || !(lysc_node->flags & LYS_ORDBY_USER)) ? 0 : 1)
1873
1874/**
1875 * @brief Examine whether a node is a list's key.
1876 *
1877 * @param[in] lysc_node Schema node to examine.
1878 * @return Boolean value whether the @p node is a key or not.
1879 */
1880#define lysc_is_key(lysc_node) \
1881 ((!lysc_node || !(lysc_node->nodetype & (LYS_LEAF)) || !(lysc_node->flags & LYS_KEY)) ? 0 : 1)
1882
1883/**
Michal Vasko5c123b02020-12-04 14:34:04 +01001884 * @brief Examine whether a node is a non-presence container.
1885 *
1886 * @param[in] lysc_node Schema node to examine.
1887 * @return Boolean value whether the @p node is a NP container or not.
1888 */
1889#define lysc_is_np_cont(lysc_node) \
1890 ((!lysc_node || !(lysc_node->nodetype & (LYS_CONTAINER)) || (lysc_node->flags & LYS_PRESENCE)) ? 0 : 1)
1891
1892/**
Michal Vaskod5cfa6e2020-11-23 16:56:08 +01001893 * @brief Check whether the schema node data instance existence depends on any when conditions.
1894 * This node and any direct parent choice and case schema nodes are also examined for when conditions.
1895 *
1896 * Be careful, this function is not recursive and checks only conditions that apply to this node directly.
1897 * Meaning if there are any conditions associated with any data parent instance of @p node, they are not returned.
1898 *
1899 * @param[in] node Schema node to examine.
1900 * @return When condition associated with the node data instance, NULL if there is none.
1901 */
1902const struct lysc_when *lysc_has_when(const struct lysc_node *node);
1903
1904/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001905 * @brief Get the groupings linked list of the given (parsed) schema node.
Radek Krejci53ea6152018-12-13 15:21:15 +01001906 * Decides the node's type and in case it has a groupings array, returns it.
1907 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01001908 * @return The node's groupings linked list if any, NULL otherwise.
Radek Krejci53ea6152018-12-13 15:21:15 +01001909 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001910const struct lysp_node_grp *lysp_node_groupings(const struct lysp_node *node);
Radek Krejci53ea6152018-12-13 15:21:15 +01001911
1912/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001913 * @brief Get the typedefs sized array of the given (parsed) schema node.
1914 * Decides the node's type and in case it has a typedefs array, returns it.
1915 * @param[in] node Node to examine.
1916 * @return The node's typedefs sized array if any, NULL otherwise.
1917 */
1918const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1919
1920/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001921 * @brief Get the actions/RPCs linked list of the given (parsed) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01001922 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1923 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01001924 * @return The node's actions/RPCs linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01001925 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001926const struct lysp_node_action *lysp_node_actions(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01001927
1928/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001929 * @brief Get the Notifications linked list of the given (parsed) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01001930 * Decides the node's type and in case it has a Notifications array, returns it.
1931 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01001932 * @return The node's Notifications linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01001933 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001934const struct lysp_node_notif *lysp_node_notifs(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01001935
1936/**
1937 * @brief Get the children linked list of the given (parsed) schema node.
1938 * Decides the node's type and in case it has a children list, returns it.
1939 * @param[in] node Node to examine.
1940 * @return The node's children linked list if any, NULL otherwise.
1941 */
1942const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1943
1944/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001945 * @brief Get the actions/RPCs linked list of the given (compiled) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01001946 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1947 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01001948 * @return The node's actions/RPCs linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01001949 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001950const struct lysc_node_action *lysc_node_actions(const struct lysc_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01001951
1952/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001953 * @brief Get the Notifications linked list of the given (compiled) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01001954 * Decides the node's type and in case it has a Notifications array, returns it.
1955 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01001956 * @return The node's Notifications linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01001957 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001958const struct lysc_node_notif *lysc_node_notifs(const struct lysc_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01001959
1960/**
1961 * @brief Get the children linked list of the given (compiled) schema node.
Michal Vasko2a668712020-10-21 11:48:09 +02001962 *
1963 * @param[in] node Node to examine.
1964 * @param[in] flags Config flag to distinguish input (LYS_CONFIG_W) and output (LYS_CONFIG_R) child in case of RPC/action node.
1965 * @return Children linked list if any,
1966 * @return NULL otherwise.
1967 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001968const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Michal Vasko2a668712020-10-21 11:48:09 +02001969
1970/**
1971 * @brief Get the parent pointer from any type of (compiled) schema node.
Michal Vasko208a04a2020-10-21 15:17:12 +02001972 * Returns input or output for direct descendants of RPC/action nodes.
1973 * To skip them, use ::lysc_node.parent pointer directly.
Michal Vasko2a668712020-10-21 11:48:09 +02001974 *
1975 * @param[in] node Node whose parent to get.
1976 * @return Node parent.
1977 * @return NULL is there is none.
1978 */
Michal Vasko208a04a2020-10-21 15:17:12 +02001979const struct lysc_node *lysc_node_parent_full(const struct lysc_node *node);
Michal Vasko2a668712020-10-21 11:48:09 +02001980
1981/**
Michal Vaskof1ab44f2020-10-22 08:58:32 +02001982 * @brief Callback to be called for every schema node in a DFS traversal.
1983 *
1984 * @param[in] node Current node.
1985 * @param[in] data Arbitrary user data.
1986 * @param[out] dfs_continue Set to true if the current subtree should be skipped and continue with siblings instead.
1987 * @return LY_SUCCESS on success,
1988 * @return LY_ERR value to terminate DFS and return this value.
1989 */
1990typedef LY_ERR (*lysc_dfs_clb)(struct lysc_node *node, void *data, ly_bool *dfs_continue);
1991
1992/**
1993 * @brief DFS traversal of all the schema nodes in a (sub)tree including any actions and nested notifications.
1994 *
1995 * Node with children, actions, and notifications is traversed in this order:
1996 * 1) each child subtree;
1997 * 2) each action subtree;
1998 * 3) each notification subtree.
1999 *
2000 * For algorithm illustration or traversal with actions and notifications skipped, see ::LYSC_TREE_DFS_BEGIN.
2001 *
2002 * @param[in] root Schema root to fully traverse.
2003 * @param[in] dfs_clb Callback to call for each node.
2004 * @param[in] data Arbitrary user data passed to @p dfs_clb.
2005 * @return LY_SUCCESS on success,
2006 * @return LY_ERR value returned by @p dfs_clb.
2007 */
2008LY_ERR lysc_tree_dfs_full(const struct lysc_node *root, lysc_dfs_clb dfs_clb, void *data);
2009
2010/**
2011 * @brief DFS traversal of all the schema nodes in a module including RPCs and notifications.
2012 *
2013 * For more details, see ::lysc_tree_dfs_full().
2014 *
2015 * @param[in] mod Module to fully traverse.
2016 * @param[in] dfs_clb Callback to call for each node.
2017 * @param[in] data Arbitrary user data passed to @p dfs_clb.
2018 * @return LY_SUCCESS on success,
2019 * @return LY_ERR value returned by @p dfs_clb.
2020 */
2021LY_ERR lysc_module_dfs_full(const struct lys_module *mod, lysc_dfs_clb dfs_clb, void *data);
2022
2023/**
Michal Vasko2fd91b92020-07-17 16:39:02 +02002024 * @brief Set a schema private pointer to a user pointer.
2025 *
2026 * @param[in] node Node, whose private field will be assigned. Works also for RPCs, actions, and notifications.
2027 * @param[in] priv Arbitrary user-specified pointer.
Radek Krejciaf9cd802020-10-06 21:59:47 +02002028 * @param[out] prev_priv_p Optional previous private object of the \p node. Note, that
Michal Vasko2fd91b92020-07-17 16:39:02 +02002029 * the caller is in this case responsible (if it is necessary) for freeing the replaced private object.
2030 * @return LY_ERR value.
2031 */
Radek Krejciaf9cd802020-10-06 21:59:47 +02002032LY_ERR lysc_set_private(const struct lysc_node *node, void *priv, void **prev_priv_p);
Michal Vasko2fd91b92020-07-17 16:39:02 +02002033
2034/**
Radek Krejci151a5b72018-10-19 14:21:44 +02002035 * @brief Get how the if-feature statement currently evaluates.
2036 *
2037 * @param[in] iff Compiled if-feature statement to evaluate.
Michal Vasko28d78432020-05-26 13:10:53 +02002038 * @return LY_SUCCESS if the statement evaluates to true,
2039 * @return LY_ENOT if it evaluates to false,
2040 * @return LY_ERR on error.
Radek Krejci151a5b72018-10-19 14:21:44 +02002041 */
Michal Vasko28d78432020-05-26 13:10:53 +02002042LY_ERR lysc_iffeature_value(const struct lysc_iffeature *iff);
Radek Krejci151a5b72018-10-19 14:21:44 +02002043
2044/**
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002045 * @brief Get the next feature in the module or submodules.
Radek Krejci151a5b72018-10-19 14:21:44 +02002046 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002047 * @param[in] last Last returned feature.
2048 * @param[in] pmod Parsed module and submodoules whose features to iterate over.
2049 * @param[in,out] idx Submodule index, set to 0 on first call.
2050 * @return Next found feature, NULL if the last has already been returned.
Radek Krejci151a5b72018-10-19 14:21:44 +02002051 */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002052struct lysp_feature *lysp_feature_next(const struct lysp_feature *last, const struct lysp_module *pmod, uint32_t *idx);
Radek Krejci151a5b72018-10-19 14:21:44 +02002053
Radek Krejcibed13942020-10-19 16:06:28 +02002054/**
2055 * @defgroup findxpathoptions Atomize XPath options
2056 * Options to modify behavior of ::lys_find_xpath() and ::lys_find_xpath_atoms() searching for schema nodes in schema tree.
2057 * @{
2058 */
Michal Vaskocdad7122020-11-09 21:04:44 +01002059#define LYS_FIND_XP_SCHEMA 0x08 /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */
2060#define LYS_FIND_XP_OUTPUT 0x10 /**< Search RPC/action output nodes instead of input ones. */
Radek Krejci576f8fa2020-10-26 21:23:58 +01002061/** @} findxpathoptions */
Michal Vasko072de482020-08-05 13:27:21 +02002062
Radek Krejci151a5b72018-10-19 14:21:44 +02002063/**
Michal Vasko40308e72020-10-20 16:38:40 +02002064 * @brief Get all the schema nodes that are required for @p xpath to be evaluated (atoms).
Michal Vasko519fd602020-05-26 12:17:39 +02002065 *
Michal Vasko26512682021-01-11 11:35:40 +01002066 * @param[in] ctx libyang context to use. May be NULL if @p ctx_node is set.
2067 * @param[in] ctx_node XPath schema context node. Use NULL for the root node.
Michal Vasko40308e72020-10-20 16:38:40 +02002068 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_PREF_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02002069 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko519fd602020-05-26 12:17:39 +02002070 * @param[out] set Set of found atoms (schema nodes).
2071 * @return LY_SUCCESS on success, @p set is returned.
Michal Vasko40308e72020-10-20 16:38:40 +02002072 * @return LY_ERR value on error.
Michal Vasko519fd602020-05-26 12:17:39 +02002073 */
Michal Vasko26512682021-01-11 11:35:40 +01002074LY_ERR lys_find_xpath_atoms(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *xpath,
2075 uint32_t options, struct ly_set **set);
Michal Vasko519fd602020-05-26 12:17:39 +02002076
Michal Vasko072de482020-08-05 13:27:21 +02002077/**
Michal Vasko40308e72020-10-20 16:38:40 +02002078 * @brief Get all the schema nodes that are required for @p expr to be evaluated (atoms).
Michal Vasko072de482020-08-05 13:27:21 +02002079 *
Michal Vasko26512682021-01-11 11:35:40 +01002080 * @param[in] ctx_node XPath schema context node. Use NULL for the root node.
Michal Vasko40308e72020-10-20 16:38:40 +02002081 * @param[in] cur_mod Current module for the expression (where it was "instantiated").
2082 * @param[in] expr Parsed expression to use.
2083 * @param[in] prefixes Sized array of compiled prefixes.
2084 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
2085 * @param[out] set Set of found atoms (schema nodes).
2086 * @return LY_SUCCESS on success, @p set is returned.
2087 * @return LY_ERR value on error.
2088 */
2089LY_ERR lys_find_expr_atoms(const struct lysc_node *ctx_node, const struct lys_module *cur_mod,
2090 const struct lyxp_expr *expr, const struct lysc_prefix *prefixes, uint32_t options, struct ly_set **set);
2091
2092/**
2093 * @brief Evaluate an @p xpath expression on schema nodes.
2094 *
Michal Vasko26512682021-01-11 11:35:40 +01002095 * @param[in] ctx libyang context to use for absolute @p xpath. May be NULL if @p ctx_node is set.
2096 * @param[in] ctx_node XPath schema context node for relative @p xpath. Use NULL for the root node.
Michal Vasko40308e72020-10-20 16:38:40 +02002097 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_PREF_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02002098 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko072de482020-08-05 13:27:21 +02002099 * @param[out] set Set of found schema nodes.
2100 * @return LY_SUCCESS on success, @p set is returned.
2101 * @return LY_ERR value if an error occurred.
2102 */
Michal Vasko26512682021-01-11 11:35:40 +01002103LY_ERR lys_find_xpath(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *xpath, uint32_t options,
2104 struct ly_set **set);
Michal Vasko519fd602020-05-26 12:17:39 +02002105
2106/**
Radek Krejcibc5644c2020-10-27 14:53:17 +01002107 * @brief Get all the schema nodes that are required for @p path to be evaluated (atoms).
2108 *
2109 * @param[in] path Compiled path to use.
2110 * @param[out] set Set of found atoms (schema nodes).
2111 * @return LY_SUCCESS on success, @p set is returned.
2112 * @return LY_ERR value on error.
2113 */
2114LY_ERR lys_find_lypath_atoms(const struct ly_path *path, struct ly_set **set);
2115
2116/**
2117 * @brief Get all the schema nodes that are required for @p path to be evaluated (atoms).
2118 *
Michal Vasko26512682021-01-11 11:35:40 +01002119 * @param[in] ctx libyang context to use for absolute @p path. May be NULL if @p ctx_node is set.
2120 * @param[in] ctx_node XPath schema context node for relative @p path. Use NULL for the root node.
Radek Krejcibc5644c2020-10-27 14:53:17 +01002121 * @param[in] path JSON path to examine.
2122 * @param[in] output Search operation output instead of input.
2123 * @param[out] set Set of found atoms (schema nodes).
2124 * @return LY_ERR value on error.
2125 */
2126LY_ERR lys_find_path_atoms(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *path, ly_bool output,
2127 struct ly_set **set);
2128
2129/**
2130 * @brief Get a schema node based on the given data path (JSON format, see @ref howtoXPath).
2131 *
Michal Vasko26512682021-01-11 11:35:40 +01002132 * @param[in] ctx libyang context to use for absolute @p path. May be NULL if @p ctx_node is set.
2133 * @param[in] ctx_node XPath schema context node for relative @p path. Use NULL for the root node.
Radek Krejcibc5644c2020-10-27 14:53:17 +01002134 * @param[in] path JSON path of the node to get.
2135 * @param[in] output Search operation output instead of input.
2136 * @return Found schema node or NULL.
2137 */
2138const struct lysc_node *lys_find_path(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *path,
2139 ly_bool output);
2140
2141/**
Michal Vasko03ff5a72019-09-11 13:49:33 +02002142 * @brief Types of the different schema paths.
2143 */
2144typedef enum {
Michal Vasko65de0402020-08-03 16:34:19 +02002145 LYSC_PATH_LOG, /**< Descriptive path format used in log messages */
2146 LYSC_PATH_DATA /**< Similar to ::LYSC_PATH_LOG except that schema-only nodes (choice, case) are skipped */
Michal Vasko03ff5a72019-09-11 13:49:33 +02002147} LYSC_PATH_TYPE;
2148
2149/**
Radek Krejci327de162019-06-14 12:52:07 +02002150 * @brief Generate path of the given node in the requested format.
2151 *
2152 * @param[in] node Schema path of this node will be generated.
2153 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02002154 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
2155 * If NULL, memory for the complete path is allocated.
2156 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02002157 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02002158 * 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 +02002159 */
Michal Vasko03ff5a72019-09-11 13:49:33 +02002160char *lysc_path(const struct lysc_node *node, LYSC_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02002161
2162/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002163 * @brief Available YANG schema tree structures representing YANG module.
2164 */
2165struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002166 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
2167 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01002168 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002169 const char *ns; /**< namespace of the module (module - mandatory) */
2170 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
2171 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
2172 const char *org; /**< party/company responsible for the module */
2173 const char *contact; /**< contact information for the module */
2174 const char *dsc; /**< description of the module */
2175 const char *ref; /**< cross-reference for the module */
2176
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002177 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01002178 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
2179 Available only for implemented modules. */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002180
Radek Krejci80d281e2020-09-14 17:42:54 +02002181 struct lysc_ident *identities; /**< List of compiled identities of the module ([sized array](@ref sizedarrays))
2182 Identities are outside the compiled tree to allow their linkage to the identities from
2183 the implemented modules. This avoids problems when the module became implemented in
2184 future (no matter if implicitly via augment/deviate or explicitly via
2185 ::lys_set_implemented()). Note that if the module is not implemented (compiled), the
2186 identities cannot be instantiated in data (in identityrefs). */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002187
2188 struct lys_module **augmented_by;/**< List of modules that augment this module ([sized array](@ref sizedarrays)) */
2189 struct lys_module **deviated_by; /**< List of modules that deviate this module ([sized array](@ref sizedarrays)) */
2190
Michal Vasko89b5c072020-10-06 13:52:44 +02002191 ly_bool implemented; /**< flag if the module is implemented, not just imported */
Radek Krejci95710c92019-02-11 15:49:55 +01002192 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002193 1 - the latest revision in searchdirs was not searched yet and this is the
2194 latest revision in the current context
2195 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002196};
2197
Radek Krejci151a5b72018-10-19 14:21:44 +02002198/**
Michal Vasko82c31e62020-07-17 15:30:40 +02002199 * @brief Get the current real status of the specified feature in the module.
2200 *
2201 * If the feature is enabled, but some of its if-features are false, the feature is considered
2202 * disabled.
Radek Krejci151a5b72018-10-19 14:21:44 +02002203 *
2204 * @param[in] module Module where the feature is defined.
2205 * @param[in] feature Name of the feature to inspect.
Michal Vasko82c31e62020-07-17 15:30:40 +02002206 * @return LY_SUCCESS if the feature is enabled,
2207 * @return LY_ENOT if the feature is disabled,
2208 * @return LY_ENOTFOUND if the feature was not found.
Radek Krejci151a5b72018-10-19 14:21:44 +02002209 */
Michal Vasko82c31e62020-07-17 15:30:40 +02002210LY_ERR lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02002211
2212/**
Radek Krejcia3045382018-11-22 14:30:31 +01002213 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
2214 * be from an augment.
2215 *
Radek Krejci8678fa42020-08-18 16:07:28 +02002216 * ::lys_getnext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
Radek Krejcia3045382018-11-22 14:30:31 +01002217 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
2218 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
2219 * \p parent and \p module parameters.
2220 *
2221 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
2222 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
2223 * all the schema nodes are iteratively returned.
2224 *
2225 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
2226 * @param[in] parent Parent of the subtree where the function starts processing.
2227 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
2228 * module must be specified.
2229 * @param[in] options [ORed options](@ref sgetnextflags).
2230 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
2231 */
2232const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002233 const struct lysc_module *module, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002234
2235/**
Radek Krejci8678fa42020-08-18 16:07:28 +02002236 * @defgroup sgetnextflags Options for ::lys_getnext().
2237 *
2238 * Various options setting behavior of ::lys_getnext().
2239 *
Radek Krejcia3045382018-11-22 14:30:31 +01002240 * @{
2241 */
Radek Krejci8678fa42020-08-18 16:07:28 +02002242#define LYS_GETNEXT_WITHCHOICE 0x01 /**< ::lys_getnext() option to allow returning #LYS_CHOICE nodes instead of looking into them */
2243#define LYS_GETNEXT_NOCHOICE 0x02 /**< ::lys_getnext() option to ignore (kind of conditional) nodes within choice node */
2244#define LYS_GETNEXT_WITHCASE 0x04 /**< ::lys_getnext() option to allow returning #LYS_CASE nodes instead of looking into them */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002245#define LYS_GETNEXT_INTONPCONT 0x08 /**< ::lys_getnext() option to look into non-presence container, instead of returning container itself */
2246#define LYS_GETNEXT_OUTPUT 0x10 /**< ::lys_getnext() option to provide RPC's/action's output schema nodes instead of input schema nodes
Radek Krejci6eeb58f2019-02-22 16:29:37 +01002247 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01002248/** @} sgetnextflags */
2249
2250/**
2251 * @brief Get child node according to the specified criteria.
2252 *
2253 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
2254 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
2255 * @param[in] name Name of the node to find.
2256 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
2257 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
2258 * Used as a bitmask, so multiple nodetypes can be specified.
2259 * @param[in] options [ORed options](@ref sgetnextflags).
2260 * @return Found node if any.
2261 */
Michal Vaskoe444f752020-02-10 12:20:06 +01002262const struct lysc_node *lys_find_child(const struct lysc_node *parent, const struct lys_module *module,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002263 const char *name, size_t name_len, uint16_t nodetype, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002264
2265/**
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002266 * @brief Make the specific module implemented.
2267 *
Michal Vaskoe8988e92021-01-25 11:26:29 +01002268 * If the module is already implemented but with a different set of features, the whole context is recompiled.
2269 *
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002270 * @param[in] mod Module to make implemented. It is not an error
2271 * to provide already implemented module, it just does nothing.
Michal Vaskoe8988e92021-01-25 11:26:29 +01002272 * @param[in] features Optional array specifying the enabled features terminated with NULL overriding any previous
2273 * feature setting. The feature string '*' enables all the features and array of length 1 with only the terminating
2274 * NULL explicitly disables all the features. In case the parameter is NULL, the features are untouched - left disabled
2275 * in a newly implemented module or with the current features settings in case the module is already implemented.
Michal Vaskoe444f752020-02-10 12:20:06 +01002276 * @return LY_SUCCESS on success.
2277 * @return LY_EDENIED in case the context contains some other revision of the same module which is already implemented.
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002278 * @return LY_ERR on other errors during module compilation.
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002279 */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002280LY_ERR lys_set_implemented(struct lys_module *mod, const char **features);
Radek Krejcia3045382018-11-22 14:30:31 +01002281
Radek Krejci084289f2019-07-09 17:35:30 +02002282/**
2283 * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
2284 *
2285 * This function check just the type's restriction, if you want to check also the data tree context (e.g. in case of
Radek Krejci8678fa42020-08-18 16:07:28 +02002286 * require-instance restriction), use ::lyd_value_validate().
Radek Krejci084289f2019-07-09 17:35:30 +02002287 *
2288 * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
2289 * @param[in] node Schema node for the @p value.
Michal Vaskof937cfe2020-08-03 16:07:12 +02002290 * @param[in] value String value to be checked, expected to be in JSON format.
Radek Krejci084289f2019-07-09 17:35:30 +02002291 * @param[in] value_len Length of the given @p value (mandatory).
Radek Krejci084289f2019-07-09 17:35:30 +02002292 * @return LY_SUCCESS on success
2293 * @return LY_ERR value if an error occurred.
2294 */
Michal Vaskof937cfe2020-08-03 16:07:12 +02002295LY_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 +02002296
Radek Krejci0935f412019-08-20 16:15:18 +02002297/**
2298 * @brief Stringify schema nodetype.
Michal Vaskod43d71a2020-08-07 14:54:58 +02002299 *
Radek Krejci0935f412019-08-20 16:15:18 +02002300 * @param[in] nodetype Nodetype to stringify.
2301 * @return Constant string with the name of the node's type.
2302 */
2303const char *lys_nodetype2str(uint16_t nodetype);
2304
Michal Vaskod43d71a2020-08-07 14:54:58 +02002305/**
2306 * @brief Getter for original XPath expression from a parsed expression.
2307 *
2308 * @param[in] path Parsed expression.
2309 * @return Original string expression.
2310 */
2311const char *lyxp_get_expr(const struct lyxp_expr *path);
2312
Radek Krejci2ff0d572020-05-21 15:27:28 +02002313/** @} schematree */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002314
Radek Krejci70853c52018-10-15 14:46:16 +02002315#ifdef __cplusplus
2316}
2317#endif
2318
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002319#endif /* LY_TREE_SCHEMA_H_ */