blob: fc19147d7fa9f7f299c00bdee65ed0b856272e90 [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 *
Radek Krejcib100b192020-10-26 08:37:45 +010058 * By default, the module is implemented (and compiled) in case it is explicitly loaded or referenced in another module as
59 * target of leafref, augment or deviation. This behavior can be changed via context options ::LY_CTX_ALL_IMPLEMENTED, when
60 * all the modules in the context are marked as implemented (note the problem with multiple revisions of a single module),
61 * or by ::LY_CTX_REF_IMPLEMENTED option, extending the set of references making the module implemented by when, must and
62 * default statements.
Radek Krejci8678fa42020-08-18 16:07:28 +020063 *
64 * All modules with deviation definition are always marked as implemented. The imported (not implemented) module can be set implemented by ::lys_set_implemented(). But
65 * the implemented module cannot be changed back to just imported module. Note also that only one revision of a specific module
66 * can be implemented in a single context. The imported modules are used only as a
67 * source of definitions for types and groupings for uses statements. The data in such modules are ignored - caller
68 * is not allowed to create the data (including instantiating identities) defined in the model via data parsers,
69 * the default nodes are not added into any data tree and mandatory nodes are not checked in the data trees.
70 *
71 * The compiled schema tree nodes are able to hold private objects (::lysc_node.priv as a pointer to a structure, function, variable, ...) used by
72 * a caller application. Such an object can be assigned to a specific node using ::lysc_set_private() function.
73 * Note that the object is not freed by libyang when the context is being destroyed. So the caller is responsible
74 * for freeing the provided structure after the context is destroyed or the private pointer is set to NULL in
75 * appropriate schema nodes where the object was previously set. This can be automated via destructor function
76 * to free these private objects. The destructor is passed to the ::ly_ctx_destroy() function.
77 *
78 * Despite all the schema structures and their members are available as part of the libyang API and callers can use
79 * it to navigate through the schema tree structure or to obtain various information, we recommend to use the following
80 * macros for the specific actions.
81 * - ::LYSC_TREE_DFS_BEGIN and ::LYSC_TREE_DFS_END to traverse the schema tree (depth-first).
82 * - ::LY_LIST_FOR and ::LY_ARRAY_FOR as described on @ref howtoStructures page.
83 *
84 * Further information about modules handling can be found on the following pages:
85 * - @subpage howtoSchemaParsers
86 * - @subpage howtoSchemaFeatures
87 * - @subpage howtoPlugins
88 * - @subpage howtoSchemaPrinters
89 *
90 * \note There are many functions to access information from the schema trees. Details are available in
91 * the [Schema Tree module](@ref schematree).
92 *
93 * For information about difference between implemented and imported modules, see the
94 * [context description](@ref howtoContext).
95 *
96 * Functions List (not assigned to above subsections)
97 * --------------------------------------------------
98 * - ::lys_getnext()
99 * - ::lys_nodetype2str()
100 * - ::lys_set_implemented()
101 * - ::lys_value_validate()
102 *
103 * - ::lysc_set_private()
104 *
105 * - ::lysc_node_children()
Michal Vasko208a04a2020-10-21 15:17:12 +0200106 * - ::lysc_node_children_full()
107 * - ::lysc_node_parent_full()
Radek Krejci8678fa42020-08-18 16:07:28 +0200108 * - ::lysc_node_actions()
109 * - ::lysc_node_notifs()
110 *
111 * - ::lysp_node_children()
112 * - ::lysp_node_actions()
113 * - ::lysp_node_notifs()
114 * - ::lysp_node_groupings()
115 * - ::lysp_node_typedefs()
116 */
117
118/**
119 * @page howtoSchemaFeatures YANG Features
120 *
Radek Krejcia8c71e62020-10-26 08:30:50 +0100121 * YANG feature statement is an important part of the language which can significantly affect the meaning of the schemas. Despite
Radek Krejci8678fa42020-08-18 16:07:28 +0200122 * the features have similar effect as loading/removing schema from the context, manipulating with the feature value is not
123 * limited to the context preparation period before working with data. YANG features, respectively their use in if-feature
124 * statements, are evaluated as part of the [data validation process](@ref howtoDataValidation).
125 *
126 * The main functions with *lys_feature_* prefix are used to change the value (true/false) of the feature and to get its current
127 * value. Enabling/disabling all the features in a particular module can be done using '`*`' value instead of the feature name.
128 *
129 * There are two options to reflect feature's if-feature statements when enabling/disabling the feature. The ::lys_feature_enable()
130 * and ::lys_feature_disable() functions check their if-feature expressions (it is not possible to enable feature if it is not
131 * allowed by its if-feature expressions) and also checks for and update other features those if-feature expressions use the
132 * changed feature. On the contrary, ::lys_feature_enable_force() and ::lys_feature_disable_force() ignore all the if-feature
133 * limitations.
134 *
135 * The ::lysc_feature_value() and ::lys_feature_value() functions differ only by their parameters. The ::lysc_iffeature_value()
136 * is used to evaluate (possibly complex in YANG 1.1) logical expression from if-feature statement.
137 *
138 * The list of features of a particular YANG module is available in ::lys_module.features.
139 *
140 * To get know, if a specific schema node is currently disabled or enable, the ::lysc_node_is_disabled() function can be used.
141 *
142 * Note, that the feature's state can affect some of the output formats (e.g. Tree format).
143 *
144 * Functions List
145 * --------------
146 * - ::lys_feature_enable()
147 * - ::lys_feature_enable_force()
148 * - ::lys_feature_disable()
149 * - ::lys_feature_disable_force()
150 * - ::lys_feature_value()
151 * - ::lysc_feature_value()
152 * - ::lysc_iffeature_value()
153 *
154 * - ::lysc_node_is_disabled()
155 */
156
157/**
Radek Krejci2ff0d572020-05-21 15:27:28 +0200158 * @ingroup trees
Radek Krejci8678fa42020-08-18 16:07:28 +0200159 * @defgroup schematree Schema Tree
Radek Krejci2ff0d572020-05-21 15:27:28 +0200160 * @{
161 *
162 * Data structures and functions to manipulate and access schema tree.
163 */
164
Michal Vasko64246d82020-08-19 12:35:00 +0200165/* *INDENT-OFF* */
166
Radek Krejci2ff0d572020-05-21 15:27:28 +0200167/**
Michal Vasko208a04a2020-10-21 15:17:12 +0200168 * @brief Macro to iterate via all elements in a schema (sub)tree including input and output.
169 * Note that __actions__ and __notifications__ of traversed nodes __are ignored__! To traverse
170 * on all the nodes including those, use ::lysc_tree_dfs_full() instead.
171 *
172 * 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 +0200173 *
174 * The function follows deep-first search algorithm:
175 * <pre>
176 * 1
177 * / \
178 * 2 4
179 * / / \
180 * 3 5 6
181 * </pre>
182 *
183 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
184 * START can be any of the lysc_node* types (including lysc_action and lysc_notif),
185 * ELEM variable must be of the struct lysc_node* type.
186 *
187 * To skip a particular subtree, instead of the continue statement, set LYSC_TREE_DFS_continue
188 * variable to non-zero value.
189 *
190 * Use with opening curly bracket '{' after the macro.
191 *
192 * @param START Pointer to the starting element processed first.
193 * @param ELEM Iterator intended for use in the block.
194 */
195#define LYSC_TREE_DFS_BEGIN(START, ELEM) \
Radek Krejci857189e2020-09-01 13:26:36 +0200196 { ly_bool LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
Michal Vasko1c9e79f2020-08-10 11:08:03 +0200197 for ((ELEM) = (LYSC_TREE_DFS_next) = (struct lysc_node*)(START); \
Radek Krejci0935f412019-08-20 16:15:18 +0200198 (ELEM); \
199 (ELEM) = (LYSC_TREE_DFS_next), LYSC_TREE_DFS_continue = 0)
200
201/**
202 * @brief Macro to iterate via all elements in a (sub)tree. This is the closing part
203 * to the #LYSC_TREE_DFS_BEGIN - they always have to be used together.
204 *
205 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
206 * START can be a pointer to any of the lysc_node* types (including lysc_action and lysc_notif),
207 * ELEM variable must be pointer to the lysc_node type.
208 *
209 * Use with closing curly bracket '}' after the macro.
210 *
211 * @param START Pointer to the starting element processed first.
212 * @param ELEM Iterator intended for use in the block.
213 */
Radek Krejci0935f412019-08-20 16:15:18 +0200214#define LYSC_TREE_DFS_END(START, ELEM) \
215 /* select element for the next run - children first */ \
216 if (LYSC_TREE_DFS_continue) { \
217 (LYSC_TREE_DFS_next) = NULL; \
218 } else { \
Michal Vasko208a04a2020-10-21 15:17:12 +0200219 (LYSC_TREE_DFS_next) = (struct lysc_node *)lysc_node_children_full(ELEM, 0); \
220 } \
Radek Krejci0935f412019-08-20 16:15:18 +0200221 if (!(LYSC_TREE_DFS_next)) { \
Michal Vasko208a04a2020-10-21 15:17:12 +0200222 /* no children, try siblings */ \
223 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
Radek Krejci0935f412019-08-20 16:15:18 +0200224 } \
225 while (!(LYSC_TREE_DFS_next)) { \
226 /* parent is already processed, go to its sibling */ \
Michal Vasko208a04a2020-10-21 15:17:12 +0200227 (ELEM) = (struct lysc_node *)lysc_node_parent_full(ELEM); \
228 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
229 } }
230
231/**
232 * @brief Helper macro for #LYSC_TREE_DFS_END, should not be used directly!
233 */
234#define _LYSC_TREE_DFS_NEXT(START, ELEM, NEXT) \
235 if ((ELEM) == (struct lysc_node *)(START)) { \
236 /* we are done, no next element to process */ \
237 break; \
238 } \
239 if ((ELEM)->nodetype == LYS_INPUT) { \
240 /* after input, get output */ \
241 (NEXT) = (struct lysc_node *)lysc_node_children_full(lysc_node_parent_full(ELEM), LYS_CONFIG_R); \
242 } else if ((ELEM)->nodetype == LYS_OUTPUT) { \
243 /* no sibling of output */ \
244 (NEXT) = NULL; \
245 } else { \
246 (NEXT) = (ELEM)->next; \
247 }
Radek Krejci0935f412019-08-20 16:15:18 +0200248
Michal Vasko64246d82020-08-19 12:35:00 +0200249/* *INDENT-ON* */
250
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200251#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
252
Michal Vasko7f45cf22020-10-01 12:49:44 +0200253#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
254#define LYS_CONTAINER 0x0001 /**< container statement node */
255#define LYS_CHOICE 0x0002 /**< choice statement node */
256#define LYS_LEAF 0x0004 /**< leaf statement node */
257#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
258#define LYS_LIST 0x0010 /**< list statement node */
259#define LYS_ANYXML 0x0020 /**< anyxml statement node */
260#define LYS_ANYDATA 0x0060 /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
261#define LYS_CASE 0x0080 /**< case statement node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200262
Michal Vasko7f45cf22020-10-01 12:49:44 +0200263#define LYS_RPC 0x0100 /**< RPC statement node */
264#define LYS_ACTION 0x0200 /**< action statement node */
265#define LYS_NOTIF 0x0400 /**< notification statement node */
Radek Krejcie7b95092019-05-15 11:03:07 +0200266
Michal Vasko7f45cf22020-10-01 12:49:44 +0200267#define LYS_USES 0x0800 /**< uses statement node */
268#define LYS_INPUT 0x1000 /**< RPC/action input node */
269#define LYS_OUTPUT 0x2000 /**< RPC/action output node */
270#define LYS_GROUPING 0x4000
271#define LYS_AUGMENT 0x8000
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100272
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200273/**
Radek Krejcid6b76452019-09-03 17:03:03 +0200274 * @brief List of YANG statements
275 */
276enum ly_stmt {
277 LY_STMT_NONE = 0,
Radek Krejci8678fa42020-08-18 16:07:28 +0200278 LY_STMT_STATUS, /**< in ::lysc_ext_substmt.storage stored as a pointer to `uint16_t`, only cardinality < #LY_STMT_CARD_SOME is allowed */
279 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 +0200280 LY_STMT_MANDATORY,
Radek Krejci8678fa42020-08-18 16:07:28 +0200281 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 +0200282 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200283 LY_STMT_DEFAULT,
Radek Krejci8678fa42020-08-18 16:07:28 +0200284 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 +0200285 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_type **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200286
Radek Krejcid6b76452019-09-03 17:03:03 +0200287 LY_STMT_ACTION,
288 LY_STMT_ANYDATA,
289 LY_STMT_ANYXML,
290 LY_STMT_ARGUMENT,
291 LY_STMT_AUGMENT,
292 LY_STMT_BASE,
293 LY_STMT_BELONGS_TO,
294 LY_STMT_BIT,
295 LY_STMT_CASE,
296 LY_STMT_CHOICE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200297 LY_STMT_CONTACT,
298 LY_STMT_CONTAINER,
Radek Krejcid6b76452019-09-03 17:03:03 +0200299 LY_STMT_DESCRIPTION,
300 LY_STMT_DEVIATE,
301 LY_STMT_DEVIATION,
302 LY_STMT_ENUM,
303 LY_STMT_ERROR_APP_TAG,
304 LY_STMT_ERROR_MESSAGE,
305 LY_STMT_EXTENSION,
306 LY_STMT_FEATURE,
307 LY_STMT_FRACTION_DIGITS,
308 LY_STMT_GROUPING,
309 LY_STMT_IDENTITY,
Radek Krejci8678fa42020-08-18 16:07:28 +0200310 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 +0200311 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_iffeature *` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200312 LY_STMT_IMPORT,
313 LY_STMT_INCLUDE,
314 LY_STMT_INPUT,
315 LY_STMT_KEY,
316 LY_STMT_LEAF,
317 LY_STMT_LEAF_LIST,
318 LY_STMT_LENGTH,
319 LY_STMT_LIST,
Radek Krejcid6b76452019-09-03 17:03:03 +0200320 LY_STMT_MAX_ELEMENTS,
321 LY_STMT_MIN_ELEMENTS,
322 LY_STMT_MODIFIER,
323 LY_STMT_MODULE,
324 LY_STMT_MUST,
325 LY_STMT_NAMESPACE,
326 LY_STMT_NOTIFICATION,
327 LY_STMT_ORDERED_BY,
328 LY_STMT_ORGANIZATION,
329 LY_STMT_OUTPUT,
330 LY_STMT_PATH,
331 LY_STMT_PATTERN,
332 LY_STMT_POSITION,
333 LY_STMT_PREFIX,
334 LY_STMT_PRESENCE,
335 LY_STMT_RANGE,
336 LY_STMT_REFERENCE,
337 LY_STMT_REFINE,
338 LY_STMT_REQUIRE_INSTANCE,
339 LY_STMT_REVISION,
340 LY_STMT_REVISION_DATE,
341 LY_STMT_RPC,
Radek Krejcid6b76452019-09-03 17:03:03 +0200342 LY_STMT_SUBMODULE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200343 LY_STMT_TYPEDEF,
344 LY_STMT_UNIQUE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200345 LY_STMT_USES,
346 LY_STMT_VALUE,
347 LY_STMT_WHEN,
348 LY_STMT_YANG_VERSION,
349 LY_STMT_YIN_ELEMENT,
350 LY_STMT_EXTENSION_INSTANCE,
351
352 LY_STMT_SYNTAX_SEMICOLON,
353 LY_STMT_SYNTAX_LEFT_BRACE,
354 LY_STMT_SYNTAX_RIGHT_BRACE,
355
356 LY_STMT_ARG_TEXT,
357 LY_STMT_ARG_VALUE
358};
359
360/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200361 * @brief Extension instance structure parent enumeration
362 */
363typedef enum {
Radek Krejci0935f412019-08-20 16:15:18 +0200364 LYEXT_PAR_MODULE, /**< ::lysc_module */
365 LYEXT_PAR_NODE, /**< ::lysc_node (and the derived structures including ::lysc_action and ::lysc_notif) */
366 LYEXT_PAR_INPUT, /**< ::lysc_action_inout */
367 LYEXT_PAR_OUTPUT, /**< ::lysc_action_inout */
368 LYEXT_PAR_TYPE, /**< ::lysc_type */
369 LYEXT_PAR_TYPE_BIT, /**< ::lysc_type_bitenum_item */
370 LYEXT_PAR_TYPE_ENUM, /**< ::lysc_type_bitenum_item */
371 LYEXT_PAR_FEATURE, /**< ::lysc_feature */
372 LYEXT_PAR_MUST, /**< ::lysc_must */
373 LYEXT_PAR_PATTERN, /**< ::lysc_pattern */
374 LYEXT_PAR_LENGTH, /**< ::lysc_range */
375 LYEXT_PAR_RANGE, /**< ::lysc_range */
376 LYEXT_PAR_WHEN, /**< ::lysc_when */
377 LYEXT_PAR_IDENT, /**< ::lysc_ident */
378 LYEXT_PAR_EXT, /**< ::lysc_ext */
Michal Vasko69730152020-10-09 16:30:07 +0200379 LYEXT_PAR_IMPORT /**< ::lysp_import */
Michal Vasko033278d2020-08-24 11:24:52 +0200380// LYEXT_PAR_TPDF, /**< ::lysp_tpdf */
381// LYEXT_PAR_EXTINST, /**< ::lysp_ext_instance */
382// LYEXT_PAR_REFINE, /**< ::lysp_refine */
383// LYEXT_PAR_DEVIATION, /**< ::lysp_deviation */
384// LYEXT_PAR_DEVIATE, /**< ::lysp_deviate */
385// LYEXT_PAR_INCLUDE, /**< ::lysp_include */
386// LYEXT_PAR_REVISION, /**< ::lysp_revision */
Radek Krejci0e59c312019-08-15 15:34:15 +0200387} LYEXT_PARENT;
388
389/**
Radek Krejci0935f412019-08-20 16:15:18 +0200390 * @brief Stringify extension instance parent type.
391 * @param[in] type Parent type to stringify.
392 * @return Constant string with the name of the parent statement.
393 */
394const char *lyext_parent2str(LYEXT_PARENT type);
395
396/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200397 * @brief Enum of substatements in which extension instances can appear.
398 */
399typedef enum {
400 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
401 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
402 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
403 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
404 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
405 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
406 lys_node_choice and lys_deviate */
407 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
408 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
409 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
410 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
411 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
412 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
413 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
414 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
415 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
416 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
417 belongs-to's prefix) and lys_import */
418 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
419 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
420 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
421 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
422 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
423 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
424 lys_node_leaflist and lys_deviate */
425 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
426 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
427 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
428 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
429 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
430 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
431 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
432 lys_node_anydata and lys_deviate */
433 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
434 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
435 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
436 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
437 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
438 lys_node_leaflist and lys_deviate */
439 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
440 lys_node_leaflist and lys_deviate */
441 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
442 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
Michal Vasko69730152020-10-09 16:30:07 +0200443 LYEXT_SUBSTMT_IFFEATURE /**< extension of the if-feature statement */
Radek Krejci0e59c312019-08-15 15:34:15 +0200444} LYEXT_SUBSTMT;
445
446/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200447 * @brief YANG import-stmt
448 */
449struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200450 struct lys_module *module; /**< pointer to the imported module
451 (mandatory, but resolved when the referring module is completely parsed) */
452 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200453 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200454 const char *dsc; /**< description */
455 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200456 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200457 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
458};
459
460/**
461 * @brief YANG include-stmt
462 */
463struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100464 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200465 (mandatory, but resolved when the referring module is completely parsed) */
466 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200467 const char *dsc; /**< description */
468 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200469 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200470 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
471};
472
473/**
474 * @brief YANG extension-stmt
475 */
476struct lysp_ext {
477 const char *name; /**< extension name */
478 const char *argument; /**< argument name, NULL if not specified */
479 const char *dsc; /**< description statement */
480 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200481 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200482 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */
Michal Vasko5fe75f12020-03-02 13:52:37 +0100483
484 struct lysc_ext *compiled; /**< pointer to the compiled extension definition */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200485};
486
487/**
488 * @brief Helper structure for generic storage of the extension instances content.
489 */
490struct lysp_stmt {
491 const char *stmt; /**< identifier of the statement */
492 const char *arg; /**< statement's argument */
493 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200494 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
David Sedlákb9d75c42019-08-14 10:49:42 +0200495 uint16_t flags; /**< statement flags, can be set to LYS_YIN_ATTR */
Radek Krejci335332a2019-09-05 13:03:35 +0200496 enum ly_stmt kw; /**< numeric respresentation of the stmt value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200497};
498
David Sedlákae4b4512019-08-14 10:45:56 +0200499#define LYS_YIN 0x1 /**< used to specify input format of extension instance */
500
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200501/**
502 * @brief YANG extension instance
503 */
504struct lysp_ext_instance {
David Sedlákbbd06ca2019-06-27 14:15:38 +0200505 const char *name; /**< extension identifier, including possible prefix */
506 const char *argument; /**< optional value of the extension's argument */
Radek Krejci335332a2019-09-05 13:03:35 +0200507 void *parent; /**< pointer to the parent element holding the extension instance(s), use
508 ::lysp_ext_instance#parent_type to access the schema element */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200509 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200510 struct lysc_ext_instance *compiled; /**< pointer to the compiled data if any - in case the source format is YIN,
511 some of the information (argument) are available only after compilation */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200512 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200513 LY_ARRAY_COUNT_TYPE insubstmt_index; /**< in case the instance is in a substatement, this identifies
David Sedlákbbd06ca2019-06-27 14:15:38 +0200514 the index of that substatement */
David Sedlákae4b4512019-08-14 10:45:56 +0200515 uint8_t yin; /** flag for YIN source format, can be set to LYS_YIN */
Radek Krejci335332a2019-09-05 13:03:35 +0200516 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200517};
518
519/**
520 * @brief YANG feature-stmt
521 */
522struct lysp_feature {
523 const char *name; /**< feature name (mandatory) */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200524 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200525 const char *dsc; /**< description statement */
526 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200527 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200528 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
529};
530
531/**
Michal Vasko7f45cf22020-10-01 12:49:44 +0200532 * @brief Qualified name (optional prefix followed by an identifier).
533 */
534struct lysp_qname {
535 const char *str; /**< qualified name string */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200536 const struct lysp_module *mod; /**< module to resolve any prefixes found in the string, it must be
Michal Vasko7f45cf22020-10-01 12:49:44 +0200537 stored explicitly because of deviations/refines */
538};
539
540/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200541 * @brief YANG identity-stmt
542 */
543struct lysp_ident {
544 const char *name; /**< identity name (mandatory), including possible prefix */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200545 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200546 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200547 const char *dsc; /**< description statement */
548 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200549 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200550 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
551};
552
Michal Vasko71e64ca2018-09-07 16:30:29 +0200553/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200554 * @brief Covers restrictions: range, length, pattern, must
555 */
556struct lysp_restr {
Michal Vasko7f45cf22020-10-01 12:49:44 +0200557 struct lysp_qname arg; /**< The restriction expression/value (mandatory);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200558 in case of pattern restriction, the first byte has a special meaning:
559 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
560 const char *emsg; /**< error-message */
561 const char *eapptag; /**< error-app-tag value */
562 const char *dsc; /**< description */
563 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200564 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200565};
566
567/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200568 * @brief YANG revision-stmt
569 */
570struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200571 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200572 const char *dsc; /**< description statement */
573 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200574 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200575};
576
577/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200578 * @brief Enumeration/Bit value definition
579 */
580struct lysp_type_enum {
581 const char *name; /**< name (mandatory) */
582 const char *dsc; /**< description statement */
583 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200584 int64_t value; /**< enum's value or bit's position */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200585 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200586 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200587 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
588 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200589};
590
591/**
592 * @brief YANG type-stmt
593 *
594 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
595 */
596struct lysp_type {
597 const char *name; /**< name of the type (mandatory) */
598 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
599 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200600 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
601 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
602 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Michal Vasko004d3152020-06-11 19:59:22 +0200603 struct lyxp_expr *path; /**< parsed path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200604 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200605 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
606 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200607
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200608 const struct lysp_module *pmod; /**< (sub)module where the type is defined (needed for deviations) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100609 struct lysc_type *compiled; /**< pointer to the compiled type */
610
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200611 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
612 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100613 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200614};
615
616/**
617 * @brief YANG typedef-stmt
618 */
619struct lysp_tpdf {
620 const char *name; /**< name of the newly defined type (mandatory) */
621 const char *units; /**< units of the newly defined type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200622 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 +0200623 const char *dsc; /**< description statement */
624 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200625 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200626 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100627 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200628};
629
630/**
631 * @brief YANG grouping-stmt
632 */
633struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100634 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
635 uint16_t nodetype; /**< LYS_GROUPING */
636 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200637 const char *name; /**< grouping name (mandatory) */
638 const char *dsc; /**< description statement */
639 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200640 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
641 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200642 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200643 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
644 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
645 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200646};
647
648/**
649 * @brief YANG when-stmt
650 */
651struct lysp_when {
652 const char *cond; /**< specified condition (mandatory) */
653 const char *dsc; /**< description statement */
654 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200655 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200656};
657
658/**
659 * @brief YANG refine-stmt
660 */
661struct lysp_refine {
662 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
663 const char *dsc; /**< description statement */
664 const char *ref; /**< reference statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200665 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200666 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200667 const char *presence; /**< presence description */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200668 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200669 uint32_t min; /**< min-elements constraint */
670 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200671 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200672 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
673};
674
675/**
Michal Vasko82a83432019-11-14 12:33:04 +0100676 * @brief YANG uses-augment-stmt and augment-stmt (compatible with struct lysp_node )
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200677 */
678struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100679 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
680 uint16_t nodetype; /**< LYS_AUGMENT */
681 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Michal Vasko82a83432019-11-14 12:33:04 +0100682 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200683 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
684 const char *dsc; /**< description statement */
685 const char *ref; /**< reference statement */
686 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200687 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Michal Vasko82a83432019-11-14 12:33:04 +0100688 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200689 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
690 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200691};
692
693/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200694 * @ingroup schematree
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200695 * @defgroup deviatetypes Deviate types
Radek Krejci8678fa42020-08-18 16:07:28 +0200696 *
697 * Type of the deviate operation (used as ::lysp_deviate.mod)
698 *
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200699 * @{
700 */
701#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
702#define LYS_DEV_ADD 2 /**< deviate type add */
703#define LYS_DEV_DELETE 3 /**< deviate type delete */
704#define LYS_DEV_REPLACE 4 /**< deviate type replace */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200705/** @} deviatetypes */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200706
707/**
708 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
709 */
710struct lysp_deviate {
711 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
712 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200713 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200714};
715
716struct lysp_deviate_add {
717 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
718 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200719 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200720 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200721 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200722 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
723 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200724 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
725 uint32_t min; /**< min-elements constraint */
726 uint32_t max; /**< max-elements constraint, 0 means unbounded */
727};
728
729struct lysp_deviate_del {
730 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
731 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200732 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200733 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200734 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200735 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
736 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200737};
738
739struct lysp_deviate_rpl {
740 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
741 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200742 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200743 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200744 const char *units; /**< units of the values */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200745 struct lysp_qname dflt; /**< default value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200746 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
747 uint32_t min; /**< min-elements constraint */
748 uint32_t max; /**< max-elements constraint, 0 means unbounded */
749};
750
751struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200752 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200753 const char *dsc; /**< description statement */
754 const char *ref; /**< reference statement */
Michal Vasko22df3f02020-08-24 13:29:22 +0200755 struct lysp_deviate *deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200756 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200757};
758
Radek Krejci4f28eda2018-11-12 11:46:16 +0100759/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100760 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200761 * @defgroup spnodeflags Parsed schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100762 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200763 * Various flags for parsed schema nodes (used as ::lysp_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100764 *
765 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
766 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200767 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100768 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
769 * 5 - list 10 - input 15 - typedef 20 - deviate
770 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200771 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
772 * 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
773 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200774 * 1 LYS_CONFIG_W |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200775 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
776 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200777 * 2 LYS_CONFIG_R |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200778 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
779 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
780 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
781 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
782 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
783 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
784 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
785 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
786 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
787 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
788 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
789 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
790 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
791 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
792 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
793 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
794 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
795 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
796 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
797 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
798 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
799 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
800 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
801 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
802 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
803 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
804 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
805 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
806 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
807 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
808 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
809 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200810 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
David Sedlákae4b4512019-08-14 10:45:56 +0200811 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x|
Michal Vasko5297a432020-08-31 12:27:51 +0200812 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
813 * 12 LYS_YIN_ARGUMENT | | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejcif56e2a42019-09-09 14:15:25 +0200814 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100815 *
816 */
817
818/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100819 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200820 * @defgroup scnodeflags Compiled schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100821 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200822 * Various flags for compiled schema nodes (used as ::lysc_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100823 *
Radek Krejci61e042e2019-09-10 15:53:09 +0200824 * 1 - container 6 - anydata/anyxml 11 - identity
825 * 2 - choice 7 - case 12 - extension
826 * 3 - leaf 8 - notification 13 - bitenum
Michal Vasko03ff5a72019-09-11 13:49:33 +0200827 * 4 - leaflist 9 - rpc/action 14 - when
Michal Vaskoecd62de2019-11-13 12:35:11 +0100828 * 5 - list 10 - feature
Radek Krejci4f28eda2018-11-12 11:46:16 +0100829 *
Michal Vaskoecd62de2019-11-13 12:35:11 +0100830 * 1 1 1 1 1
831 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
832 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
833 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | |
834 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
835 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | |
836 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
837 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x|x|x|x| |x|
838 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
839 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x|x|x|x| |x|
840 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
841 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x|x|x|x| |x|
842 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
843 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
844 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
845 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
846 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | |
847 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
848 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
849 * LYS_PRESENCE |x| | | | | | | | | | | | | |
850 * LYS_UNIQUE | | |x| | | | | | | | | | | |
851 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
852 * 9 LYS_KEY | | |x| | | | | | | | | | | |
853 * LYS_FENABLED | | | | | | | | | |x| | | | |
854 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
855 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
856 * LYS_ISENUM | | | | | | | | | | | | |x| |
857 * LYS_KEYLESS | | | | |x| | | | | | | | | |
858 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
859 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
860 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
861 * 12 LYS_SET_CONFIG |x|x|x|x|x|x| | | | | | | | |
862 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100863 *
864 */
865
866/**
867 * @defgroup snodeflags Schema nodes flags
Radek Krejci8678fa42020-08-18 16:07:28 +0200868 *
869 * Various flags for schema nodes ([parsed](@ref spnodeflags) as well as [compiled](@ref scnodeflags)).
870 *
Radek Krejci4f28eda2018-11-12 11:46:16 +0100871 * @{
872 */
Michal Vasko1bf09392020-03-27 12:38:10 +0100873#define LYS_CONFIG_W 0x01 /**< config true; also set for input children nodes */
874#define LYS_CONFIG_R 0x02 /**< config false; also set for output and notification children nodes */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200875#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100876#define LYS_STATUS_CURR 0x04 /**< status current; */
877#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
878#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
879#define LYS_STATUS_MASK 0x1C /**< mask for status value */
880#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100881 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
882 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
883 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
884 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100885#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
886 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
887 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100888#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Michal Vaskoc118ae22020-08-06 14:51:09 +0200889#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, but it is not only for explicit presence
890 containers, but also for NP containers with some meaning, applicable only to
891 ::lysc_node_container */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100892#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
893#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 +0200894#define LYS_KEYLESS 0x200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Radek Krejci8678fa42020-08-18 16:07:28 +0200895#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysc_feature.
896 Do not interpret presence of this flag as enabled feature! Also if-feature statements
897 are supposed to be taken into account, so use ::lys_feature_value() or
898 ::lysc_feature_value() to get know if a specific feature is really enabled. */
Radek Krejcife909632019-02-12 15:34:42 +0100899#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 +0100900 ::lysc_node_list/::lysp_node_list */
901#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
902 ::lysc_node_list/::lysp_node_list */
903#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
904#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
905#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
906#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200907#define LYS_USED_GRP 0x400 /**< internal flag for validating not-instantiated groupings
908 (resp. do not validate again the instantiated groupings). */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100909#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100910#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200911#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100912
913#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
914#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
915#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
916#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
917#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
918#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
919#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
920#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
921#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
922#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100923#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 +0100924 cases of choice. This information is important for refines, since it is prohibited to make leafs
925 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100926 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
927 between own default or the default values taken from the type. */
928#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 +0100929#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 +0100930
Radek Krejcif56e2a42019-09-09 14:15:25 +0200931#define LYS_SINGLEQUOTED 0x100 /**< flag for single-quoted argument of an extension instance's substatement, only when the source is YANG */
932#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 +0200933
Radek Krejcif56e2a42019-09-09 14:15:25 +0200934#define LYS_YIN_ATTR 0x400 /**< flag to identify YIN attribute parsed as extension's substatement, only when the source is YIN */
935#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 +0200936
Radek Krejci693262f2019-04-29 15:23:20 +0200937#define LYS_ISENUM 0x200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
938
Radek Krejcife909632019-02-12 15:34:42 +0100939#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200940/** @} snodeflags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200941
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200942/**
943 * @brief Generic YANG data node
944 */
945struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100946 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200947 uint16_t nodetype; /**< type of the node (mandatory) */
948 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100949 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200950 const char *name; /**< node name (mandatory) */
951 const char *dsc; /**< description statement */
952 const char *ref; /**< reference statement */
953 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200954 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)),
955 must be qname because of refines */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200956 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200957};
958
959/**
960 * @brief Extension structure of the lysp_node for YANG container
961 */
962struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100963 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200964 uint16_t nodetype; /**< LYS_CONTAINER */
965 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
966 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
967 const char *name; /**< node name (mandatory) */
968 const char *dsc; /**< description statement */
969 const char *ref; /**< reference statement */
970 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200971 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200972 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200973
974 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200975 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200976 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200977 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
978 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200979 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200980 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
981 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200982};
983
984struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100985 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200986 uint16_t nodetype; /**< LYS_LEAF */
987 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
988 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
989 const char *name; /**< node name (mandatory) */
990 const char *dsc; /**< description statement */
991 const char *ref; /**< reference statement */
992 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200993 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200994 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200995
996 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200997 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200998 struct lysp_type type; /**< type of the leaf node (mandatory) */
999 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001000 struct lysp_qname dflt; /**< default value, it may or may not be a qualified name */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001001};
1002
1003struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001004 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001005 uint16_t nodetype; /**< LYS_LEAFLIST */
1006 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1007 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1008 const char *name; /**< node name (mandatory) */
1009 const char *dsc; /**< description statement */
1010 const char *ref; /**< reference statement */
1011 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001012 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001013 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001014
1015 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001016 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001017 struct lysp_type type; /**< type of the leaf node (mandatory) */
1018 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001019 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)), they may or
1020 may not be qualified names */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001021 uint32_t min; /**< min-elements constraint */
1022 uint32_t max; /**< max-elements constraint, 0 means unbounded */
1023};
1024
1025struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001026 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001027 uint16_t nodetype; /**< LYS_LIST */
1028 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1029 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1030 const char *name; /**< node name (mandatory) */
1031 const char *dsc; /**< description statement */
1032 const char *ref; /**< reference statement */
1033 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001034 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001035 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001036
1037 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001038 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001039 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001040 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1041 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001042 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001043 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1044 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001045 struct lysp_qname *uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001046 uint32_t min; /**< min-elements constraint */
1047 uint32_t max; /**< max-elements constraint, 0 means unbounded */
1048};
1049
1050struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001051 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001052 uint16_t nodetype; /**< LYS_CHOICE */
1053 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1054 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1055 const char *name; /**< node name (mandatory) */
1056 const char *dsc; /**< description statement */
1057 const char *ref; /**< reference statement */
1058 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001059 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001060 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001061
1062 /* choice */
1063 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001064 struct lysp_qname dflt; /**< default case */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001065};
1066
1067struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001068 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001069 uint16_t nodetype; /**< LYS_CASE */
1070 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1071 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1072 const char *name; /**< node name (mandatory) */
1073 const char *dsc; /**< description statement */
1074 const char *ref; /**< reference statement */
1075 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001076 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001077 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001078
1079 /* case */
1080 struct lysp_node *child; /**< list of data nodes (linked list) */
1081};
1082
1083struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001084 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001085 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001086 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1087 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1088 const char *name; /**< node name (mandatory) */
1089 const char *dsc; /**< description statement */
1090 const char *ref; /**< reference statement */
1091 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001092 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001093 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001094
1095 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001096 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001097};
1098
1099struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001100 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +02001101 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001102 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1103 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1104 const char *name; /**< grouping name reference (mandatory) */
1105 const char *dsc; /**< description statement */
1106 const char *ref; /**< reference statement */
1107 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001108 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001109 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001110
1111 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001112 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
1113 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001114};
1115
1116/**
1117 * @brief YANG input-stmt and output-stmt
1118 */
1119struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001120 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001121 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001122 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1123 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1124 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001125 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001126 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001127};
1128
1129/**
1130 * @brief YANG rpc-stmt and action-stmt
1131 */
1132struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001133 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko1bf09392020-03-27 12:38:10 +01001134 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001135 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001136 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001137 const char *name; /**< grouping name reference (mandatory) */
1138 const char *dsc; /**< description statement */
1139 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001140 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001141 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1142 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1143
1144 /* action */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001145 struct lysp_action_inout input; /**< RPC's/Action's input */
1146 struct lysp_action_inout output; /**< RPC's/Action's output */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001147};
1148
1149/**
1150 * @brief YANG notification-stmt
1151 */
1152struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001153 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1154 uint16_t nodetype; /**< LYS_NOTIF */
1155 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001156 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001157 const char *name; /**< grouping name reference (mandatory) */
1158 const char *dsc; /**< description statement */
1159 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001160 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001161 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001162 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001163
1164 /* notif */
1165 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1166 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001167};
1168
1169/**
Radek Krejcif0fceb62018-09-05 14:58:45 +02001170 * @brief supported YANG schema version values
1171 */
1172typedef enum LYS_VERSION {
1173 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
Radek Krejci96e48da2020-09-04 13:18:06 +02001174 LYS_VERSION_1_0 = 1, /**< YANG 1 (1.0) */
Radek Krejcif0fceb62018-09-05 14:58:45 +02001175 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
1176} LYS_VERSION;
1177
1178/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001179 * @brief Printable YANG schema tree structure representing YANG module.
1180 *
1181 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
1182 */
1183struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001184 struct lys_module *mod; /**< covering module structure */
1185
Radek Krejcib7db73a2018-10-24 14:18:40 +02001186 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1187 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001188 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1189 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001190 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1191 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1192 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1193 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1194 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001195 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001196 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1197 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1198 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1199 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001200 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001201
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001202 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001203 uint8_t parsing : 1; /**< flag for circular check */
1204 uint8_t is_submod : 1; /**< always 0 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001205};
1206
1207struct lysp_submodule {
Michal Vaskoc3781c32020-10-06 14:04:08 +02001208 struct lys_module *mod; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001209
1210 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1211 in the list is always the last (newest) revision of the module */
1212 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1213 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
1214 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1215 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1216 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1217 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1218 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
1219 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
1220 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1221 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1222 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1223 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001224 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001225
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001226 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001227 uint8_t parsing : 1; /**< flag for circular check */
1228 uint8_t is_submod : 1; /**< always 1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001229
Michal Vaskoc3781c32020-10-06 14:04:08 +02001230 uint8_t latest_revision : 2; /**< flag to mark the latest available revision:
Radek Krejci086c7132018-10-26 15:29:04 +02001231 1 - the latest revision in searchdirs was not searched yet and this is the
1232 latest revision in the current context
1233 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001234 const char *name; /**< name of the module (mandatory) */
1235 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1236 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
1237 const char *org; /**< party/company responsible for the module */
1238 const char *contact; /**< contact information for the module */
1239 const char *dsc; /**< description of the module */
1240 const char *ref; /**< cross-reference for the module */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001241};
1242
1243/**
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001244 * @brief Get the parsed module or submodule name.
1245 *
1246 * @param[in] PMOD Parsed module or submodule.
1247 * @return Module or submodule name.
1248 */
1249#define LYSP_MODULE_NAME(PMOD) (PMOD->is_submod ? ((struct lysp_submodule *)PMOD)->name : ((struct lysp_module *)PMOD)->mod->name)
1250
1251/**
1252 * @brief Free the printable YANG schema tree structure. Works for both modules and submodules.
Radek Krejci3f5e3db2018-10-11 15:57:47 +02001253 *
1254 * @param[in] module Printable YANG schema tree structure to free.
1255 */
1256void lysp_module_free(struct lysp_module *module);
1257
1258/**
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001259 * @brief Compiled prefix data pair mapping of prefixes to modules. In case the format is ::LY_PREF_SCHEMA_RESOLVED,
1260 * the expected prefix data is a sized array of these structures.
1261 */
1262struct lysc_prefix {
1263 char *prefix; /**< used prefix */
1264 const struct lys_module *mod; /**< mapping to a module */
1265};
1266
1267/**
Radek Krejci0e59c312019-08-15 15:34:15 +02001268 * @brief Compiled YANG extension-stmt
1269 */
1270struct lysc_ext {
1271 const char *name; /**< extension name */
1272 const char *argument; /**< argument name, NULL if not specified */
Radek Krejci0e59c312019-08-15 15:34:15 +02001273 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1274 struct lyext_plugin *plugin; /**< Plugin implementing the specific extension */
Radek Krejci0935f412019-08-20 16:15:18 +02001275 struct lys_module *module; /**< module structure */
Michal Vasko6f4cbb62020-02-28 11:15:47 +01001276 uint32_t refcount; /**< reference counter since extension definition is shared among all its instances */
Radek Krejci0e59c312019-08-15 15:34:15 +02001277 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
1278};
1279
1280/**
Radek Krejcice8c1592018-10-29 15:35:51 +01001281 * @brief YANG extension instance
1282 */
1283struct lysc_ext_instance {
Radek Krejciad5963b2019-09-06 16:03:05 +02001284 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
1285 this identifies the index of the substatement for this extension instance */
Radek Krejci28681fa2019-09-06 13:08:45 +02001286 struct lys_module *module; /**< module where the extension instantiated is defined */
Radek Krejciad5963b2019-09-06 16:03:05 +02001287 struct lysc_ext *def; /**< pointer to the extension definition */
Radek Krejcice8c1592018-10-29 15:35:51 +01001288 void *parent; /**< pointer to the parent element holding the extension instance(s), use
1289 ::lysc_ext_instance#parent_type to access the schema element */
1290 const char *argument; /**< optional value of the extension's argument */
1291 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +01001292 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001293 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0e59c312019-08-15 15:34:15 +02001294 void *data; /**< private plugins's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +01001295};
1296
1297/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001298 * @brief Compiled YANG if-feature-stmt
1299 */
1300struct lysc_iffeature {
1301 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
1302 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
1303};
1304
1305/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001306 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001307 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001308struct lysc_when {
1309 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko175012e2019-11-06 15:49:14 +01001310 struct lysc_node *context; /**< context node for evaluating the expression, NULL if the context is root node */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001311 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001312 const char *dsc; /**< description */
1313 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001314 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001315 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Michal Vaskoecd62de2019-11-13 12:35:11 +01001316 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS is allowed */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001317};
1318
1319/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001320 * @brief YANG identity-stmt
1321 */
1322struct lysc_ident {
1323 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +01001324 const char *dsc; /**< description */
1325 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001326 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001327 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
1328 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001329 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001330 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1331};
1332
1333/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001334 * @brief YANG feature-stmt
1335 */
1336struct lysc_feature {
1337 const char *name; /**< feature name (mandatory) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001338 const char *dsc; /**< description */
1339 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001340 struct lys_module *module; /**< module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001341 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 +01001342 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001343 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001344 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
1345 #LYS_FENABLED values allowed */
1346};
1347
Radek Krejci151a5b72018-10-19 14:21:44 +02001348/**
1349 * @defgroup ifftokens if-feature expression tokens
Radek Krejci8678fa42020-08-18 16:07:28 +02001350 * Tokens of if-feature expression used in ::lysc_iffeature.expr.
Radek Krejci151a5b72018-10-19 14:21:44 +02001351 *
1352 * @{
1353 */
1354#define LYS_IFF_NOT 0x00 /**< operand "not" */
1355#define LYS_IFF_AND 0x01 /**< operand "and" */
1356#define LYS_IFF_OR 0x02 /**< operand "or" */
1357#define LYS_IFF_F 0x03 /**< feature */
Radek Krejci2ff0d572020-05-21 15:27:28 +02001358/** @} ifftokens */
Radek Krejci151a5b72018-10-19 14:21:44 +02001359
1360/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001361 * @brief Compiled YANG revision statement
1362 */
1363struct lysc_revision {
1364 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1365 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1366};
1367
Radek Krejci2167ee12018-11-02 16:09:07 +01001368struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001369 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001370 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001371 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1372 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001373 };
Radek Krejci693262f2019-04-29 15:23:20 +02001374 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001375 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1376 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001377 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001378 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001379 const char *dsc; /**< description */
1380 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001381 const char *emsg; /**< error-message */
1382 const char *eapptag; /**< error-app-tag value */
1383 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1384};
1385
1386struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001387 const char *expr; /**< original, not compiled, regular expression */
1388 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001389 const char *dsc; /**< description */
1390 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001391 const char *emsg; /**< error-message */
1392 const char *eapptag; /**< error-app-tag value */
1393 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0f969882020-08-21 16:56:47 +02001394 uint32_t inverted : 1; /**< invert-match flag */
1395 uint32_t refcount : 31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001396};
1397
1398struct lysc_must {
Radek Krejci2167ee12018-11-02 16:09:07 +01001399 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001400 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001401 const char *dsc; /**< description */
1402 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001403 const char *emsg; /**< error-message */
1404 const char *eapptag; /**< error-app-tag value */
1405 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1406};
1407
1408struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001409 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001410 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001411 LY_DATA_TYPE basetype; /**< Base type of the type */
1412 uint32_t refcount; /**< reference counter for type sharing */
1413};
1414
1415struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001416 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001417 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 +01001418 LY_DATA_TYPE basetype; /**< Base type of the type */
1419 uint32_t refcount; /**< reference counter for type sharing */
1420 struct lysc_range *range; /**< Optional range limitation */
1421};
1422
1423struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001424 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001425 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 +01001426 LY_DATA_TYPE basetype; /**< Base type of the type */
1427 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001428 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001429 struct lysc_range *range; /**< Optional range limitation */
1430};
1431
1432struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001433 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001434 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 +01001435 LY_DATA_TYPE basetype; /**< Base type of the type */
1436 uint32_t refcount; /**< reference counter for type sharing */
1437 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001438 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001439};
1440
Radek Krejci693262f2019-04-29 15:23:20 +02001441struct lysc_type_bitenum_item {
1442 const char *name; /**< enumeration identifier */
1443 const char *dsc; /**< description */
1444 const char *ref; /**< reference */
1445 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1446 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1447 union {
1448 int32_t value; /**< integer value associated with the enumeration */
1449 uint32_t position; /**< non-negative integer value associated with the bit */
1450 };
1451 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1452 values are allowed */
1453};
1454
Radek Krejci2167ee12018-11-02 16:09:07 +01001455struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001456 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001457 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 +01001458 LY_DATA_TYPE basetype; /**< Base type of the type */
1459 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001460 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1461};
1462
1463struct lysc_type_bits {
1464 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001465 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 +02001466 LY_DATA_TYPE basetype; /**< Base type of the type */
1467 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001468 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1469 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001470};
1471
1472struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001473 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001474 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 +01001475 LY_DATA_TYPE basetype; /**< Base type of the type */
1476 uint32_t refcount; /**< reference counter for type sharing */
Michal Vasko004d3152020-06-11 19:59:22 +02001477 struct lyxp_expr *path; /**< parsed target path, compiled path cannot be stored because of type sharing */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001478 struct lysc_prefix *prefixes; /**< resolved prefixes used in the path */
Radek Krejci412ddfa2018-11-23 11:44:11 +01001479 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001480 uint8_t require_instance; /**< require-instance flag */
1481};
1482
1483struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001484 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001485 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 +01001486 LY_DATA_TYPE basetype; /**< Base type of the type */
1487 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001488 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001489 mandatory (at least 1 item) */
1490};
1491
1492struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001493 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001494 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 +01001495 LY_DATA_TYPE basetype; /**< Base type of the type */
1496 uint32_t refcount; /**< reference counter for type sharing */
1497 uint8_t require_instance; /**< require-instance flag */
1498};
1499
Radek Krejci2167ee12018-11-02 16:09:07 +01001500struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001501 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001502 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 +01001503 LY_DATA_TYPE basetype; /**< Base type of the type */
1504 uint32_t refcount; /**< reference counter for type sharing */
1505 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1506};
1507
1508struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001509 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001510 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 +01001511 LY_DATA_TYPE basetype; /**< Base type of the type */
1512 uint32_t refcount; /**< reference counter for type sharing */
1513 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001514};
1515
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001516struct lysc_action_inout {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001517 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001518 struct lysc_node *data; /**< first child node (linked list) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001519 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1520};
1521
Michal Vasko60ea6352020-06-29 13:39:39 +02001522/**
1523 * @brief Maximum number of hashes stored in a schema node.
1524 */
1525#define LYS_NODE_HASH_COUNT 4
1526
Radek Krejci056d0a82018-12-06 16:57:25 +01001527struct lysc_action {
Michal Vasko1bf09392020-03-27 12:38:10 +01001528 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci056d0a82018-12-06 16:57:25 +01001529 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001530 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejci95710c92019-02-11 15:49:55 +01001531 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001532 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1533
Radek Krejcifc11bd72019-04-11 16:00:05 +02001534 struct lysc_ext_instance *input_exts; /**< list of the extension instances of input ([sized array](@ref sizedarrays)) */
1535 struct lysc_ext_instance *output_exts; /**< list of the extension instances of outpu ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001536
Radek Krejci056d0a82018-12-06 16:57:25 +01001537 const char *name; /**< action/RPC name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001538 const char *dsc; /**< description */
1539 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001540 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1541 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1542
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001543 struct lysc_action_inout input; /**< RPC's/action's input */
1544 struct lysc_action_inout output; /**< RPC's/action's output */
Michal Vaskoceab6dd2020-10-09 16:53:36 +02001545 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001546 void *priv; /** private arbitrary user data, not used by libyang */
1547
Radek Krejci056d0a82018-12-06 16:57:25 +01001548};
1549
1550struct lysc_notif {
1551 uint16_t nodetype; /**< LYS_NOTIF */
1552 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001553 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejci95710c92019-02-11 15:49:55 +01001554 struct lys_module *module; /**< module structure */
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 */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001577 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1578 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1579 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1580 never NULL. If there is no sibling node, pointer points to the node
1581 itself. In case of the first node, this pointer points to the last
1582 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001583 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001584 const char *dsc; /**< description */
1585 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001586 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001587 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001588 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001589 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001590};
1591
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001592struct lysc_node_container {
1593 uint16_t nodetype; /**< LYS_CONTAINER */
1594 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001595 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001596 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001597 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1598 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1599 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1600 never NULL. If there is no sibling node, pointer points to the node
1601 itself. In case of the first node, this pointer points to the last
1602 node in the list. */
1603 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001604 const char *dsc; /**< description */
1605 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001606 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001607 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001608 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001609 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001610
1611 struct lysc_node *child; /**< first child node (linked list) */
1612 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1613 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1614 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001615};
1616
Radek Krejcia3045382018-11-22 14:30:31 +01001617struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001618 uint16_t nodetype; /**< LYS_CASE */
1619 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001620 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
Radek Krejci056d0a82018-12-06 16:57:25 +01001621 struct lys_module *module; /**< module structure */
Radek Krejci056d0a82018-12-06 16:57:25 +01001622 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1623 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1624 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1625 never NULL. If there is no sibling node, pointer points to the node
1626 itself. In case of the first node, this pointer points to the last
1627 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001628 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001629 const char *dsc; /**< description */
1630 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001631 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001632 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001633 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001634 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci056d0a82018-12-06 16:57:25 +01001635
Radek Krejcia3045382018-11-22 14:30:31 +01001636 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 +01001637 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001638};
1639
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001640struct lysc_node_choice {
1641 uint16_t nodetype; /**< LYS_CHOICE */
1642 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001643 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001644 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001645 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1646 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1647 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1648 never NULL. If there is no sibling node, pointer points to the node
1649 itself. In case of the first node, this pointer points to the last
1650 node in the list. */
1651 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001652 const char *dsc; /**< description */
1653 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001654 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001655 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001656 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001657 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001658
Radek Krejcia9026eb2018-12-12 16:04:47 +01001659 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1660 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1661 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001662 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001663};
1664
1665struct lysc_node_leaf {
1666 uint16_t nodetype; /**< LYS_LEAF */
1667 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001668 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001669 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001670 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1671 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1672 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1673 never NULL. If there is no sibling node, pointer points to the node
1674 itself. In case of the first node, this pointer points to the last
1675 node in the list. */
1676 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001677 const char *dsc; /**< description */
1678 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001679 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001680 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001681 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001682 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001683
1684 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1685 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001686
Radek Krejci4f28eda2018-11-12 11:46:16 +01001687 const char *units; /**< units of the leaf's type */
Radek Krejcia1911222019-07-22 17:24:50 +02001688 struct lyd_value *dflt; /**< default value */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001689};
1690
1691struct lysc_node_leaflist {
1692 uint16_t nodetype; /**< LYS_LEAFLIST */
1693 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001694 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001695 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001696 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1697 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1698 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1699 never NULL. If there is no sibling node, pointer points to the node
1700 itself. In case of the first node, this pointer points to the last
1701 node in the list. */
1702 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001703 const char *dsc; /**< description */
1704 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001705 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001706 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001707 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001708 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001709
1710 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1711 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1712
Radek Krejci0e5d8382018-11-28 16:37:53 +01001713 const char *units; /**< units of the leaf's type */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001714 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values */
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001715
Radek Krejci0e5d8382018-11-28 16:37:53 +01001716 uint32_t min; /**< min-elements constraint */
1717 uint32_t max; /**< max-elements constraint */
1718
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001719};
1720
1721struct lysc_node_list {
1722 uint16_t nodetype; /**< LYS_LIST */
1723 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001724 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001725 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001726 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1727 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1728 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1729 never NULL. If there is no sibling node, pointer points to the node
1730 itself. In case of the first node, this pointer points to the last
1731 node in the list. */
1732 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001733 const char *dsc; /**< description */
1734 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001735 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001736 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001737 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001738 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001739
1740 struct lysc_node *child; /**< first child node (linked list) */
1741 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1742 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1743 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1744
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001745 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1746 uint32_t min; /**< min-elements constraint */
1747 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001748};
1749
1750struct lysc_node_anydata {
1751 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1752 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001753 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001754 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001755 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1756 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1757 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1758 never NULL. If there is no sibling node, pointer points to the node
1759 itself. In case of the first node, this pointer points to the last
1760 node in the list. */
1761 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001762 const char *dsc; /**< description */
1763 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001764 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001765 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001766 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001767 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci9800fb82018-12-13 14:26:23 +01001768
1769 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001770};
1771
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001772/**
1773 * @brief Compiled YANG schema tree structure representing YANG module.
1774 *
1775 * Semantically validated YANG schema tree for data tree parsing.
1776 * Contains only the necessary information for the data validation.
1777 */
1778struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001779 struct lys_module *mod; /**< covering module structure */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001780
Radek Krejci2a408df2018-10-29 16:32:26 +01001781 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1782 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1783 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001784 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001785};
1786
1787/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001788 * @brief Get the groupings sized array of the given (parsed) schema node.
1789 * Decides the node's type and in case it has a groupings array, returns it.
1790 * @param[in] node Node to examine.
1791 * @return The node's groupings sized array if any, NULL otherwise.
1792 */
1793const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1794
1795/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001796 * @brief Get the typedefs sized array of the given (parsed) schema node.
1797 * Decides the node's type and in case it has a typedefs array, returns it.
1798 * @param[in] node Node to examine.
1799 * @return The node's typedefs sized array if any, NULL otherwise.
1800 */
1801const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1802
1803/**
1804 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1805 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1806 * @param[in] node Node to examine.
1807 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1808 */
1809const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1810
1811/**
1812 * @brief Get the Notifications sized array of the given (parsed) schema node.
1813 * Decides the node's type and in case it has a Notifications array, returns it.
1814 * @param[in] node Node to examine.
1815 * @return The node's Notifications sized array if any, NULL otherwise.
1816 */
1817const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1818
1819/**
1820 * @brief Get the children linked list of the given (parsed) schema node.
1821 * Decides the node's type and in case it has a children list, returns it.
1822 * @param[in] node Node to examine.
1823 * @return The node's children linked list if any, NULL otherwise.
1824 */
1825const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1826
1827/**
1828 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1829 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1830 * @param[in] node Node to examine.
1831 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1832 */
1833const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1834
1835/**
1836 * @brief Get the Notifications sized array of the given (compiled) schema node.
1837 * Decides the node's type and in case it has a Notifications array, returns it.
1838 * @param[in] node Node to examine.
1839 * @return The node's Notifications sized array if any, NULL otherwise.
1840 */
1841const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1842
1843/**
1844 * @brief Get the children linked list of the given (compiled) schema node.
Michal Vasko208a04a2020-10-21 15:17:12 +02001845 * Skips over input and output nodes. To return them, use ::lysc_node_children_full().
Michal Vasko2a668712020-10-21 11:48:09 +02001846 *
Radek Krejci056d0a82018-12-06 16:57:25 +01001847 * @param[in] node Node to examine.
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001848 * @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 +01001849 * @return The node's children linked list if any, NULL otherwise.
1850 */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001851const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Radek Krejci056d0a82018-12-06 16:57:25 +01001852
1853/**
Michal Vasko2a668712020-10-21 11:48:09 +02001854 * @brief Get the children linked list of the given (compiled) schema node.
Michal Vasko208a04a2020-10-21 15:17:12 +02001855 * Returns all children node types including input and output. To skip them, use ::lysc_node_children().
Michal Vasko2a668712020-10-21 11:48:09 +02001856 *
1857 * @param[in] node Node to examine.
1858 * @param[in] flags Config flag to distinguish input (LYS_CONFIG_W) and output (LYS_CONFIG_R) child in case of RPC/action node.
1859 * @return Children linked list if any,
1860 * @return NULL otherwise.
1861 */
Michal Vasko208a04a2020-10-21 15:17:12 +02001862const struct lysc_node *lysc_node_children_full(const struct lysc_node *node, uint16_t flags);
Michal Vasko2a668712020-10-21 11:48:09 +02001863
1864/**
1865 * @brief Get the parent pointer from any type of (compiled) schema node.
Michal Vasko208a04a2020-10-21 15:17:12 +02001866 * Returns input or output for direct descendants of RPC/action nodes.
1867 * To skip them, use ::lysc_node.parent pointer directly.
Michal Vasko2a668712020-10-21 11:48:09 +02001868 *
1869 * @param[in] node Node whose parent to get.
1870 * @return Node parent.
1871 * @return NULL is there is none.
1872 */
Michal Vasko208a04a2020-10-21 15:17:12 +02001873const struct lysc_node *lysc_node_parent_full(const struct lysc_node *node);
Michal Vasko2a668712020-10-21 11:48:09 +02001874
1875/**
Michal Vaskof1ab44f2020-10-22 08:58:32 +02001876 * @brief Callback to be called for every schema node in a DFS traversal.
1877 *
1878 * @param[in] node Current node.
1879 * @param[in] data Arbitrary user data.
1880 * @param[out] dfs_continue Set to true if the current subtree should be skipped and continue with siblings instead.
1881 * @return LY_SUCCESS on success,
1882 * @return LY_ERR value to terminate DFS and return this value.
1883 */
1884typedef LY_ERR (*lysc_dfs_clb)(struct lysc_node *node, void *data, ly_bool *dfs_continue);
1885
1886/**
1887 * @brief DFS traversal of all the schema nodes in a (sub)tree including any actions and nested notifications.
1888 *
1889 * Node with children, actions, and notifications is traversed in this order:
1890 * 1) each child subtree;
1891 * 2) each action subtree;
1892 * 3) each notification subtree.
1893 *
1894 * For algorithm illustration or traversal with actions and notifications skipped, see ::LYSC_TREE_DFS_BEGIN.
1895 *
1896 * @param[in] root Schema root to fully traverse.
1897 * @param[in] dfs_clb Callback to call for each node.
1898 * @param[in] data Arbitrary user data passed to @p dfs_clb.
1899 * @return LY_SUCCESS on success,
1900 * @return LY_ERR value returned by @p dfs_clb.
1901 */
1902LY_ERR lysc_tree_dfs_full(const struct lysc_node *root, lysc_dfs_clb dfs_clb, void *data);
1903
1904/**
1905 * @brief DFS traversal of all the schema nodes in a module including RPCs and notifications.
1906 *
1907 * For more details, see ::lysc_tree_dfs_full().
1908 *
1909 * @param[in] mod Module to fully traverse.
1910 * @param[in] dfs_clb Callback to call for each node.
1911 * @param[in] data Arbitrary user data passed to @p dfs_clb.
1912 * @return LY_SUCCESS on success,
1913 * @return LY_ERR value returned by @p dfs_clb.
1914 */
1915LY_ERR lysc_module_dfs_full(const struct lys_module *mod, lysc_dfs_clb dfs_clb, void *data);
1916
1917/**
Michal Vaskod975f862020-06-23 13:29:28 +02001918 * @brief Examine whether a node is user-ordered list or leaf-list.
1919 *
Radek Krejci8678fa42020-08-18 16:07:28 +02001920 * @param[in] schema Schema node to examine.
Michal Vaskod975f862020-06-23 13:29:28 +02001921 * @return non-zero if it is,
Radek Krejci857189e2020-09-01 13:26:36 +02001922 * @return Boolean value whether the @p node is user-ordered or not.
Michal Vaskod975f862020-06-23 13:29:28 +02001923 */
Radek Krejci857189e2020-09-01 13:26:36 +02001924ly_bool lysc_is_userordered(const struct lysc_node *schema);
Michal Vaskod975f862020-06-23 13:29:28 +02001925
1926/**
Michal Vasko2fd91b92020-07-17 16:39:02 +02001927 * @brief Set a schema private pointer to a user pointer.
1928 *
1929 * @param[in] node Node, whose private field will be assigned. Works also for RPCs, actions, and notifications.
1930 * @param[in] priv Arbitrary user-specified pointer.
Radek Krejciaf9cd802020-10-06 21:59:47 +02001931 * @param[out] prev_priv_p Optional previous private object of the \p node. Note, that
Michal Vasko2fd91b92020-07-17 16:39:02 +02001932 * the caller is in this case responsible (if it is necessary) for freeing the replaced private object.
1933 * @return LY_ERR value.
1934 */
Radek Krejciaf9cd802020-10-06 21:59:47 +02001935LY_ERR lysc_set_private(const struct lysc_node *node, void *priv, void **prev_priv_p);
Michal Vasko2fd91b92020-07-17 16:39:02 +02001936
1937/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001938 * @brief Get how the if-feature statement currently evaluates.
1939 *
1940 * @param[in] iff Compiled if-feature statement to evaluate.
Michal Vasko28d78432020-05-26 13:10:53 +02001941 * @return LY_SUCCESS if the statement evaluates to true,
1942 * @return LY_ENOT if it evaluates to false,
1943 * @return LY_ERR on error.
Radek Krejci151a5b72018-10-19 14:21:44 +02001944 */
Michal Vasko28d78432020-05-26 13:10:53 +02001945LY_ERR lysc_iffeature_value(const struct lysc_iffeature *iff);
Radek Krejci151a5b72018-10-19 14:21:44 +02001946
1947/**
1948 * @brief Get the current status of the provided feature.
1949 *
1950 * @param[in] feature Compiled feature statement to examine.
Michal Vasko28d78432020-05-26 13:10:53 +02001951 * @return LY_SUCCESS if feature is enabled,
1952 * @return LY_ENOT if feature is disabled,
1953 * @return LY_ERR in case of error (invalid argument)
Radek Krejci151a5b72018-10-19 14:21:44 +02001954 */
Michal Vasko28d78432020-05-26 13:10:53 +02001955LY_ERR lysc_feature_value(const struct lysc_feature *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001956
Radek Krejcibed13942020-10-19 16:06:28 +02001957/**
1958 * @defgroup findxpathoptions Atomize XPath options
1959 * Options to modify behavior of ::lys_find_xpath() and ::lys_find_xpath_atoms() searching for schema nodes in schema tree.
1960 * @{
1961 */
1962#define LYS_FIND_XP_SCHEMA 0x04 /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */
1963#define LYS_FIND_XP_OUTPUT 0x08 /**< Search RPC/action output nodes instead of input ones. */
1964/*
1965 * }@
1966 */
Michal Vasko072de482020-08-05 13:27:21 +02001967
Radek Krejci151a5b72018-10-19 14:21:44 +02001968/**
Michal Vasko40308e72020-10-20 16:38:40 +02001969 * @brief Get all the schema nodes that are required for @p xpath to be evaluated (atoms).
Michal Vasko519fd602020-05-26 12:17:39 +02001970 *
1971 * @param[in] ctx_node XPath schema context node.
Michal Vasko40308e72020-10-20 16:38:40 +02001972 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_PREF_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02001973 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko519fd602020-05-26 12:17:39 +02001974 * @param[out] set Set of found atoms (schema nodes).
1975 * @return LY_SUCCESS on success, @p set is returned.
Michal Vasko40308e72020-10-20 16:38:40 +02001976 * @return LY_ERR value on error.
Michal Vasko519fd602020-05-26 12:17:39 +02001977 */
Radek Krejcibed13942020-10-19 16:06:28 +02001978LY_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 +02001979
Michal Vasko072de482020-08-05 13:27:21 +02001980/**
Michal Vasko40308e72020-10-20 16:38:40 +02001981 * @brief Get all the schema nodes that are required for @p path to be evaluated (atoms).
1982 *
1983 * @param[in] path Compiled path to use.
1984 * @param[out] set Set of found atoms (schema nodes).
1985 * @return LY_SUCCESS on success, @p set is returned.
1986 * @return LY_ERR value on error.
1987 */
1988LY_ERR lys_find_path_atoms(const struct ly_path *path, struct ly_set **set);
1989
1990/**
1991 * @brief Get all the schema nodes that are required for @p expr to be evaluated (atoms).
Michal Vasko072de482020-08-05 13:27:21 +02001992 *
1993 * @param[in] ctx_node XPath schema context node.
Michal Vasko40308e72020-10-20 16:38:40 +02001994 * @param[in] cur_mod Current module for the expression (where it was "instantiated").
1995 * @param[in] expr Parsed expression to use.
1996 * @param[in] prefixes Sized array of compiled prefixes.
1997 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
1998 * @param[out] set Set of found atoms (schema nodes).
1999 * @return LY_SUCCESS on success, @p set is returned.
2000 * @return LY_ERR value on error.
2001 */
2002LY_ERR lys_find_expr_atoms(const struct lysc_node *ctx_node, const struct lys_module *cur_mod,
2003 const struct lyxp_expr *expr, const struct lysc_prefix *prefixes, uint32_t options, struct ly_set **set);
2004
2005/**
2006 * @brief Evaluate an @p xpath expression on schema nodes.
2007 *
2008 * @param[in] ctx_node XPath schema context node.
2009 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_PREF_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02002010 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko072de482020-08-05 13:27:21 +02002011 * @param[out] set Set of found schema nodes.
2012 * @return LY_SUCCESS on success, @p set is returned.
2013 * @return LY_ERR value if an error occurred.
2014 */
Radek Krejci1deb5be2020-08-26 16:43:36 +02002015LY_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 +02002016
2017/**
Michal Vasko03ff5a72019-09-11 13:49:33 +02002018 * @brief Types of the different schema paths.
2019 */
2020typedef enum {
Michal Vasko65de0402020-08-03 16:34:19 +02002021 LYSC_PATH_LOG, /**< Descriptive path format used in log messages */
2022 LYSC_PATH_DATA /**< Similar to ::LYSC_PATH_LOG except that schema-only nodes (choice, case) are skipped */
Michal Vasko03ff5a72019-09-11 13:49:33 +02002023} LYSC_PATH_TYPE;
2024
2025/**
Radek Krejci327de162019-06-14 12:52:07 +02002026 * @brief Generate path of the given node in the requested format.
2027 *
2028 * @param[in] node Schema path of this node will be generated.
2029 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02002030 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
2031 * If NULL, memory for the complete path is allocated.
2032 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02002033 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02002034 * 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 +02002035 */
Michal Vasko03ff5a72019-09-11 13:49:33 +02002036char *lysc_path(const struct lysc_node *node, LYSC_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02002037
2038/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002039 * @brief Available YANG schema tree structures representing YANG module.
2040 */
2041struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002042 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
2043 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01002044 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002045 const char *ns; /**< namespace of the module (module - mandatory) */
2046 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
2047 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
2048 const char *org; /**< party/company responsible for the module */
2049 const char *contact; /**< contact information for the module */
2050 const char *dsc; /**< description of the module */
2051 const char *ref; /**< cross-reference for the module */
2052
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002053 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01002054 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
2055 Available only for implemented modules. */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002056
Radek Krejci14915cc2020-09-14 17:28:13 +02002057 struct lysc_feature *features; /**< List of compiled features of the module ([sized array](@ref sizedarrays)).
2058 Features are outside the compiled tree since they are needed even the module is not
2059 compiled. In such a case, the features are always disabled and cannot be enabled until
2060 the module is implemented. The features are present in this form to allow their linkage
Radek Krejci0af46292019-01-11 16:02:31 +01002061 from if-feature statements of the compiled schemas and their proper use in case
2062 the module became implemented in future (no matter if implicitly via augment/deviate
Radek Krejci14915cc2020-09-14 17:28:13 +02002063 or explicitly via ::lys_set_implemented()). */
Radek Krejci80d281e2020-09-14 17:42:54 +02002064 struct lysc_ident *identities; /**< List of compiled identities of the module ([sized array](@ref sizedarrays))
2065 Identities are outside the compiled tree to allow their linkage to the identities from
2066 the implemented modules. This avoids problems when the module became implemented in
2067 future (no matter if implicitly via augment/deviate or explicitly via
2068 ::lys_set_implemented()). Note that if the module is not implemented (compiled), the
2069 identities cannot be instantiated in data (in identityrefs). */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002070
2071 struct lys_module **augmented_by;/**< List of modules that augment this module ([sized array](@ref sizedarrays)) */
2072 struct lys_module **deviated_by; /**< List of modules that deviate this module ([sized array](@ref sizedarrays)) */
2073
Michal Vasko89b5c072020-10-06 13:52:44 +02002074 ly_bool implemented; /**< flag if the module is implemented, not just imported */
Radek Krejci95710c92019-02-11 15:49:55 +01002075 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002076 1 - the latest revision in searchdirs was not searched yet and this is the
2077 latest revision in the current context
2078 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002079};
2080
Radek Krejci151a5b72018-10-19 14:21:44 +02002081/**
2082 * @brief Enable specified feature in the module
2083 *
2084 * By default, when the module is loaded by libyang parser, all features are disabled.
2085 *
Radek Krejcica3db002018-11-01 10:31:01 +01002086 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
2087 * enabling all features on the following feature set will fail since it is not possible to enable both features
2088 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
2089 * is untouched.
2090 *
2091 * feature f1;
2092 * feature f2 { if-feature 'not f1';}
2093 *
Radek Krejci151a5b72018-10-19 14:21:44 +02002094 * @param[in] module Module where the feature will be enabled.
2095 * @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 +02002096 * @return LY_SUCCESS on success,
2097 * @return LY_EINVAL if @p module is not implemented,
2098 * @return LY_ENOTFOUND if @p feature was not found,
2099 * @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 +02002100 */
Radek Krejcied5acc52019-04-25 15:57:04 +02002101LY_ERR lys_feature_enable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02002102
2103/**
2104 * @brief Disable specified feature in the module
2105 *
2106 * By default, when the module is loaded by libyang parser, all features are disabled.
2107 *
Michal Vasko82c31e62020-07-17 15:30:40 +02002108 * If disabling a feature causes some other features that depend on this feature to become disabled.
2109 *
Radek Krejci151a5b72018-10-19 14:21:44 +02002110 * @param[in] module Module where the feature will be disabled.
2111 * @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 +02002112 * @return LY_SUCCESS on success,
2113 * @return LY_EINVAL if @p module is not implemented,
2114 * @return LY_ENOTFOUND if @p feature was not found.
Radek Krejci151a5b72018-10-19 14:21:44 +02002115 */
Radek Krejcied5acc52019-04-25 15:57:04 +02002116LY_ERR lys_feature_disable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02002117
2118/**
Michal Vasko82c31e62020-07-17 15:30:40 +02002119 * @brief Enable specified feature in the module disregarding its if-features.
2120 *
2121 * @param[in] module Module where the feature will be enabled.
2122 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk character.
2123 * @return LY_SUCCESS on success,
2124 * @return LY_EINVAL if @p module is not implemented,
2125 * @return LY_ENOTFOUND if @p feature was not found.
2126 */
2127LY_ERR lys_feature_enable_force(const struct lys_module *module, const char *feature);
2128
2129/**
2130 * @brief Disable specified feature in the module disregarding dependant features.
2131 *
2132 * By default, when the module is loaded by libyang parser, all features are disabled.
2133 *
2134 * @param[in] module Module where the feature will be disabled.
2135 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk character.
2136 * @return LY_SUCCESS on success,
2137 * @return LY_EINVAL if @p module is not implemented,
2138 * @return LY_ENOTFOUND if @p feature was not found.
2139 */
2140LY_ERR lys_feature_disable_force(const struct lys_module *module, const char *feature);
2141
2142/**
2143 * @brief Get the current real status of the specified feature in the module.
2144 *
2145 * If the feature is enabled, but some of its if-features are false, the feature is considered
2146 * disabled.
Radek Krejci151a5b72018-10-19 14:21:44 +02002147 *
2148 * @param[in] module Module where the feature is defined.
2149 * @param[in] feature Name of the feature to inspect.
Michal Vasko82c31e62020-07-17 15:30:40 +02002150 * @return LY_SUCCESS if the feature is enabled,
2151 * @return LY_ENOT if the feature is disabled,
2152 * @return LY_ENOTFOUND if the feature was not found.
Radek Krejci151a5b72018-10-19 14:21:44 +02002153 */
Michal Vasko82c31e62020-07-17 15:30:40 +02002154LY_ERR lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02002155
2156/**
Radek Krejcia3045382018-11-22 14:30:31 +01002157 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
2158 * be from an augment.
2159 *
Radek Krejci8678fa42020-08-18 16:07:28 +02002160 * ::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 +01002161 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
2162 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
2163 * \p parent and \p module parameters.
2164 *
2165 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
2166 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
2167 * all the schema nodes are iteratively returned.
2168 *
2169 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
2170 * @param[in] parent Parent of the subtree where the function starts processing.
2171 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
2172 * module must be specified.
2173 * @param[in] options [ORed options](@ref sgetnextflags).
2174 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
2175 */
2176const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002177 const struct lysc_module *module, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002178
2179/**
Radek Krejci8678fa42020-08-18 16:07:28 +02002180 * @defgroup sgetnextflags Options for ::lys_getnext().
2181 *
2182 * Various options setting behavior of ::lys_getnext().
2183 *
Radek Krejcia3045382018-11-22 14:30:31 +01002184 * @{
2185 */
Radek Krejci8678fa42020-08-18 16:07:28 +02002186#define LYS_GETNEXT_WITHCHOICE 0x01 /**< ::lys_getnext() option to allow returning #LYS_CHOICE nodes instead of looking into them */
2187#define LYS_GETNEXT_NOCHOICE 0x02 /**< ::lys_getnext() option to ignore (kind of conditional) nodes within choice node */
2188#define LYS_GETNEXT_WITHCASE 0x04 /**< ::lys_getnext() option to allow returning #LYS_CASE nodes instead of looking into them */
2189#define LYS_GETNEXT_INTONPCONT 0x40 /**< ::lys_getnext() option to look into non-presence container, instead of returning container itself */
2190#define LYS_GETNEXT_NOSTATECHECK 0x100 /**< ::lys_getnext() option to skip checking module validity (import-only, disabled) and
Radek Krejcia3045382018-11-22 14:30:31 +01002191 relevant if-feature conditions state */
Radek Krejci8678fa42020-08-18 16:07:28 +02002192#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 +01002193 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01002194/** @} sgetnextflags */
2195
2196/**
2197 * @brief Get child node according to the specified criteria.
2198 *
2199 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
2200 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
2201 * @param[in] name Name of the node to find.
2202 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
2203 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
2204 * Used as a bitmask, so multiple nodetypes can be specified.
2205 * @param[in] options [ORed options](@ref sgetnextflags).
2206 * @return Found node if any.
2207 */
Michal Vaskoe444f752020-02-10 12:20:06 +01002208const struct lysc_node *lys_find_child(const struct lysc_node *parent, const struct lys_module *module,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002209 const char *name, size_t name_len, uint16_t nodetype, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002210
2211/**
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002212 * @brief Make the specific module implemented.
2213 *
2214 * @param[in] mod Module to make implemented. It is not an error
2215 * to provide already implemented module, it just does nothing.
Michal Vaskoe444f752020-02-10 12:20:06 +01002216 * @return LY_SUCCESS on success.
2217 * @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 +02002218 */
2219LY_ERR lys_set_implemented(struct lys_module *mod);
2220
2221/**
Radek Krejcia3045382018-11-22 14:30:31 +01002222 * @brief Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statement
2223 * affecting the node.
2224 *
2225 * @param[in] node Schema node to check.
2226 * @param[in] recursive - 0 to check if-feature only in the \p node schema node,
2227 * - 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 +01002228 * @return NULL if enabled,
Michal Vaskoc193ce92020-03-06 11:04:48 +01002229 * @return pointer to the node with the unsatisfied (disabled) if-feature expression.
Radek Krejcia3045382018-11-22 14:30:31 +01002230 */
Radek Krejci857189e2020-09-01 13:26:36 +02002231const struct lysc_node *lysc_node_is_disabled(const struct lysc_node *node, ly_bool recursive);
Radek Krejcia3045382018-11-22 14:30:31 +01002232
Radek Krejci084289f2019-07-09 17:35:30 +02002233/**
2234 * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
2235 *
2236 * 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 +02002237 * require-instance restriction), use ::lyd_value_validate().
Radek Krejci084289f2019-07-09 17:35:30 +02002238 *
2239 * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
2240 * @param[in] node Schema node for the @p value.
Michal Vaskof937cfe2020-08-03 16:07:12 +02002241 * @param[in] value String value to be checked, expected to be in JSON format.
Radek Krejci084289f2019-07-09 17:35:30 +02002242 * @param[in] value_len Length of the given @p value (mandatory).
Radek Krejci084289f2019-07-09 17:35:30 +02002243 * @return LY_SUCCESS on success
2244 * @return LY_ERR value if an error occurred.
2245 */
Michal Vaskof937cfe2020-08-03 16:07:12 +02002246LY_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 +02002247
Radek Krejci0935f412019-08-20 16:15:18 +02002248/**
2249 * @brief Stringify schema nodetype.
Michal Vaskod43d71a2020-08-07 14:54:58 +02002250 *
Radek Krejci0935f412019-08-20 16:15:18 +02002251 * @param[in] nodetype Nodetype to stringify.
2252 * @return Constant string with the name of the node's type.
2253 */
2254const char *lys_nodetype2str(uint16_t nodetype);
2255
Michal Vaskod43d71a2020-08-07 14:54:58 +02002256/**
2257 * @brief Getter for original XPath expression from a parsed expression.
2258 *
2259 * @param[in] path Parsed expression.
2260 * @return Original string expression.
2261 */
2262const char *lyxp_get_expr(const struct lyxp_expr *path);
2263
Radek Krejci2ff0d572020-05-21 15:27:28 +02002264/** @} schematree */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002265
Radek Krejci70853c52018-10-15 14:46:16 +02002266#ifdef __cplusplus
2267}
2268#endif
2269
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002270#endif /* LY_TREE_SCHEMA_H_ */