blob: 8872ad37fc020c0b899d8897bd01873950e93990 [file] [log] [blame]
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001/**
2 * @file tree_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief libyang representation of YANG schema trees.
5 *
6 * Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_TREE_SCHEMA_H_
16#define LY_TREE_SCHEMA_H_
17
Radek Krejci54579462019-04-30 12:47:06 +020018#define PCRE2_CODE_UNIT_WIDTH 8
19
20#include <pcre2.h>
Radek Krejci535ea9f2020-05-29 16:01:05 +020021
Radek Krejci5aeea3a2018-09-05 13:29:36 +020022#include <stdint.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020023#include <stdio.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020024
Radek Krejcie7b95092019-05-15 11:03:07 +020025#include "log.h"
26#include "tree.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020027#include "tree_data.h"
Radek Krejcice8c1592018-10-29 15:35:51 +010028
Radek Krejci70853c52018-10-15 14:46:16 +020029#ifdef __cplusplus
30extern "C" {
31#endif
32
Radek Krejcica376bd2020-06-11 16:04:06 +020033struct ly_ctx;
34struct ly_set;
35
Radek Krejci5aeea3a2018-09-05 13:29:36 +020036/**
Radek Krejci8678fa42020-08-18 16:07:28 +020037 * @page howtoSchema YANG Modules
38 *
39 * To be able to work with YANG data instances, libyang has to represent YANG data models. All the processed modules are stored
40 * in libyang [context](@ref howtoContext) and loaded using [parser functions](@ref howtoSchemaParsers). It means, that there is
41 * no way to create/change YANG module programmatically. However, all the YANG model definitions are available and can be examined
42 * through the C structures. All the context's modules together form YANG Schema for the data being instantiated.
43 *
44 * Any YANG module is represented as ::lys_module. In fact, the module is represented in two different formats. As ::lys_module.parsed,
45 * there is a parsed schema reflecting the source YANG module. It is exactly what is read from the input. This format is good for
46 * converting from one format to another (YANG to YIN and vice versa), but it is not very useful for validating/manipulating YANG
47 * data. Therefore, there is ::lys_module.compiled storing the compiled YANG module. It is based on the parsed module, but all the
48 * 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
49 * `uses` or `type` references. This split also means, that the YANG module is fully validated after compilation of the parsed
50 * representation of the module. YANG submodules are available only in the parsed representation. When a submodule is compiled, it
51 * is fully integrated into its main module.
52 *
53 * The context can contain even modules without the compiled representation. Such modules are still useful as imports of other
54 * modules. The grouping or typedef definition can be even compiled into the importing modules. This is actually the main
55 * difference between the imported and implemented modules in the libyang context. The implemented modules are compiled while the
56 * imported modules are only parsed.
57 *
58 * In case the context's ::LY_CTX_ALLIMPLEMENTED option is not set, the module is not implemented in case it is implicitly
59 * loaded as import for another module and it is not referenced in such a module (and no other) as target of leafref, augment
60 * or deviation.
61 *
62 * All modules with deviation definition are always marked as implemented. The imported (not implemented) module can be set implemented by ::lys_set_implemented(). But
63 * the implemented module cannot be changed back to just imported module. Note also that only one revision of a specific module
64 * can be implemented in a single context. The imported modules are used only as a
65 * source of definitions for types and groupings for uses statements. The data in such modules are ignored - caller
66 * is not allowed to create the data (including instantiating identities) defined in the model via data parsers,
67 * the default nodes are not added into any data tree and mandatory nodes are not checked in the data trees.
68 *
69 * The compiled schema tree nodes are able to hold private objects (::lysc_node.priv as a pointer to a structure, function, variable, ...) used by
70 * a caller application. Such an object can be assigned to a specific node using ::lysc_set_private() function.
71 * Note that the object is not freed by libyang when the context is being destroyed. So the caller is responsible
72 * for freeing the provided structure after the context is destroyed or the private pointer is set to NULL in
73 * appropriate schema nodes where the object was previously set. This can be automated via destructor function
74 * to free these private objects. The destructor is passed to the ::ly_ctx_destroy() function.
75 *
76 * Despite all the schema structures and their members are available as part of the libyang API and callers can use
77 * it to navigate through the schema tree structure or to obtain various information, we recommend to use the following
78 * macros for the specific actions.
79 * - ::LYSC_TREE_DFS_BEGIN and ::LYSC_TREE_DFS_END to traverse the schema tree (depth-first).
80 * - ::LY_LIST_FOR and ::LY_ARRAY_FOR as described on @ref howtoStructures page.
81 *
82 * Further information about modules handling can be found on the following pages:
83 * - @subpage howtoSchemaParsers
84 * - @subpage howtoSchemaFeatures
85 * - @subpage howtoPlugins
86 * - @subpage howtoSchemaPrinters
87 *
88 * \note There are many functions to access information from the schema trees. Details are available in
89 * the [Schema Tree module](@ref schematree).
90 *
91 * For information about difference between implemented and imported modules, see the
92 * [context description](@ref howtoContext).
93 *
94 * Functions List (not assigned to above subsections)
95 * --------------------------------------------------
96 * - ::lys_getnext()
97 * - ::lys_nodetype2str()
98 * - ::lys_set_implemented()
99 * - ::lys_value_validate()
100 *
101 * - ::lysc_set_private()
102 *
103 * - ::lysc_node_children()
Michal Vasko208a04a2020-10-21 15:17:12 +0200104 * - ::lysc_node_children_full()
105 * - ::lysc_node_parent_full()
Radek Krejci8678fa42020-08-18 16:07:28 +0200106 * - ::lysc_node_actions()
107 * - ::lysc_node_notifs()
108 *
109 * - ::lysp_node_children()
110 * - ::lysp_node_actions()
111 * - ::lysp_node_notifs()
112 * - ::lysp_node_groupings()
113 * - ::lysp_node_typedefs()
114 */
115
116/**
117 * @page howtoSchemaFeatures YANG Features
118 *
119 * YANG feature statement is an iportant part of the language which can significantly affect the meaning of the schemas. Despite
120 * the features have similar effect as loading/removing schema from the context, manipulating with the feature value is not
121 * limited to the context preparation period before working with data. YANG features, respectively their use in if-feature
122 * statements, are evaluated as part of the [data validation process](@ref howtoDataValidation).
123 *
124 * The main functions with *lys_feature_* prefix are used to change the value (true/false) of the feature and to get its current
125 * value. Enabling/disabling all the features in a particular module can be done using '`*`' value instead of the feature name.
126 *
127 * There are two options to reflect feature's if-feature statements when enabling/disabling the feature. The ::lys_feature_enable()
128 * and ::lys_feature_disable() functions check their if-feature expressions (it is not possible to enable feature if it is not
129 * allowed by its if-feature expressions) and also checks for and update other features those if-feature expressions use the
130 * changed feature. On the contrary, ::lys_feature_enable_force() and ::lys_feature_disable_force() ignore all the if-feature
131 * limitations.
132 *
133 * The ::lysc_feature_value() and ::lys_feature_value() functions differ only by their parameters. The ::lysc_iffeature_value()
134 * is used to evaluate (possibly complex in YANG 1.1) logical expression from if-feature statement.
135 *
136 * The list of features of a particular YANG module is available in ::lys_module.features.
137 *
138 * To get know, if a specific schema node is currently disabled or enable, the ::lysc_node_is_disabled() function can be used.
139 *
140 * Note, that the feature's state can affect some of the output formats (e.g. Tree format).
141 *
142 * Functions List
143 * --------------
144 * - ::lys_feature_enable()
145 * - ::lys_feature_enable_force()
146 * - ::lys_feature_disable()
147 * - ::lys_feature_disable_force()
148 * - ::lys_feature_value()
149 * - ::lysc_feature_value()
150 * - ::lysc_iffeature_value()
151 *
152 * - ::lysc_node_is_disabled()
153 */
154
155/**
Radek Krejci2ff0d572020-05-21 15:27:28 +0200156 * @ingroup trees
Radek Krejci8678fa42020-08-18 16:07:28 +0200157 * @defgroup schematree Schema Tree
Radek Krejci2ff0d572020-05-21 15:27:28 +0200158 * @{
159 *
160 * Data structures and functions to manipulate and access schema tree.
161 */
162
Michal Vasko64246d82020-08-19 12:35:00 +0200163/* *INDENT-OFF* */
164
Radek Krejci2ff0d572020-05-21 15:27:28 +0200165/**
Michal Vasko208a04a2020-10-21 15:17:12 +0200166 * @brief Macro to iterate via all elements in a schema (sub)tree including input and output.
167 * Note that __actions__ and __notifications__ of traversed nodes __are ignored__! To traverse
168 * on all the nodes including those, use ::lysc_tree_dfs_full() instead.
169 *
170 * 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 +0200171 *
172 * The function follows deep-first search algorithm:
173 * <pre>
174 * 1
175 * / \
176 * 2 4
177 * / / \
178 * 3 5 6
179 * </pre>
180 *
181 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
182 * START can be any of the lysc_node* types (including lysc_action and lysc_notif),
183 * ELEM variable must be of the struct lysc_node* type.
184 *
185 * To skip a particular subtree, instead of the continue statement, set LYSC_TREE_DFS_continue
186 * variable to non-zero value.
187 *
188 * Use with opening curly bracket '{' after the macro.
189 *
190 * @param START Pointer to the starting element processed first.
191 * @param ELEM Iterator intended for use in the block.
192 */
193#define LYSC_TREE_DFS_BEGIN(START, ELEM) \
Radek Krejci857189e2020-09-01 13:26:36 +0200194 { ly_bool LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
Michal Vasko1c9e79f2020-08-10 11:08:03 +0200195 for ((ELEM) = (LYSC_TREE_DFS_next) = (struct lysc_node*)(START); \
Radek Krejci0935f412019-08-20 16:15:18 +0200196 (ELEM); \
197 (ELEM) = (LYSC_TREE_DFS_next), LYSC_TREE_DFS_continue = 0)
198
199/**
200 * @brief Macro to iterate via all elements in a (sub)tree. This is the closing part
201 * to the #LYSC_TREE_DFS_BEGIN - they always have to be used together.
202 *
203 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
204 * START can be a pointer to any of the lysc_node* types (including lysc_action and lysc_notif),
205 * ELEM variable must be pointer to the lysc_node type.
206 *
207 * Use with closing curly bracket '}' after the macro.
208 *
209 * @param START Pointer to the starting element processed first.
210 * @param ELEM Iterator intended for use in the block.
211 */
Radek Krejci0935f412019-08-20 16:15:18 +0200212#define LYSC_TREE_DFS_END(START, ELEM) \
213 /* select element for the next run - children first */ \
214 if (LYSC_TREE_DFS_continue) { \
215 (LYSC_TREE_DFS_next) = NULL; \
216 } else { \
Michal Vasko208a04a2020-10-21 15:17:12 +0200217 (LYSC_TREE_DFS_next) = (struct lysc_node *)lysc_node_children_full(ELEM, 0); \
218 } \
Radek Krejci0935f412019-08-20 16:15:18 +0200219 if (!(LYSC_TREE_DFS_next)) { \
Michal Vasko208a04a2020-10-21 15:17:12 +0200220 /* no children, try siblings */ \
221 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
Radek Krejci0935f412019-08-20 16:15:18 +0200222 } \
223 while (!(LYSC_TREE_DFS_next)) { \
224 /* parent is already processed, go to its sibling */ \
Michal Vasko208a04a2020-10-21 15:17:12 +0200225 (ELEM) = (struct lysc_node *)lysc_node_parent_full(ELEM); \
226 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
227 } }
228
229/**
230 * @brief Helper macro for #LYSC_TREE_DFS_END, should not be used directly!
231 */
232#define _LYSC_TREE_DFS_NEXT(START, ELEM, NEXT) \
233 if ((ELEM) == (struct lysc_node *)(START)) { \
234 /* we are done, no next element to process */ \
235 break; \
236 } \
237 if ((ELEM)->nodetype == LYS_INPUT) { \
238 /* after input, get output */ \
239 (NEXT) = (struct lysc_node *)lysc_node_children_full(lysc_node_parent_full(ELEM), LYS_CONFIG_R); \
240 } else if ((ELEM)->nodetype == LYS_OUTPUT) { \
241 /* no sibling of output */ \
242 (NEXT) = NULL; \
243 } else { \
244 (NEXT) = (ELEM)->next; \
245 }
Radek Krejci0935f412019-08-20 16:15:18 +0200246
Michal Vasko64246d82020-08-19 12:35:00 +0200247/* *INDENT-ON* */
248
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200249#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
250
Michal Vasko7f45cf22020-10-01 12:49:44 +0200251#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
252#define LYS_CONTAINER 0x0001 /**< container statement node */
253#define LYS_CHOICE 0x0002 /**< choice statement node */
254#define LYS_LEAF 0x0004 /**< leaf statement node */
255#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
256#define LYS_LIST 0x0010 /**< list statement node */
257#define LYS_ANYXML 0x0020 /**< anyxml statement node */
258#define LYS_ANYDATA 0x0060 /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
259#define LYS_CASE 0x0080 /**< case statement node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200260
Michal Vasko7f45cf22020-10-01 12:49:44 +0200261#define LYS_RPC 0x0100 /**< RPC statement node */
262#define LYS_ACTION 0x0200 /**< action statement node */
263#define LYS_NOTIF 0x0400 /**< notification statement node */
Radek Krejcie7b95092019-05-15 11:03:07 +0200264
Michal Vasko7f45cf22020-10-01 12:49:44 +0200265#define LYS_USES 0x0800 /**< uses statement node */
266#define LYS_INPUT 0x1000 /**< RPC/action input node */
267#define LYS_OUTPUT 0x2000 /**< RPC/action output node */
268#define LYS_GROUPING 0x4000
269#define LYS_AUGMENT 0x8000
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100270
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200271/**
Radek Krejcid6b76452019-09-03 17:03:03 +0200272 * @brief List of YANG statements
273 */
274enum ly_stmt {
275 LY_STMT_NONE = 0,
Radek Krejci8678fa42020-08-18 16:07:28 +0200276 LY_STMT_STATUS, /**< in ::lysc_ext_substmt.storage stored as a pointer to `uint16_t`, only cardinality < #LY_STMT_CARD_SOME is allowed */
277 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 +0200278 LY_STMT_MANDATORY,
Radek Krejci8678fa42020-08-18 16:07:28 +0200279 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 +0200280 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200281 LY_STMT_DEFAULT,
Radek Krejci8678fa42020-08-18 16:07:28 +0200282 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 +0200283 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_type **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200284
Radek Krejcid6b76452019-09-03 17:03:03 +0200285 LY_STMT_ACTION,
286 LY_STMT_ANYDATA,
287 LY_STMT_ANYXML,
288 LY_STMT_ARGUMENT,
289 LY_STMT_AUGMENT,
290 LY_STMT_BASE,
291 LY_STMT_BELONGS_TO,
292 LY_STMT_BIT,
293 LY_STMT_CASE,
294 LY_STMT_CHOICE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200295 LY_STMT_CONTACT,
296 LY_STMT_CONTAINER,
Radek Krejcid6b76452019-09-03 17:03:03 +0200297 LY_STMT_DESCRIPTION,
298 LY_STMT_DEVIATE,
299 LY_STMT_DEVIATION,
300 LY_STMT_ENUM,
301 LY_STMT_ERROR_APP_TAG,
302 LY_STMT_ERROR_MESSAGE,
303 LY_STMT_EXTENSION,
304 LY_STMT_FEATURE,
305 LY_STMT_FRACTION_DIGITS,
306 LY_STMT_GROUPING,
307 LY_STMT_IDENTITY,
Radek Krejci8678fa42020-08-18 16:07:28 +0200308 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 +0200309 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_iffeature *` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200310 LY_STMT_IMPORT,
311 LY_STMT_INCLUDE,
312 LY_STMT_INPUT,
313 LY_STMT_KEY,
314 LY_STMT_LEAF,
315 LY_STMT_LEAF_LIST,
316 LY_STMT_LENGTH,
317 LY_STMT_LIST,
Radek Krejcid6b76452019-09-03 17:03:03 +0200318 LY_STMT_MAX_ELEMENTS,
319 LY_STMT_MIN_ELEMENTS,
320 LY_STMT_MODIFIER,
321 LY_STMT_MODULE,
322 LY_STMT_MUST,
323 LY_STMT_NAMESPACE,
324 LY_STMT_NOTIFICATION,
325 LY_STMT_ORDERED_BY,
326 LY_STMT_ORGANIZATION,
327 LY_STMT_OUTPUT,
328 LY_STMT_PATH,
329 LY_STMT_PATTERN,
330 LY_STMT_POSITION,
331 LY_STMT_PREFIX,
332 LY_STMT_PRESENCE,
333 LY_STMT_RANGE,
334 LY_STMT_REFERENCE,
335 LY_STMT_REFINE,
336 LY_STMT_REQUIRE_INSTANCE,
337 LY_STMT_REVISION,
338 LY_STMT_REVISION_DATE,
339 LY_STMT_RPC,
Radek Krejcid6b76452019-09-03 17:03:03 +0200340 LY_STMT_SUBMODULE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200341 LY_STMT_TYPEDEF,
342 LY_STMT_UNIQUE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200343 LY_STMT_USES,
344 LY_STMT_VALUE,
345 LY_STMT_WHEN,
346 LY_STMT_YANG_VERSION,
347 LY_STMT_YIN_ELEMENT,
348 LY_STMT_EXTENSION_INSTANCE,
349
350 LY_STMT_SYNTAX_SEMICOLON,
351 LY_STMT_SYNTAX_LEFT_BRACE,
352 LY_STMT_SYNTAX_RIGHT_BRACE,
353
354 LY_STMT_ARG_TEXT,
355 LY_STMT_ARG_VALUE
356};
357
358/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200359 * @brief Extension instance structure parent enumeration
360 */
361typedef enum {
Radek Krejci0935f412019-08-20 16:15:18 +0200362 LYEXT_PAR_MODULE, /**< ::lysc_module */
363 LYEXT_PAR_NODE, /**< ::lysc_node (and the derived structures including ::lysc_action and ::lysc_notif) */
364 LYEXT_PAR_INPUT, /**< ::lysc_action_inout */
365 LYEXT_PAR_OUTPUT, /**< ::lysc_action_inout */
366 LYEXT_PAR_TYPE, /**< ::lysc_type */
367 LYEXT_PAR_TYPE_BIT, /**< ::lysc_type_bitenum_item */
368 LYEXT_PAR_TYPE_ENUM, /**< ::lysc_type_bitenum_item */
369 LYEXT_PAR_FEATURE, /**< ::lysc_feature */
370 LYEXT_PAR_MUST, /**< ::lysc_must */
371 LYEXT_PAR_PATTERN, /**< ::lysc_pattern */
372 LYEXT_PAR_LENGTH, /**< ::lysc_range */
373 LYEXT_PAR_RANGE, /**< ::lysc_range */
374 LYEXT_PAR_WHEN, /**< ::lysc_when */
375 LYEXT_PAR_IDENT, /**< ::lysc_ident */
376 LYEXT_PAR_EXT, /**< ::lysc_ext */
Michal Vasko69730152020-10-09 16:30:07 +0200377 LYEXT_PAR_IMPORT /**< ::lysp_import */
Michal Vasko033278d2020-08-24 11:24:52 +0200378// LYEXT_PAR_TPDF, /**< ::lysp_tpdf */
379// LYEXT_PAR_EXTINST, /**< ::lysp_ext_instance */
380// LYEXT_PAR_REFINE, /**< ::lysp_refine */
381// LYEXT_PAR_DEVIATION, /**< ::lysp_deviation */
382// LYEXT_PAR_DEVIATE, /**< ::lysp_deviate */
383// LYEXT_PAR_INCLUDE, /**< ::lysp_include */
384// LYEXT_PAR_REVISION, /**< ::lysp_revision */
Radek Krejci0e59c312019-08-15 15:34:15 +0200385} LYEXT_PARENT;
386
387/**
Radek Krejci0935f412019-08-20 16:15:18 +0200388 * @brief Stringify extension instance parent type.
389 * @param[in] type Parent type to stringify.
390 * @return Constant string with the name of the parent statement.
391 */
392const char *lyext_parent2str(LYEXT_PARENT type);
393
394/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200395 * @brief Enum of substatements in which extension instances can appear.
396 */
397typedef enum {
398 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
399 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
400 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
401 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
402 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
403 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
404 lys_node_choice and lys_deviate */
405 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
406 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
407 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
408 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
409 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
410 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
411 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
412 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
413 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
414 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
415 belongs-to's prefix) and lys_import */
416 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
417 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
418 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
419 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
420 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
421 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
422 lys_node_leaflist and lys_deviate */
423 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
424 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
425 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
426 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
427 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
428 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
429 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
430 lys_node_anydata and lys_deviate */
431 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
432 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
433 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
434 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
435 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
436 lys_node_leaflist and lys_deviate */
437 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
438 lys_node_leaflist and lys_deviate */
439 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
440 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
Michal Vasko69730152020-10-09 16:30:07 +0200441 LYEXT_SUBSTMT_IFFEATURE /**< extension of the if-feature statement */
Radek Krejci0e59c312019-08-15 15:34:15 +0200442} LYEXT_SUBSTMT;
443
444/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200445 * @brief YANG import-stmt
446 */
447struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200448 struct lys_module *module; /**< pointer to the imported module
449 (mandatory, but resolved when the referring module is completely parsed) */
450 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200451 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200452 const char *dsc; /**< description */
453 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200454 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200455 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
456};
457
458/**
459 * @brief YANG include-stmt
460 */
461struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100462 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200463 (mandatory, but resolved when the referring module is completely parsed) */
464 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200465 const char *dsc; /**< description */
466 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200467 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200468 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
469};
470
471/**
472 * @brief YANG extension-stmt
473 */
474struct lysp_ext {
475 const char *name; /**< extension name */
476 const char *argument; /**< argument name, NULL if not specified */
477 const char *dsc; /**< description statement */
478 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200479 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200480 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */
Michal Vasko5fe75f12020-03-02 13:52:37 +0100481
482 struct lysc_ext *compiled; /**< pointer to the compiled extension definition */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200483};
484
485/**
486 * @brief Helper structure for generic storage of the extension instances content.
487 */
488struct lysp_stmt {
489 const char *stmt; /**< identifier of the statement */
490 const char *arg; /**< statement's argument */
491 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200492 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
David Sedlákb9d75c42019-08-14 10:49:42 +0200493 uint16_t flags; /**< statement flags, can be set to LYS_YIN_ATTR */
Radek Krejci335332a2019-09-05 13:03:35 +0200494 enum ly_stmt kw; /**< numeric respresentation of the stmt value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200495};
496
David Sedlákae4b4512019-08-14 10:45:56 +0200497#define LYS_YIN 0x1 /**< used to specify input format of extension instance */
498
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200499/**
500 * @brief YANG extension instance
501 */
502struct lysp_ext_instance {
David Sedlákbbd06ca2019-06-27 14:15:38 +0200503 const char *name; /**< extension identifier, including possible prefix */
504 const char *argument; /**< optional value of the extension's argument */
Radek Krejci335332a2019-09-05 13:03:35 +0200505 void *parent; /**< pointer to the parent element holding the extension instance(s), use
506 ::lysp_ext_instance#parent_type to access the schema element */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200507 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200508 struct lysc_ext_instance *compiled; /**< pointer to the compiled data if any - in case the source format is YIN,
509 some of the information (argument) are available only after compilation */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200510 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200511 LY_ARRAY_COUNT_TYPE insubstmt_index; /**< in case the instance is in a substatement, this identifies
David Sedlákbbd06ca2019-06-27 14:15:38 +0200512 the index of that substatement */
David Sedlákae4b4512019-08-14 10:45:56 +0200513 uint8_t yin; /** flag for YIN source format, can be set to LYS_YIN */
Radek Krejci335332a2019-09-05 13:03:35 +0200514 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200515};
516
517/**
518 * @brief YANG feature-stmt
519 */
520struct lysp_feature {
521 const char *name; /**< feature name (mandatory) */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200522 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200523 const char *dsc; /**< description statement */
524 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200525 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200526 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
527};
528
529/**
Michal Vasko7f45cf22020-10-01 12:49:44 +0200530 * @brief Qualified name (optional prefix followed by an identifier).
531 */
532struct lysp_qname {
533 const char *str; /**< qualified name string */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200534 const struct lysp_module *mod; /**< module to resolve any prefixes found in the string, it must be
Michal Vasko7f45cf22020-10-01 12:49:44 +0200535 stored explicitly because of deviations/refines */
536};
537
538/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200539 * @brief YANG identity-stmt
540 */
541struct lysp_ident {
542 const char *name; /**< identity name (mandatory), including possible prefix */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200543 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200544 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200545 const char *dsc; /**< description statement */
546 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200547 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200548 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
549};
550
Michal Vasko71e64ca2018-09-07 16:30:29 +0200551/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200552 * @brief Covers restrictions: range, length, pattern, must
553 */
554struct lysp_restr {
Michal Vasko7f45cf22020-10-01 12:49:44 +0200555 struct lysp_qname arg; /**< The restriction expression/value (mandatory);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200556 in case of pattern restriction, the first byte has a special meaning:
557 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
558 const char *emsg; /**< error-message */
559 const char *eapptag; /**< error-app-tag value */
560 const char *dsc; /**< description */
561 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200562 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200563};
564
565/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200566 * @brief YANG revision-stmt
567 */
568struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200569 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200570 const char *dsc; /**< description statement */
571 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200572 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200573};
574
575/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200576 * @brief Enumeration/Bit value definition
577 */
578struct lysp_type_enum {
579 const char *name; /**< name (mandatory) */
580 const char *dsc; /**< description statement */
581 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200582 int64_t value; /**< enum's value or bit's position */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200583 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200584 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200585 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
586 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200587};
588
589/**
590 * @brief YANG type-stmt
591 *
592 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
593 */
594struct lysp_type {
595 const char *name; /**< name of the type (mandatory) */
596 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
597 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200598 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
599 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
600 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Michal Vasko004d3152020-06-11 19:59:22 +0200601 struct lyxp_expr *path; /**< parsed path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200602 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200603 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
604 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200605
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200606 const struct lysp_module *pmod; /**< (sub)module where the type is defined (needed for deviations) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100607 struct lysc_type *compiled; /**< pointer to the compiled type */
608
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200609 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
610 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100611 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200612};
613
614/**
615 * @brief YANG typedef-stmt
616 */
617struct lysp_tpdf {
618 const char *name; /**< name of the newly defined type (mandatory) */
619 const char *units; /**< units of the newly defined type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200620 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 +0200621 const char *dsc; /**< description statement */
622 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200623 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200624 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100625 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200626};
627
628/**
629 * @brief YANG grouping-stmt
630 */
631struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100632 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
633 uint16_t nodetype; /**< LYS_GROUPING */
634 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200635 const char *name; /**< grouping name (mandatory) */
636 const char *dsc; /**< description statement */
637 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200638 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
639 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200640 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200641 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
642 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
643 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200644};
645
646/**
647 * @brief YANG when-stmt
648 */
649struct lysp_when {
650 const char *cond; /**< specified condition (mandatory) */
651 const char *dsc; /**< description statement */
652 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200653 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200654};
655
656/**
657 * @brief YANG refine-stmt
658 */
659struct lysp_refine {
660 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
661 const char *dsc; /**< description statement */
662 const char *ref; /**< reference statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200663 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200664 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200665 const char *presence; /**< presence description */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200666 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200667 uint32_t min; /**< min-elements constraint */
668 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200669 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200670 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
671};
672
673/**
Michal Vasko82a83432019-11-14 12:33:04 +0100674 * @brief YANG uses-augment-stmt and augment-stmt (compatible with struct lysp_node )
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200675 */
676struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100677 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
678 uint16_t nodetype; /**< LYS_AUGMENT */
679 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Michal Vasko82a83432019-11-14 12:33:04 +0100680 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200681 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
682 const char *dsc; /**< description statement */
683 const char *ref; /**< reference statement */
684 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200685 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Michal Vasko82a83432019-11-14 12:33:04 +0100686 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200687 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
688 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200689};
690
691/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200692 * @ingroup schematree
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200693 * @defgroup deviatetypes Deviate types
Radek Krejci8678fa42020-08-18 16:07:28 +0200694 *
695 * Type of the deviate operation (used as ::lysp_deviate.mod)
696 *
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200697 * @{
698 */
699#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
700#define LYS_DEV_ADD 2 /**< deviate type add */
701#define LYS_DEV_DELETE 3 /**< deviate type delete */
702#define LYS_DEV_REPLACE 4 /**< deviate type replace */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200703/** @} deviatetypes */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200704
705/**
706 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
707 */
708struct lysp_deviate {
709 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
710 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200711 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200712};
713
714struct lysp_deviate_add {
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 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200719 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200720 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
721 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200722 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
723 uint32_t min; /**< min-elements constraint */
724 uint32_t max; /**< max-elements constraint, 0 means unbounded */
725};
726
727struct lysp_deviate_del {
728 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
729 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200730 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200731 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200732 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200733 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
734 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200735};
736
737struct lysp_deviate_rpl {
738 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
739 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200740 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200741 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200742 const char *units; /**< units of the values */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200743 struct lysp_qname dflt; /**< default value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200744 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
745 uint32_t min; /**< min-elements constraint */
746 uint32_t max; /**< max-elements constraint, 0 means unbounded */
747};
748
749struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200750 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200751 const char *dsc; /**< description statement */
752 const char *ref; /**< reference statement */
Michal Vasko22df3f02020-08-24 13:29:22 +0200753 struct lysp_deviate *deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200754 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200755};
756
Radek Krejci4f28eda2018-11-12 11:46:16 +0100757/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100758 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200759 * @defgroup spnodeflags Parsed schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100760 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200761 * Various flags for parsed schema nodes (used as ::lysp_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100762 *
763 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
764 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200765 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100766 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
767 * 5 - list 10 - input 15 - typedef 20 - deviate
768 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200769 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
770 * 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
771 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200772 * 1 LYS_CONFIG_W |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200773 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
774 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200775 * 2 LYS_CONFIG_R |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200776 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
777 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
778 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
779 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
780 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
781 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
782 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
783 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
784 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
785 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
786 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
787 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
788 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
789 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
790 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
791 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
792 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
793 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
794 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
795 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
796 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
797 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
798 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
799 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
800 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
801 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
802 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
803 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
804 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
805 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
806 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
807 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200808 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
David Sedlákae4b4512019-08-14 10:45:56 +0200809 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x|
Michal Vasko5297a432020-08-31 12:27:51 +0200810 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
811 * 12 LYS_YIN_ARGUMENT | | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejcif56e2a42019-09-09 14:15:25 +0200812 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100813 *
814 */
815
816/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100817 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200818 * @defgroup scnodeflags Compiled schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100819 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200820 * Various flags for compiled schema nodes (used as ::lysc_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100821 *
Radek Krejci61e042e2019-09-10 15:53:09 +0200822 * 1 - container 6 - anydata/anyxml 11 - identity
823 * 2 - choice 7 - case 12 - extension
824 * 3 - leaf 8 - notification 13 - bitenum
Michal Vasko03ff5a72019-09-11 13:49:33 +0200825 * 4 - leaflist 9 - rpc/action 14 - when
Michal Vaskoecd62de2019-11-13 12:35:11 +0100826 * 5 - list 10 - feature
Radek Krejci4f28eda2018-11-12 11:46:16 +0100827 *
Michal Vaskoecd62de2019-11-13 12:35:11 +0100828 * 1 1 1 1 1
829 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
830 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
831 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | |
832 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
833 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | |
834 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
835 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x|x|x|x| |x|
836 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
837 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x|x|x|x| |x|
838 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
839 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x|x|x|x| |x|
840 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
841 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
842 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
843 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
844 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | |
845 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
846 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
847 * LYS_PRESENCE |x| | | | | | | | | | | | | |
848 * LYS_UNIQUE | | |x| | | | | | | | | | | |
849 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
850 * 9 LYS_KEY | | |x| | | | | | | | | | | |
851 * LYS_FENABLED | | | | | | | | | |x| | | | |
852 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
853 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
854 * LYS_ISENUM | | | | | | | | | | | | |x| |
855 * LYS_KEYLESS | | | | |x| | | | | | | | | |
856 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
857 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
858 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
859 * 12 LYS_SET_CONFIG |x|x|x|x|x|x| | | | | | | | |
860 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100861 *
862 */
863
864/**
865 * @defgroup snodeflags Schema nodes flags
Radek Krejci8678fa42020-08-18 16:07:28 +0200866 *
867 * Various flags for schema nodes ([parsed](@ref spnodeflags) as well as [compiled](@ref scnodeflags)).
868 *
Radek Krejci4f28eda2018-11-12 11:46:16 +0100869 * @{
870 */
Michal Vasko1bf09392020-03-27 12:38:10 +0100871#define LYS_CONFIG_W 0x01 /**< config true; also set for input children nodes */
872#define LYS_CONFIG_R 0x02 /**< config false; also set for output and notification children nodes */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200873#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100874#define LYS_STATUS_CURR 0x04 /**< status current; */
875#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
876#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
877#define LYS_STATUS_MASK 0x1C /**< mask for status value */
878#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100879 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
880 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
881 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
882 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100883#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
884 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
885 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100886#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Michal Vaskoc118ae22020-08-06 14:51:09 +0200887#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, but it is not only for explicit presence
888 containers, but also for NP containers with some meaning, applicable only to
889 ::lysc_node_container */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100890#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
891#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 +0200892#define LYS_KEYLESS 0x200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Radek Krejci8678fa42020-08-18 16:07:28 +0200893#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysc_feature.
894 Do not interpret presence of this flag as enabled feature! Also if-feature statements
895 are supposed to be taken into account, so use ::lys_feature_value() or
896 ::lysc_feature_value() to get know if a specific feature is really enabled. */
Radek Krejcife909632019-02-12 15:34:42 +0100897#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 +0100898 ::lysc_node_list/::lysp_node_list */
899#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
900 ::lysc_node_list/::lysp_node_list */
901#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
902#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
903#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
904#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200905#define LYS_USED_GRP 0x400 /**< internal flag for validating not-instantiated groupings
906 (resp. do not validate again the instantiated groupings). */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100907#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100908#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200909#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100910
911#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
912#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
913#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
914#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
915#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
916#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
917#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
918#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
919#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
920#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100921#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 +0100922 cases of choice. This information is important for refines, since it is prohibited to make leafs
923 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100924 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
925 between own default or the default values taken from the type. */
926#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 +0100927#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 +0100928
Radek Krejcif56e2a42019-09-09 14:15:25 +0200929#define LYS_SINGLEQUOTED 0x100 /**< flag for single-quoted argument of an extension instance's substatement, only when the source is YANG */
930#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 +0200931
Radek Krejcif56e2a42019-09-09 14:15:25 +0200932#define LYS_YIN_ATTR 0x400 /**< flag to identify YIN attribute parsed as extension's substatement, only when the source is YIN */
933#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 +0200934
Radek Krejci693262f2019-04-29 15:23:20 +0200935#define LYS_ISENUM 0x200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
936
Radek Krejcife909632019-02-12 15:34:42 +0100937#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200938/** @} snodeflags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200939
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200940/**
941 * @brief Generic YANG data node
942 */
943struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100944 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200945 uint16_t nodetype; /**< type of the node (mandatory) */
946 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100947 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200948 const char *name; /**< node name (mandatory) */
949 const char *dsc; /**< description statement */
950 const char *ref; /**< reference statement */
951 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200952 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)),
953 must be qname because of refines */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200954 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200955};
956
957/**
958 * @brief Extension structure of the lysp_node for YANG container
959 */
960struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100961 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200962 uint16_t nodetype; /**< LYS_CONTAINER */
963 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
964 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
965 const char *name; /**< node name (mandatory) */
966 const char *dsc; /**< description statement */
967 const char *ref; /**< reference statement */
968 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200969 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200970 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200971
972 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200973 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200974 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200975 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
976 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200977 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200978 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
979 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200980};
981
982struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100983 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200984 uint16_t nodetype; /**< LYS_LEAF */
985 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
986 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
987 const char *name; /**< node name (mandatory) */
988 const char *dsc; /**< description statement */
989 const char *ref; /**< reference statement */
990 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200991 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200992 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200993
994 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200995 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200996 struct lysp_type type; /**< type of the leaf node (mandatory) */
997 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200998 struct lysp_qname dflt; /**< default value, it may or may not be a qualified name */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200999};
1000
1001struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001002 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001003 uint16_t nodetype; /**< LYS_LEAFLIST */
1004 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1005 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1006 const char *name; /**< node name (mandatory) */
1007 const char *dsc; /**< description statement */
1008 const char *ref; /**< reference statement */
1009 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001010 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001011 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001012
1013 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001014 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001015 struct lysp_type type; /**< type of the leaf node (mandatory) */
1016 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001017 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)), they may or
1018 may not be qualified names */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001019 uint32_t min; /**< min-elements constraint */
1020 uint32_t max; /**< max-elements constraint, 0 means unbounded */
1021};
1022
1023struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001024 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001025 uint16_t nodetype; /**< LYS_LIST */
1026 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1027 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1028 const char *name; /**< node name (mandatory) */
1029 const char *dsc; /**< description statement */
1030 const char *ref; /**< reference statement */
1031 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001032 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001033 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001034
1035 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001036 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001037 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001038 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1039 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001040 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001041 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1042 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001043 struct lysp_qname *uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001044 uint32_t min; /**< min-elements constraint */
1045 uint32_t max; /**< max-elements constraint, 0 means unbounded */
1046};
1047
1048struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001049 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001050 uint16_t nodetype; /**< LYS_CHOICE */
1051 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1052 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1053 const char *name; /**< node name (mandatory) */
1054 const char *dsc; /**< description statement */
1055 const char *ref; /**< reference statement */
1056 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001057 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001058 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001059
1060 /* choice */
1061 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001062 struct lysp_qname dflt; /**< default case */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001063};
1064
1065struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001066 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001067 uint16_t nodetype; /**< LYS_CASE */
1068 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1069 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1070 const char *name; /**< node name (mandatory) */
1071 const char *dsc; /**< description statement */
1072 const char *ref; /**< reference statement */
1073 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001074 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001075 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001076
1077 /* case */
1078 struct lysp_node *child; /**< list of data nodes (linked list) */
1079};
1080
1081struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001082 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001083 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001084 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1085 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1086 const char *name; /**< node name (mandatory) */
1087 const char *dsc; /**< description statement */
1088 const char *ref; /**< reference statement */
1089 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001090 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001091 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001092
1093 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001094 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001095};
1096
1097struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001098 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +02001099 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001100 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1101 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1102 const char *name; /**< grouping name reference (mandatory) */
1103 const char *dsc; /**< description statement */
1104 const char *ref; /**< reference statement */
1105 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001106 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001107 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001108
1109 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001110 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
1111 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001112};
1113
1114/**
1115 * @brief YANG input-stmt and output-stmt
1116 */
1117struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001118 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001119 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001120 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1121 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1122 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001123 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001124 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001125};
1126
1127/**
1128 * @brief YANG rpc-stmt and action-stmt
1129 */
1130struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001131 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko1bf09392020-03-27 12:38:10 +01001132 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001133 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001134 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001135 const char *name; /**< grouping name reference (mandatory) */
1136 const char *dsc; /**< description statement */
1137 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001138 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001139 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1140 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1141
1142 /* action */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001143 struct lysp_action_inout input; /**< RPC's/Action's input */
1144 struct lysp_action_inout output; /**< RPC's/Action's output */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001145};
1146
1147/**
1148 * @brief YANG notification-stmt
1149 */
1150struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001151 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1152 uint16_t nodetype; /**< LYS_NOTIF */
1153 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001154 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001155 const char *name; /**< grouping name reference (mandatory) */
1156 const char *dsc; /**< description statement */
1157 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001158 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001159 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001160 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001161
1162 /* notif */
1163 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1164 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001165};
1166
1167/**
Radek Krejcif0fceb62018-09-05 14:58:45 +02001168 * @brief supported YANG schema version values
1169 */
1170typedef enum LYS_VERSION {
1171 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
Radek Krejci96e48da2020-09-04 13:18:06 +02001172 LYS_VERSION_1_0 = 1, /**< YANG 1 (1.0) */
Radek Krejcif0fceb62018-09-05 14:58:45 +02001173 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
1174} LYS_VERSION;
1175
1176/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001177 * @brief Printable YANG schema tree structure representing YANG module.
1178 *
1179 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
1180 */
1181struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001182 struct lys_module *mod; /**< covering module structure */
1183
Radek Krejcib7db73a2018-10-24 14:18:40 +02001184 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1185 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001186 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1187 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001188 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1189 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1190 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1191 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1192 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001193 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001194 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1195 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1196 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1197 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001198 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001199
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001200 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001201 uint8_t parsing : 1; /**< flag for circular check */
1202 uint8_t is_submod : 1; /**< always 0 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001203};
1204
1205struct lysp_submodule {
Michal Vaskoc3781c32020-10-06 14:04:08 +02001206 struct lys_module *mod; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001207
1208 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1209 in the list is always the last (newest) revision of the module */
1210 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1211 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
1212 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1213 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1214 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1215 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1216 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
1217 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
1218 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1219 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1220 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1221 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001222 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001223
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001224 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001225 uint8_t parsing : 1; /**< flag for circular check */
1226 uint8_t is_submod : 1; /**< always 1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001227
Michal Vaskoc3781c32020-10-06 14:04:08 +02001228 uint8_t latest_revision : 2; /**< flag to mark the latest available revision:
Radek Krejci086c7132018-10-26 15:29:04 +02001229 1 - the latest revision in searchdirs was not searched yet and this is the
1230 latest revision in the current context
1231 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001232 const char *name; /**< name of the module (mandatory) */
1233 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1234 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
1235 const char *org; /**< party/company responsible for the module */
1236 const char *contact; /**< contact information for the module */
1237 const char *dsc; /**< description of the module */
1238 const char *ref; /**< cross-reference for the module */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001239};
1240
1241/**
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001242 * @brief Get the parsed module or submodule name.
1243 *
1244 * @param[in] PMOD Parsed module or submodule.
1245 * @return Module or submodule name.
1246 */
1247#define LYSP_MODULE_NAME(PMOD) (PMOD->is_submod ? ((struct lysp_submodule *)PMOD)->name : ((struct lysp_module *)PMOD)->mod->name)
1248
1249/**
1250 * @brief Free the printable YANG schema tree structure. Works for both modules and submodules.
Radek Krejci3f5e3db2018-10-11 15:57:47 +02001251 *
1252 * @param[in] module Printable YANG schema tree structure to free.
1253 */
1254void lysp_module_free(struct lysp_module *module);
1255
1256/**
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001257 * @brief Compiled prefix data pair mapping of prefixes to modules. In case the format is ::LY_PREF_SCHEMA_RESOLVED,
1258 * the expected prefix data is a sized array of these structures.
1259 */
1260struct lysc_prefix {
1261 char *prefix; /**< used prefix */
1262 const struct lys_module *mod; /**< mapping to a module */
1263};
1264
1265/**
Radek Krejci0e59c312019-08-15 15:34:15 +02001266 * @brief Compiled YANG extension-stmt
1267 */
1268struct lysc_ext {
1269 const char *name; /**< extension name */
1270 const char *argument; /**< argument name, NULL if not specified */
Radek Krejci0e59c312019-08-15 15:34:15 +02001271 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1272 struct lyext_plugin *plugin; /**< Plugin implementing the specific extension */
Radek Krejci0935f412019-08-20 16:15:18 +02001273 struct lys_module *module; /**< module structure */
Michal Vasko6f4cbb62020-02-28 11:15:47 +01001274 uint32_t refcount; /**< reference counter since extension definition is shared among all its instances */
Radek Krejci0e59c312019-08-15 15:34:15 +02001275 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
1276};
1277
1278/**
Radek Krejcice8c1592018-10-29 15:35:51 +01001279 * @brief YANG extension instance
1280 */
1281struct lysc_ext_instance {
Radek Krejciad5963b2019-09-06 16:03:05 +02001282 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
1283 this identifies the index of the substatement for this extension instance */
Radek Krejci28681fa2019-09-06 13:08:45 +02001284 struct lys_module *module; /**< module where the extension instantiated is defined */
Radek Krejciad5963b2019-09-06 16:03:05 +02001285 struct lysc_ext *def; /**< pointer to the extension definition */
Radek Krejcice8c1592018-10-29 15:35:51 +01001286 void *parent; /**< pointer to the parent element holding the extension instance(s), use
1287 ::lysc_ext_instance#parent_type to access the schema element */
1288 const char *argument; /**< optional value of the extension's argument */
1289 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +01001290 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001291 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0e59c312019-08-15 15:34:15 +02001292 void *data; /**< private plugins's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +01001293};
1294
1295/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001296 * @brief Compiled YANG if-feature-stmt
1297 */
1298struct lysc_iffeature {
1299 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
1300 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
1301};
1302
1303/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001304 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001305 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001306struct lysc_when {
1307 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko175012e2019-11-06 15:49:14 +01001308 struct lysc_node *context; /**< context node for evaluating the expression, NULL if the context is root node */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001309 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001310 const char *dsc; /**< description */
1311 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001312 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001313 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Michal Vaskoecd62de2019-11-13 12:35:11 +01001314 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS is allowed */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001315};
1316
1317/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001318 * @brief YANG identity-stmt
1319 */
1320struct lysc_ident {
1321 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +01001322 const char *dsc; /**< description */
1323 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001324 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001325 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
1326 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001327 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001328 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1329};
1330
1331/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001332 * @brief YANG feature-stmt
1333 */
1334struct lysc_feature {
1335 const char *name; /**< feature name (mandatory) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001336 const char *dsc; /**< description */
1337 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001338 struct lys_module *module; /**< module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001339 struct lysc_feature **depfeatures;/**< list of pointers to other features depending on this one ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001340 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001341 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001342 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
1343 #LYS_FENABLED values allowed */
1344};
1345
Radek Krejci151a5b72018-10-19 14:21:44 +02001346/**
1347 * @defgroup ifftokens if-feature expression tokens
Radek Krejci8678fa42020-08-18 16:07:28 +02001348 * Tokens of if-feature expression used in ::lysc_iffeature.expr.
Radek Krejci151a5b72018-10-19 14:21:44 +02001349 *
1350 * @{
1351 */
1352#define LYS_IFF_NOT 0x00 /**< operand "not" */
1353#define LYS_IFF_AND 0x01 /**< operand "and" */
1354#define LYS_IFF_OR 0x02 /**< operand "or" */
1355#define LYS_IFF_F 0x03 /**< feature */
Radek Krejci2ff0d572020-05-21 15:27:28 +02001356/** @} ifftokens */
Radek Krejci151a5b72018-10-19 14:21:44 +02001357
1358/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001359 * @brief Compiled YANG revision statement
1360 */
1361struct lysc_revision {
1362 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1363 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1364};
1365
Radek Krejci2167ee12018-11-02 16:09:07 +01001366struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001367 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001368 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001369 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1370 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001371 };
Radek Krejci693262f2019-04-29 15:23:20 +02001372 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001373 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1374 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001375 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001376 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001377 const char *dsc; /**< description */
1378 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001379 const char *emsg; /**< error-message */
1380 const char *eapptag; /**< error-app-tag value */
1381 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1382};
1383
1384struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001385 const char *expr; /**< original, not compiled, regular expression */
1386 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001387 const char *dsc; /**< description */
1388 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001389 const char *emsg; /**< error-message */
1390 const char *eapptag; /**< error-app-tag value */
1391 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0f969882020-08-21 16:56:47 +02001392 uint32_t inverted : 1; /**< invert-match flag */
1393 uint32_t refcount : 31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001394};
1395
1396struct lysc_must {
Radek Krejci2167ee12018-11-02 16:09:07 +01001397 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001398 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001399 const char *dsc; /**< description */
1400 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001401 const char *emsg; /**< error-message */
1402 const char *eapptag; /**< error-app-tag value */
1403 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1404};
1405
1406struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001407 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001408 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 +01001409 LY_DATA_TYPE basetype; /**< Base type of the type */
1410 uint32_t refcount; /**< reference counter for type sharing */
1411};
1412
1413struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001414 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001415 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 +01001416 LY_DATA_TYPE basetype; /**< Base type of the type */
1417 uint32_t refcount; /**< reference counter for type sharing */
1418 struct lysc_range *range; /**< Optional range limitation */
1419};
1420
1421struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001422 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001423 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 +01001424 LY_DATA_TYPE basetype; /**< Base type of the type */
1425 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001426 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001427 struct lysc_range *range; /**< Optional range limitation */
1428};
1429
1430struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001431 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001432 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 +01001433 LY_DATA_TYPE basetype; /**< Base type of the type */
1434 uint32_t refcount; /**< reference counter for type sharing */
1435 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001436 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001437};
1438
Radek Krejci693262f2019-04-29 15:23:20 +02001439struct lysc_type_bitenum_item {
1440 const char *name; /**< enumeration identifier */
1441 const char *dsc; /**< description */
1442 const char *ref; /**< reference */
1443 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1444 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1445 union {
1446 int32_t value; /**< integer value associated with the enumeration */
1447 uint32_t position; /**< non-negative integer value associated with the bit */
1448 };
1449 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1450 values are allowed */
1451};
1452
Radek Krejci2167ee12018-11-02 16:09:07 +01001453struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001454 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001455 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 +01001456 LY_DATA_TYPE basetype; /**< Base type of the type */
1457 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001458 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1459};
1460
1461struct lysc_type_bits {
1462 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001463 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 +02001464 LY_DATA_TYPE basetype; /**< Base type of the type */
1465 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001466 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1467 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001468};
1469
1470struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001471 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001472 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 +01001473 LY_DATA_TYPE basetype; /**< Base type of the type */
1474 uint32_t refcount; /**< reference counter for type sharing */
Michal Vasko004d3152020-06-11 19:59:22 +02001475 struct lyxp_expr *path; /**< parsed target path, compiled path cannot be stored because of type sharing */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001476 struct lysc_prefix *prefixes; /**< resolved prefixes used in the path */
Radek Krejci412ddfa2018-11-23 11:44:11 +01001477 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001478 uint8_t require_instance; /**< require-instance flag */
1479};
1480
1481struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001482 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001483 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 +01001484 LY_DATA_TYPE basetype; /**< Base type of the type */
1485 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001486 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001487 mandatory (at least 1 item) */
1488};
1489
1490struct lysc_type_instanceid {
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 */
1495 uint8_t require_instance; /**< require-instance flag */
1496};
1497
Radek Krejci2167ee12018-11-02 16:09:07 +01001498struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001499 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001500 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 +01001501 LY_DATA_TYPE basetype; /**< Base type of the type */
1502 uint32_t refcount; /**< reference counter for type sharing */
1503 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1504};
1505
1506struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001507 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001508 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 +01001509 LY_DATA_TYPE basetype; /**< Base type of the type */
1510 uint32_t refcount; /**< reference counter for type sharing */
1511 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001512};
1513
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001514struct lysc_action_inout {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001515 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001516 struct lysc_node *data; /**< first child node (linked list) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001517 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1518};
1519
Michal Vasko60ea6352020-06-29 13:39:39 +02001520/**
1521 * @brief Maximum number of hashes stored in a schema node.
1522 */
1523#define LYS_NODE_HASH_COUNT 4
1524
Radek Krejci056d0a82018-12-06 16:57:25 +01001525struct lysc_action {
Michal Vasko1bf09392020-03-27 12:38:10 +01001526 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci056d0a82018-12-06 16:57:25 +01001527 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001528 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejci95710c92019-02-11 15:49:55 +01001529 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001530 struct lysp_action *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1531 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1532
Radek Krejcifc11bd72019-04-11 16:00:05 +02001533 struct lysc_ext_instance *input_exts; /**< list of the extension instances of input ([sized array](@ref sizedarrays)) */
1534 struct lysc_ext_instance *output_exts; /**< list of the extension instances of outpu ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001535
Radek Krejci056d0a82018-12-06 16:57:25 +01001536 const char *name; /**< action/RPC name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001537 const char *dsc; /**< description */
1538 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001539 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1540 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1541
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001542 struct lysc_action_inout input; /**< RPC's/action's input */
1543 struct lysc_action_inout output; /**< RPC's/action's output */
Michal Vaskoceab6dd2020-10-09 16:53:36 +02001544 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001545 void *priv; /** private arbitrary user data, not used by libyang */
1546
Radek Krejci056d0a82018-12-06 16:57:25 +01001547};
1548
1549struct lysc_notif {
1550 uint16_t nodetype; /**< LYS_NOTIF */
1551 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001552 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejci95710c92019-02-11 15:49:55 +01001553 struct lys_module *module; /**< module structure */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001554 struct lysp_notif *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001555 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1556
Radek Krejcifc11bd72019-04-11 16:00:05 +02001557 struct lysc_node *data; /**< first child node (linked list) */
1558 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1559
Radek Krejci056d0a82018-12-06 16:57:25 +01001560 const char *name; /**< Notification name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001561 const char *dsc; /**< description */
1562 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001563 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1564 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Michal Vaskoceab6dd2020-10-09 16:53:36 +02001565 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001566 void *priv; /** private arbitrary user data, not used by libyang */
Radek Krejci056d0a82018-12-06 16:57:25 +01001567};
1568
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001569/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001570 * @brief Compiled YANG data node
1571 */
1572struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001573 uint16_t nodetype; /**< type of the node (mandatory) */
1574 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001575 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001576 struct lys_module *module; /**< module structure */
Michal Vaskocc048b22020-03-27 15:52:38 +01001577 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or
1578 in case of implicit case node. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001579 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1580 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1581 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1582 never NULL. If there is no sibling node, pointer points to the node
1583 itself. In case of the first node, this pointer points to the last
1584 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001585 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001586 const char *dsc; /**< description */
1587 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001588 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001589 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001590 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001591 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001592};
1593
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001594struct lysc_node_container {
1595 uint16_t nodetype; /**< LYS_CONTAINER */
1596 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001597 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001598 struct lys_module *module; /**< module structure */
1599 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1600 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1601 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1602 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1603 never NULL. If there is no sibling node, pointer points to the node
1604 itself. In case of the first node, this pointer points to the last
1605 node in the list. */
1606 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001607 const char *dsc; /**< description */
1608 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001609 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001610 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001611 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001612 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001613
1614 struct lysc_node *child; /**< first child node (linked list) */
1615 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1616 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1617 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001618};
1619
Radek Krejcia3045382018-11-22 14:30:31 +01001620struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001621 uint16_t nodetype; /**< LYS_CASE */
1622 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001623 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
Radek Krejci056d0a82018-12-06 16:57:25 +01001624 struct lys_module *module; /**< module structure */
1625 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1626 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1627 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1628 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1629 never NULL. If there is no sibling node, pointer points to the node
1630 itself. In case of the first node, this pointer points to the last
1631 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001632 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001633 const char *dsc; /**< description */
1634 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001635 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001636 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001637 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001638 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci056d0a82018-12-06 16:57:25 +01001639
Radek Krejcia3045382018-11-22 14:30:31 +01001640 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 +01001641 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001642};
1643
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001644struct lysc_node_choice {
1645 uint16_t nodetype; /**< LYS_CHOICE */
1646 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001647 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001648 struct lys_module *module; /**< module structure */
1649 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1650 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1651 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1652 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1653 never NULL. If there is no sibling node, pointer points to the node
1654 itself. In case of the first node, this pointer points to the last
1655 node in the list. */
1656 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001657 const char *dsc; /**< description */
1658 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001659 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001660 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001661 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001662 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001663
Radek Krejcia9026eb2018-12-12 16:04:47 +01001664 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1665 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1666 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001667 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001668};
1669
1670struct lysc_node_leaf {
1671 uint16_t nodetype; /**< LYS_LEAF */
1672 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001673 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001674 struct lys_module *module; /**< module structure */
1675 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1676 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1677 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1678 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1679 never NULL. If there is no sibling node, pointer points to the node
1680 itself. In case of the first node, this pointer points to the last
1681 node in the list. */
1682 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001683 const char *dsc; /**< description */
1684 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001685 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001686 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001687 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001688 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001689
1690 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1691 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001692
Radek Krejci4f28eda2018-11-12 11:46:16 +01001693 const char *units; /**< units of the leaf's type */
Radek Krejcia1911222019-07-22 17:24:50 +02001694 struct lyd_value *dflt; /**< default value */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001695};
1696
1697struct lysc_node_leaflist {
1698 uint16_t nodetype; /**< LYS_LEAFLIST */
1699 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001700 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001701 struct lys_module *module; /**< module structure */
1702 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1703 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1704 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1705 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1706 never NULL. If there is no sibling node, pointer points to the node
1707 itself. In case of the first node, this pointer points to the last
1708 node in the list. */
1709 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001710 const char *dsc; /**< description */
1711 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001712 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001713 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001714 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001715 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001716
1717 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1718 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1719
Radek Krejci0e5d8382018-11-28 16:37:53 +01001720 const char *units; /**< units of the leaf's type */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001721 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values */
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001722
Radek Krejci0e5d8382018-11-28 16:37:53 +01001723 uint32_t min; /**< min-elements constraint */
1724 uint32_t max; /**< max-elements constraint */
1725
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001726};
1727
1728struct lysc_node_list {
1729 uint16_t nodetype; /**< LYS_LIST */
1730 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001731 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001732 struct lys_module *module; /**< module structure */
1733 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1734 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1735 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1736 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1737 never NULL. If there is no sibling node, pointer points to the node
1738 itself. In case of the first node, this pointer points to the last
1739 node in the list. */
1740 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001741 const char *dsc; /**< description */
1742 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001743 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001744 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001745 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001746 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001747
1748 struct lysc_node *child; /**< first child node (linked list) */
1749 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1750 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1751 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1752
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001753 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1754 uint32_t min; /**< min-elements constraint */
1755 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001756};
1757
1758struct lysc_node_anydata {
1759 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1760 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001761 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001762 struct lys_module *module; /**< module structure */
1763 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1764 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1765 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1766 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1767 never NULL. If there is no sibling node, pointer points to the node
1768 itself. In case of the first node, this pointer points to the last
1769 node in the list. */
1770 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001771 const char *dsc; /**< description */
1772 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001773 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001774 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001775 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001776 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci9800fb82018-12-13 14:26:23 +01001777
1778 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001779};
1780
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001781/**
1782 * @brief Compiled YANG schema tree structure representing YANG module.
1783 *
1784 * Semantically validated YANG schema tree for data tree parsing.
1785 * Contains only the necessary information for the data validation.
1786 */
1787struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001788 struct lys_module *mod; /**< covering module structure */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001789
Radek Krejci2a408df2018-10-29 16:32:26 +01001790 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1791 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1792 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001793 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001794};
1795
1796/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001797 * @brief Get the groupings sized array of the given (parsed) schema node.
1798 * Decides the node's type and in case it has a groupings array, returns it.
1799 * @param[in] node Node to examine.
1800 * @return The node's groupings sized array if any, NULL otherwise.
1801 */
1802const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1803
1804/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001805 * @brief Get the typedefs sized array of the given (parsed) schema node.
1806 * Decides the node's type and in case it has a typedefs array, returns it.
1807 * @param[in] node Node to examine.
1808 * @return The node's typedefs sized array if any, NULL otherwise.
1809 */
1810const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1811
1812/**
1813 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1814 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1815 * @param[in] node Node to examine.
1816 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1817 */
1818const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1819
1820/**
1821 * @brief Get the Notifications sized array of the given (parsed) schema node.
1822 * Decides the node's type and in case it has a Notifications array, returns it.
1823 * @param[in] node Node to examine.
1824 * @return The node's Notifications sized array if any, NULL otherwise.
1825 */
1826const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1827
1828/**
1829 * @brief Get the children linked list of the given (parsed) schema node.
1830 * Decides the node's type and in case it has a children list, returns it.
1831 * @param[in] node Node to examine.
1832 * @return The node's children linked list if any, NULL otherwise.
1833 */
1834const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1835
1836/**
1837 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1838 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1839 * @param[in] node Node to examine.
1840 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1841 */
1842const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1843
1844/**
1845 * @brief Get the Notifications sized array of the given (compiled) schema node.
1846 * Decides the node's type and in case it has a Notifications array, returns it.
1847 * @param[in] node Node to examine.
1848 * @return The node's Notifications sized array if any, NULL otherwise.
1849 */
1850const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1851
1852/**
1853 * @brief Get the children linked list of the given (compiled) schema node.
Michal Vasko208a04a2020-10-21 15:17:12 +02001854 * Skips over input and output nodes. To return them, use ::lysc_node_children_full().
Michal Vasko2a668712020-10-21 11:48:09 +02001855 *
Radek Krejci056d0a82018-12-06 16:57:25 +01001856 * @param[in] node Node to examine.
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001857 * @param[in] flags Config flag to distinguish input (LYS_CONFIG_W) and output (LYS_CONFIG_R) data in case of RPC/action node.
Radek Krejci056d0a82018-12-06 16:57:25 +01001858 * @return The node's children linked list if any, NULL otherwise.
1859 */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001860const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Radek Krejci056d0a82018-12-06 16:57:25 +01001861
1862/**
Michal Vasko2a668712020-10-21 11:48:09 +02001863 * @brief Get the children linked list of the given (compiled) schema node.
Michal Vasko208a04a2020-10-21 15:17:12 +02001864 * Returns all children node types including input and output. To skip them, use ::lysc_node_children().
Michal Vasko2a668712020-10-21 11:48:09 +02001865 *
1866 * @param[in] node Node to examine.
1867 * @param[in] flags Config flag to distinguish input (LYS_CONFIG_W) and output (LYS_CONFIG_R) child in case of RPC/action node.
1868 * @return Children linked list if any,
1869 * @return NULL otherwise.
1870 */
Michal Vasko208a04a2020-10-21 15:17:12 +02001871const struct lysc_node *lysc_node_children_full(const struct lysc_node *node, uint16_t flags);
Michal Vasko2a668712020-10-21 11:48:09 +02001872
1873/**
1874 * @brief Get the parent pointer from any type of (compiled) schema node.
Michal Vasko208a04a2020-10-21 15:17:12 +02001875 * Returns input or output for direct descendants of RPC/action nodes.
1876 * To skip them, use ::lysc_node.parent pointer directly.
Michal Vasko2a668712020-10-21 11:48:09 +02001877 *
1878 * @param[in] node Node whose parent to get.
1879 * @return Node parent.
1880 * @return NULL is there is none.
1881 */
Michal Vasko208a04a2020-10-21 15:17:12 +02001882const struct lysc_node *lysc_node_parent_full(const struct lysc_node *node);
Michal Vasko2a668712020-10-21 11:48:09 +02001883
1884/**
Michal Vaskod975f862020-06-23 13:29:28 +02001885 * @brief Examine whether a node is user-ordered list or leaf-list.
1886 *
Radek Krejci8678fa42020-08-18 16:07:28 +02001887 * @param[in] schema Schema node to examine.
Michal Vaskod975f862020-06-23 13:29:28 +02001888 * @return non-zero if it is,
Radek Krejci857189e2020-09-01 13:26:36 +02001889 * @return Boolean value whether the @p node is user-ordered or not.
Michal Vaskod975f862020-06-23 13:29:28 +02001890 */
Radek Krejci857189e2020-09-01 13:26:36 +02001891ly_bool lysc_is_userordered(const struct lysc_node *schema);
Michal Vaskod975f862020-06-23 13:29:28 +02001892
1893/**
Michal Vasko2fd91b92020-07-17 16:39:02 +02001894 * @brief Set a schema private pointer to a user pointer.
1895 *
1896 * @param[in] node Node, whose private field will be assigned. Works also for RPCs, actions, and notifications.
1897 * @param[in] priv Arbitrary user-specified pointer.
Radek Krejciaf9cd802020-10-06 21:59:47 +02001898 * @param[out] prev_priv_p Optional previous private object of the \p node. Note, that
Michal Vasko2fd91b92020-07-17 16:39:02 +02001899 * the caller is in this case responsible (if it is necessary) for freeing the replaced private object.
1900 * @return LY_ERR value.
1901 */
Radek Krejciaf9cd802020-10-06 21:59:47 +02001902LY_ERR lysc_set_private(const struct lysc_node *node, void *priv, void **prev_priv_p);
Michal Vasko2fd91b92020-07-17 16:39:02 +02001903
1904/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001905 * @brief Get how the if-feature statement currently evaluates.
1906 *
1907 * @param[in] iff Compiled if-feature statement to evaluate.
Michal Vasko28d78432020-05-26 13:10:53 +02001908 * @return LY_SUCCESS if the statement evaluates to true,
1909 * @return LY_ENOT if it evaluates to false,
1910 * @return LY_ERR on error.
Radek Krejci151a5b72018-10-19 14:21:44 +02001911 */
Michal Vasko28d78432020-05-26 13:10:53 +02001912LY_ERR lysc_iffeature_value(const struct lysc_iffeature *iff);
Radek Krejci151a5b72018-10-19 14:21:44 +02001913
1914/**
1915 * @brief Get the current status of the provided feature.
1916 *
1917 * @param[in] feature Compiled feature statement to examine.
Michal Vasko28d78432020-05-26 13:10:53 +02001918 * @return LY_SUCCESS if feature is enabled,
1919 * @return LY_ENOT if feature is disabled,
1920 * @return LY_ERR in case of error (invalid argument)
Radek Krejci151a5b72018-10-19 14:21:44 +02001921 */
Michal Vasko28d78432020-05-26 13:10:53 +02001922LY_ERR lysc_feature_value(const struct lysc_feature *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001923
Radek Krejcibed13942020-10-19 16:06:28 +02001924/**
1925 * @defgroup findxpathoptions Atomize XPath options
1926 * Options to modify behavior of ::lys_find_xpath() and ::lys_find_xpath_atoms() searching for schema nodes in schema tree.
1927 * @{
1928 */
1929#define LYS_FIND_XP_SCHEMA 0x04 /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */
1930#define LYS_FIND_XP_OUTPUT 0x08 /**< Search RPC/action output nodes instead of input ones. */
1931/*
1932 * }@
1933 */
Michal Vasko072de482020-08-05 13:27:21 +02001934
Radek Krejci151a5b72018-10-19 14:21:44 +02001935/**
Michal Vasko40308e72020-10-20 16:38:40 +02001936 * @brief Get all the schema nodes that are required for @p xpath to be evaluated (atoms).
Michal Vasko519fd602020-05-26 12:17:39 +02001937 *
1938 * @param[in] ctx_node XPath schema context node.
Michal Vasko40308e72020-10-20 16:38:40 +02001939 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_PREF_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02001940 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko519fd602020-05-26 12:17:39 +02001941 * @param[out] set Set of found atoms (schema nodes).
1942 * @return LY_SUCCESS on success, @p set is returned.
Michal Vasko40308e72020-10-20 16:38:40 +02001943 * @return LY_ERR value on error.
Michal Vasko519fd602020-05-26 12:17:39 +02001944 */
Radek Krejcibed13942020-10-19 16:06:28 +02001945LY_ERR lys_find_xpath_atoms(const struct lysc_node *ctx_node, const char *xpath, uint32_t options, struct ly_set **set);
Michal Vasko519fd602020-05-26 12:17:39 +02001946
Michal Vasko072de482020-08-05 13:27:21 +02001947/**
Michal Vasko40308e72020-10-20 16:38:40 +02001948 * @brief Get all the schema nodes that are required for @p path to be evaluated (atoms).
1949 *
1950 * @param[in] path Compiled path to use.
1951 * @param[out] set Set of found atoms (schema nodes).
1952 * @return LY_SUCCESS on success, @p set is returned.
1953 * @return LY_ERR value on error.
1954 */
1955LY_ERR lys_find_path_atoms(const struct ly_path *path, struct ly_set **set);
1956
1957/**
1958 * @brief Get all the schema nodes that are required for @p expr to be evaluated (atoms).
Michal Vasko072de482020-08-05 13:27:21 +02001959 *
1960 * @param[in] ctx_node XPath schema context node.
Michal Vasko40308e72020-10-20 16:38:40 +02001961 * @param[in] cur_mod Current module for the expression (where it was "instantiated").
1962 * @param[in] expr Parsed expression to use.
1963 * @param[in] prefixes Sized array of compiled prefixes.
1964 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
1965 * @param[out] set Set of found atoms (schema nodes).
1966 * @return LY_SUCCESS on success, @p set is returned.
1967 * @return LY_ERR value on error.
1968 */
1969LY_ERR lys_find_expr_atoms(const struct lysc_node *ctx_node, const struct lys_module *cur_mod,
1970 const struct lyxp_expr *expr, const struct lysc_prefix *prefixes, uint32_t options, struct ly_set **set);
1971
1972/**
1973 * @brief Evaluate an @p xpath expression on schema nodes.
1974 *
1975 * @param[in] ctx_node XPath schema context node.
1976 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_PREF_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02001977 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko072de482020-08-05 13:27:21 +02001978 * @param[out] set Set of found schema nodes.
1979 * @return LY_SUCCESS on success, @p set is returned.
1980 * @return LY_ERR value if an error occurred.
1981 */
Radek Krejci1deb5be2020-08-26 16:43:36 +02001982LY_ERR lys_find_xpath(const struct lysc_node *ctx_node, const char *xpath, uint32_t options, struct ly_set **set);
Michal Vasko519fd602020-05-26 12:17:39 +02001983
1984/**
Michal Vasko03ff5a72019-09-11 13:49:33 +02001985 * @brief Types of the different schema paths.
1986 */
1987typedef enum {
Michal Vasko65de0402020-08-03 16:34:19 +02001988 LYSC_PATH_LOG, /**< Descriptive path format used in log messages */
1989 LYSC_PATH_DATA /**< Similar to ::LYSC_PATH_LOG except that schema-only nodes (choice, case) are skipped */
Michal Vasko03ff5a72019-09-11 13:49:33 +02001990} LYSC_PATH_TYPE;
1991
1992/**
Radek Krejci327de162019-06-14 12:52:07 +02001993 * @brief Generate path of the given node in the requested format.
1994 *
1995 * @param[in] node Schema path of this node will be generated.
1996 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001997 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
1998 * If NULL, memory for the complete path is allocated.
1999 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02002000 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02002001 * 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 +02002002 */
Michal Vasko03ff5a72019-09-11 13:49:33 +02002003char *lysc_path(const struct lysc_node *node, LYSC_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02002004
2005/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002006 * @brief Available YANG schema tree structures representing YANG module.
2007 */
2008struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002009 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
2010 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01002011 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002012 const char *ns; /**< namespace of the module (module - mandatory) */
2013 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
2014 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
2015 const char *org; /**< party/company responsible for the module */
2016 const char *contact; /**< contact information for the module */
2017 const char *dsc; /**< description of the module */
2018 const char *ref; /**< cross-reference for the module */
2019
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002020 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01002021 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
2022 Available only for implemented modules. */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002023
Radek Krejci14915cc2020-09-14 17:28:13 +02002024 struct lysc_feature *features; /**< List of compiled features of the module ([sized array](@ref sizedarrays)).
2025 Features are outside the compiled tree since they are needed even the module is not
2026 compiled. In such a case, the features are always disabled and cannot be enabled until
2027 the module is implemented. The features are present in this form to allow their linkage
Radek Krejci0af46292019-01-11 16:02:31 +01002028 from if-feature statements of the compiled schemas and their proper use in case
2029 the module became implemented in future (no matter if implicitly via augment/deviate
Radek Krejci14915cc2020-09-14 17:28:13 +02002030 or explicitly via ::lys_set_implemented()). */
Radek Krejci80d281e2020-09-14 17:42:54 +02002031 struct lysc_ident *identities; /**< List of compiled identities of the module ([sized array](@ref sizedarrays))
2032 Identities are outside the compiled tree to allow their linkage to the identities from
2033 the implemented modules. This avoids problems when the module became implemented in
2034 future (no matter if implicitly via augment/deviate or explicitly via
2035 ::lys_set_implemented()). Note that if the module is not implemented (compiled), the
2036 identities cannot be instantiated in data (in identityrefs). */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002037
2038 struct lys_module **augmented_by;/**< List of modules that augment this module ([sized array](@ref sizedarrays)) */
2039 struct lys_module **deviated_by; /**< List of modules that deviate this module ([sized array](@ref sizedarrays)) */
2040
Michal Vasko89b5c072020-10-06 13:52:44 +02002041 ly_bool implemented; /**< flag if the module is implemented, not just imported */
Radek Krejci95710c92019-02-11 15:49:55 +01002042 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002043 1 - the latest revision in searchdirs was not searched yet and this is the
2044 latest revision in the current context
2045 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002046};
2047
Radek Krejci151a5b72018-10-19 14:21:44 +02002048/**
2049 * @brief Enable specified feature in the module
2050 *
2051 * By default, when the module is loaded by libyang parser, all features are disabled.
2052 *
Radek Krejcica3db002018-11-01 10:31:01 +01002053 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
2054 * enabling all features on the following feature set will fail since it is not possible to enable both features
2055 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
2056 * is untouched.
2057 *
2058 * feature f1;
2059 * feature f2 { if-feature 'not f1';}
2060 *
Radek Krejci151a5b72018-10-19 14:21:44 +02002061 * @param[in] module Module where the feature will be enabled.
2062 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
Michal Vasko82c31e62020-07-17 15:30:40 +02002063 * @return LY_SUCCESS on success,
2064 * @return LY_EINVAL if @p module is not implemented,
2065 * @return LY_ENOTFOUND if @p feature was not found,
2066 * @return LY_EDENIED if @p feature could not be enabled because it has some false if-feature statements.
Radek Krejci151a5b72018-10-19 14:21:44 +02002067 */
Radek Krejcied5acc52019-04-25 15:57:04 +02002068LY_ERR lys_feature_enable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02002069
2070/**
2071 * @brief Disable specified feature in the module
2072 *
2073 * By default, when the module is loaded by libyang parser, all features are disabled.
2074 *
Michal Vasko82c31e62020-07-17 15:30:40 +02002075 * If disabling a feature causes some other features that depend on this feature to become disabled.
2076 *
Radek Krejci151a5b72018-10-19 14:21:44 +02002077 * @param[in] module Module where the feature will be disabled.
2078 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
Michal Vasko82c31e62020-07-17 15:30:40 +02002079 * @return LY_SUCCESS on success,
2080 * @return LY_EINVAL if @p module is not implemented,
2081 * @return LY_ENOTFOUND if @p feature was not found.
Radek Krejci151a5b72018-10-19 14:21:44 +02002082 */
Radek Krejcied5acc52019-04-25 15:57:04 +02002083LY_ERR lys_feature_disable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02002084
2085/**
Michal Vasko82c31e62020-07-17 15:30:40 +02002086 * @brief Enable specified feature in the module disregarding its if-features.
2087 *
2088 * @param[in] module Module where the feature will be enabled.
2089 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk character.
2090 * @return LY_SUCCESS on success,
2091 * @return LY_EINVAL if @p module is not implemented,
2092 * @return LY_ENOTFOUND if @p feature was not found.
2093 */
2094LY_ERR lys_feature_enable_force(const struct lys_module *module, const char *feature);
2095
2096/**
2097 * @brief Disable specified feature in the module disregarding dependant features.
2098 *
2099 * By default, when the module is loaded by libyang parser, all features are disabled.
2100 *
2101 * @param[in] module Module where the feature will be disabled.
2102 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk character.
2103 * @return LY_SUCCESS on success,
2104 * @return LY_EINVAL if @p module is not implemented,
2105 * @return LY_ENOTFOUND if @p feature was not found.
2106 */
2107LY_ERR lys_feature_disable_force(const struct lys_module *module, const char *feature);
2108
2109/**
2110 * @brief Get the current real status of the specified feature in the module.
2111 *
2112 * If the feature is enabled, but some of its if-features are false, the feature is considered
2113 * disabled.
Radek Krejci151a5b72018-10-19 14:21:44 +02002114 *
2115 * @param[in] module Module where the feature is defined.
2116 * @param[in] feature Name of the feature to inspect.
Michal Vasko82c31e62020-07-17 15:30:40 +02002117 * @return LY_SUCCESS if the feature is enabled,
2118 * @return LY_ENOT if the feature is disabled,
2119 * @return LY_ENOTFOUND if the feature was not found.
Radek Krejci151a5b72018-10-19 14:21:44 +02002120 */
Michal Vasko82c31e62020-07-17 15:30:40 +02002121LY_ERR lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02002122
2123/**
Radek Krejcia3045382018-11-22 14:30:31 +01002124 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
2125 * be from an augment.
2126 *
Radek Krejci8678fa42020-08-18 16:07:28 +02002127 * ::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 +01002128 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
2129 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
2130 * \p parent and \p module parameters.
2131 *
2132 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
2133 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
2134 * all the schema nodes are iteratively returned.
2135 *
2136 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
2137 * @param[in] parent Parent of the subtree where the function starts processing.
2138 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
2139 * module must be specified.
2140 * @param[in] options [ORed options](@ref sgetnextflags).
2141 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
2142 */
2143const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002144 const struct lysc_module *module, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002145
2146/**
Radek Krejci8678fa42020-08-18 16:07:28 +02002147 * @defgroup sgetnextflags Options for ::lys_getnext().
2148 *
2149 * Various options setting behavior of ::lys_getnext().
2150 *
Radek Krejcia3045382018-11-22 14:30:31 +01002151 * @{
2152 */
Radek Krejci8678fa42020-08-18 16:07:28 +02002153#define LYS_GETNEXT_WITHCHOICE 0x01 /**< ::lys_getnext() option to allow returning #LYS_CHOICE nodes instead of looking into them */
2154#define LYS_GETNEXT_NOCHOICE 0x02 /**< ::lys_getnext() option to ignore (kind of conditional) nodes within choice node */
2155#define LYS_GETNEXT_WITHCASE 0x04 /**< ::lys_getnext() option to allow returning #LYS_CASE nodes instead of looking into them */
2156#define LYS_GETNEXT_INTONPCONT 0x40 /**< ::lys_getnext() option to look into non-presence container, instead of returning container itself */
2157#define LYS_GETNEXT_NOSTATECHECK 0x100 /**< ::lys_getnext() option to skip checking module validity (import-only, disabled) and
Radek Krejcia3045382018-11-22 14:30:31 +01002158 relevant if-feature conditions state */
Radek Krejci8678fa42020-08-18 16:07:28 +02002159#define LYS_GETNEXT_OUTPUT 0x200 /**< ::lys_getnext() option to provide RPC's/action's output schema nodes instead of input schema nodes
Radek Krejci6eeb58f2019-02-22 16:29:37 +01002160 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01002161/** @} sgetnextflags */
2162
2163/**
2164 * @brief Get child node according to the specified criteria.
2165 *
2166 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
2167 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
2168 * @param[in] name Name of the node to find.
2169 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
2170 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
2171 * Used as a bitmask, so multiple nodetypes can be specified.
2172 * @param[in] options [ORed options](@ref sgetnextflags).
2173 * @return Found node if any.
2174 */
Michal Vaskoe444f752020-02-10 12:20:06 +01002175const struct lysc_node *lys_find_child(const struct lysc_node *parent, const struct lys_module *module,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002176 const char *name, size_t name_len, uint16_t nodetype, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002177
2178/**
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002179 * @brief Make the specific module implemented.
2180 *
2181 * @param[in] mod Module to make implemented. It is not an error
2182 * to provide already implemented module, it just does nothing.
Michal Vaskoe444f752020-02-10 12:20:06 +01002183 * @return LY_SUCCESS on success.
2184 * @return LY_EDENIED in case the context contains some other revision of the same module which is already implemented.
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002185 */
2186LY_ERR lys_set_implemented(struct lys_module *mod);
2187
2188/**
Radek Krejcia3045382018-11-22 14:30:31 +01002189 * @brief Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statement
2190 * affecting the node.
2191 *
2192 * @param[in] node Schema node to check.
2193 * @param[in] recursive - 0 to check if-feature only in the \p node schema node,
2194 * - 1 to check if-feature in all ascendant schema nodes until there is a node possibly having an instance in a data tree
Michal Vaskoe444f752020-02-10 12:20:06 +01002195 * @return NULL if enabled,
Michal Vaskoc193ce92020-03-06 11:04:48 +01002196 * @return pointer to the node with the unsatisfied (disabled) if-feature expression.
Radek Krejcia3045382018-11-22 14:30:31 +01002197 */
Radek Krejci857189e2020-09-01 13:26:36 +02002198const struct lysc_node *lysc_node_is_disabled(const struct lysc_node *node, ly_bool recursive);
Radek Krejcia3045382018-11-22 14:30:31 +01002199
Radek Krejci084289f2019-07-09 17:35:30 +02002200/**
2201 * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
2202 *
2203 * 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 +02002204 * require-instance restriction), use ::lyd_value_validate().
Radek Krejci084289f2019-07-09 17:35:30 +02002205 *
2206 * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
2207 * @param[in] node Schema node for the @p value.
Michal Vaskof937cfe2020-08-03 16:07:12 +02002208 * @param[in] value String value to be checked, expected to be in JSON format.
Radek Krejci084289f2019-07-09 17:35:30 +02002209 * @param[in] value_len Length of the given @p value (mandatory).
Radek Krejci084289f2019-07-09 17:35:30 +02002210 * @return LY_SUCCESS on success
2211 * @return LY_ERR value if an error occurred.
2212 */
Michal Vaskof937cfe2020-08-03 16:07:12 +02002213LY_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 +02002214
Radek Krejci0935f412019-08-20 16:15:18 +02002215/**
2216 * @brief Stringify schema nodetype.
Michal Vaskod43d71a2020-08-07 14:54:58 +02002217 *
Radek Krejci0935f412019-08-20 16:15:18 +02002218 * @param[in] nodetype Nodetype to stringify.
2219 * @return Constant string with the name of the node's type.
2220 */
2221const char *lys_nodetype2str(uint16_t nodetype);
2222
Michal Vaskod43d71a2020-08-07 14:54:58 +02002223/**
2224 * @brief Getter for original XPath expression from a parsed expression.
2225 *
2226 * @param[in] path Parsed expression.
2227 * @return Original string expression.
2228 */
2229const char *lyxp_get_expr(const struct lyxp_expr *path);
2230
Radek Krejci2ff0d572020-05-21 15:27:28 +02002231/** @} schematree */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002232
Radek Krejci70853c52018-10-15 14:46:16 +02002233#ifdef __cplusplus
2234}
2235#endif
2236
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002237#endif /* LY_TREE_SCHEMA_H_ */