blob: 35dade97315c68d449f35db615d20400df65ad25 [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 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100121 * YANG feature statement is an important part of the language which can significantly affect the meaning of the schemas.
122 * Modifying features may have similar effects as loading/removing schema from the context so it is limited to context
123 * preparation period before working with data. YANG features, respectively their use in if-feature
124 * statements, are evaluated as part of schema compilation so a feature-specific compiled schema tree is generated
125 * as a result.
Radek Krejci8678fa42020-08-18 16:07:28 +0200126 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100127 * To enable any features, they must currently be specified when implementing a new schema with ::lys_parse() or
128 * ::ly_ctx_load_module(). To later examine what the status of a feature is, check its ::LYS_FENABLED flag or
129 * search for it first with ::lys_feature_value(). Lastly, to evaluate compiled if-features, use ::lysc_iffeature_value().
Radek Krejci8678fa42020-08-18 16:07:28 +0200130 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100131 * To iterate over all features of a particular YANG module, use ::lysp_feature_next().
Radek Krejci8678fa42020-08-18 16:07:28 +0200132 *
133 * Note, that the feature's state can affect some of the output formats (e.g. Tree format).
134 *
135 * Functions List
136 * --------------
Radek Krejci8678fa42020-08-18 16:07:28 +0200137 * - ::lys_feature_value()
Radek Krejci8678fa42020-08-18 16:07:28 +0200138 * - ::lysc_iffeature_value()
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100139 * - ::lysp_feature_next()
Radek Krejci8678fa42020-08-18 16:07:28 +0200140 */
141
142/**
Radek Krejci2ff0d572020-05-21 15:27:28 +0200143 * @ingroup trees
Radek Krejci8678fa42020-08-18 16:07:28 +0200144 * @defgroup schematree Schema Tree
Radek Krejci2ff0d572020-05-21 15:27:28 +0200145 * @{
146 *
147 * Data structures and functions to manipulate and access schema tree.
148 */
149
Michal Vasko64246d82020-08-19 12:35:00 +0200150/* *INDENT-OFF* */
151
Radek Krejci2ff0d572020-05-21 15:27:28 +0200152/**
Michal Vasko208a04a2020-10-21 15:17:12 +0200153 * @brief Macro to iterate via all elements in a schema (sub)tree including input and output.
154 * Note that __actions__ and __notifications__ of traversed nodes __are ignored__! To traverse
155 * on all the nodes including those, use ::lysc_tree_dfs_full() instead.
156 *
157 * 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 +0200158 *
159 * The function follows deep-first search algorithm:
160 * <pre>
161 * 1
162 * / \
163 * 2 4
164 * / / \
165 * 3 5 6
166 * </pre>
167 *
168 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
169 * START can be any of the lysc_node* types (including lysc_action and lysc_notif),
170 * ELEM variable must be of the struct lysc_node* type.
171 *
172 * To skip a particular subtree, instead of the continue statement, set LYSC_TREE_DFS_continue
173 * variable to non-zero value.
174 *
175 * Use with opening curly bracket '{' after the macro.
176 *
177 * @param START Pointer to the starting element processed first.
178 * @param ELEM Iterator intended for use in the block.
179 */
180#define LYSC_TREE_DFS_BEGIN(START, ELEM) \
Radek Krejci857189e2020-09-01 13:26:36 +0200181 { ly_bool LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
Michal Vasko1c9e79f2020-08-10 11:08:03 +0200182 for ((ELEM) = (LYSC_TREE_DFS_next) = (struct lysc_node*)(START); \
Radek Krejci0935f412019-08-20 16:15:18 +0200183 (ELEM); \
184 (ELEM) = (LYSC_TREE_DFS_next), LYSC_TREE_DFS_continue = 0)
185
186/**
187 * @brief Macro to iterate via all elements in a (sub)tree. This is the closing part
188 * to the #LYSC_TREE_DFS_BEGIN - they always have to be used together.
189 *
190 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
191 * START can be a pointer to any of the lysc_node* types (including lysc_action and lysc_notif),
192 * ELEM variable must be pointer to the lysc_node type.
193 *
194 * Use with closing curly bracket '}' after the macro.
195 *
196 * @param START Pointer to the starting element processed first.
197 * @param ELEM Iterator intended for use in the block.
198 */
Radek Krejci0935f412019-08-20 16:15:18 +0200199#define LYSC_TREE_DFS_END(START, ELEM) \
200 /* select element for the next run - children first */ \
201 if (LYSC_TREE_DFS_continue) { \
202 (LYSC_TREE_DFS_next) = NULL; \
203 } else { \
Michal Vasko208a04a2020-10-21 15:17:12 +0200204 (LYSC_TREE_DFS_next) = (struct lysc_node *)lysc_node_children_full(ELEM, 0); \
205 } \
Radek Krejci0935f412019-08-20 16:15:18 +0200206 if (!(LYSC_TREE_DFS_next)) { \
Michal Vasko208a04a2020-10-21 15:17:12 +0200207 /* no children, try siblings */ \
208 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
Radek Krejci0935f412019-08-20 16:15:18 +0200209 } \
210 while (!(LYSC_TREE_DFS_next)) { \
211 /* parent is already processed, go to its sibling */ \
Michal Vasko208a04a2020-10-21 15:17:12 +0200212 (ELEM) = (struct lysc_node *)lysc_node_parent_full(ELEM); \
213 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
214 } }
215
216/**
217 * @brief Helper macro for #LYSC_TREE_DFS_END, should not be used directly!
218 */
219#define _LYSC_TREE_DFS_NEXT(START, ELEM, NEXT) \
220 if ((ELEM) == (struct lysc_node *)(START)) { \
221 /* we are done, no next element to process */ \
222 break; \
223 } \
224 if ((ELEM)->nodetype == LYS_INPUT) { \
225 /* after input, get output */ \
226 (NEXT) = (struct lysc_node *)lysc_node_children_full(lysc_node_parent_full(ELEM), LYS_CONFIG_R); \
227 } else if ((ELEM)->nodetype == LYS_OUTPUT) { \
228 /* no sibling of output */ \
229 (NEXT) = NULL; \
230 } else { \
231 (NEXT) = (ELEM)->next; \
232 }
Radek Krejci0935f412019-08-20 16:15:18 +0200233
Michal Vasko64246d82020-08-19 12:35:00 +0200234/* *INDENT-ON* */
235
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200236#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
237
Michal Vasko7f45cf22020-10-01 12:49:44 +0200238#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
239#define LYS_CONTAINER 0x0001 /**< container statement node */
240#define LYS_CHOICE 0x0002 /**< choice statement node */
241#define LYS_LEAF 0x0004 /**< leaf statement node */
242#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
243#define LYS_LIST 0x0010 /**< list statement node */
244#define LYS_ANYXML 0x0020 /**< anyxml statement node */
245#define LYS_ANYDATA 0x0060 /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
246#define LYS_CASE 0x0080 /**< case statement node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200247
Michal Vasko7f45cf22020-10-01 12:49:44 +0200248#define LYS_RPC 0x0100 /**< RPC statement node */
249#define LYS_ACTION 0x0200 /**< action statement node */
250#define LYS_NOTIF 0x0400 /**< notification statement node */
Radek Krejcie7b95092019-05-15 11:03:07 +0200251
Michal Vasko7f45cf22020-10-01 12:49:44 +0200252#define LYS_USES 0x0800 /**< uses statement node */
253#define LYS_INPUT 0x1000 /**< RPC/action input node */
254#define LYS_OUTPUT 0x2000 /**< RPC/action output node */
255#define LYS_GROUPING 0x4000
256#define LYS_AUGMENT 0x8000
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100257
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200258/**
Radek Krejcid6b76452019-09-03 17:03:03 +0200259 * @brief List of YANG statements
260 */
261enum ly_stmt {
262 LY_STMT_NONE = 0,
Radek Krejci8678fa42020-08-18 16:07:28 +0200263 LY_STMT_STATUS, /**< in ::lysc_ext_substmt.storage stored as a pointer to `uint16_t`, only cardinality < #LY_STMT_CARD_SOME is allowed */
264 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 +0200265 LY_STMT_MANDATORY,
Radek Krejci8678fa42020-08-18 16:07:28 +0200266 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 +0200267 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200268 LY_STMT_DEFAULT,
Radek Krejci8678fa42020-08-18 16:07:28 +0200269 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 +0200270 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_type **` */
Radek Krejci335332a2019-09-05 13:03:35 +0200271
Radek Krejcid6b76452019-09-03 17:03:03 +0200272 LY_STMT_ACTION,
273 LY_STMT_ANYDATA,
274 LY_STMT_ANYXML,
275 LY_STMT_ARGUMENT,
276 LY_STMT_AUGMENT,
277 LY_STMT_BASE,
278 LY_STMT_BELONGS_TO,
279 LY_STMT_BIT,
280 LY_STMT_CASE,
281 LY_STMT_CHOICE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200282 LY_STMT_CONTACT,
283 LY_STMT_CONTAINER,
Radek Krejcid6b76452019-09-03 17:03:03 +0200284 LY_STMT_DESCRIPTION,
285 LY_STMT_DEVIATE,
286 LY_STMT_DEVIATION,
287 LY_STMT_ENUM,
288 LY_STMT_ERROR_APP_TAG,
289 LY_STMT_ERROR_MESSAGE,
290 LY_STMT_EXTENSION,
291 LY_STMT_FEATURE,
292 LY_STMT_FRACTION_DIGITS,
293 LY_STMT_GROUPING,
294 LY_STMT_IDENTITY,
Radek Krejci8678fa42020-08-18 16:07:28 +0200295 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 +0200296 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_iffeature *` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200297 LY_STMT_IMPORT,
298 LY_STMT_INCLUDE,
299 LY_STMT_INPUT,
300 LY_STMT_KEY,
301 LY_STMT_LEAF,
302 LY_STMT_LEAF_LIST,
303 LY_STMT_LENGTH,
304 LY_STMT_LIST,
Radek Krejcid6b76452019-09-03 17:03:03 +0200305 LY_STMT_MAX_ELEMENTS,
306 LY_STMT_MIN_ELEMENTS,
307 LY_STMT_MODIFIER,
308 LY_STMT_MODULE,
309 LY_STMT_MUST,
310 LY_STMT_NAMESPACE,
311 LY_STMT_NOTIFICATION,
312 LY_STMT_ORDERED_BY,
313 LY_STMT_ORGANIZATION,
314 LY_STMT_OUTPUT,
315 LY_STMT_PATH,
316 LY_STMT_PATTERN,
317 LY_STMT_POSITION,
318 LY_STMT_PREFIX,
319 LY_STMT_PRESENCE,
320 LY_STMT_RANGE,
321 LY_STMT_REFERENCE,
322 LY_STMT_REFINE,
323 LY_STMT_REQUIRE_INSTANCE,
324 LY_STMT_REVISION,
325 LY_STMT_REVISION_DATE,
326 LY_STMT_RPC,
Radek Krejcid6b76452019-09-03 17:03:03 +0200327 LY_STMT_SUBMODULE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200328 LY_STMT_TYPEDEF,
329 LY_STMT_UNIQUE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200330 LY_STMT_USES,
331 LY_STMT_VALUE,
332 LY_STMT_WHEN,
333 LY_STMT_YANG_VERSION,
334 LY_STMT_YIN_ELEMENT,
335 LY_STMT_EXTENSION_INSTANCE,
336
337 LY_STMT_SYNTAX_SEMICOLON,
338 LY_STMT_SYNTAX_LEFT_BRACE,
339 LY_STMT_SYNTAX_RIGHT_BRACE,
340
341 LY_STMT_ARG_TEXT,
342 LY_STMT_ARG_VALUE
343};
344
345/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200346 * @brief Extension instance structure parent enumeration
347 */
348typedef enum {
Radek Krejci0935f412019-08-20 16:15:18 +0200349 LYEXT_PAR_MODULE, /**< ::lysc_module */
350 LYEXT_PAR_NODE, /**< ::lysc_node (and the derived structures including ::lysc_action and ::lysc_notif) */
351 LYEXT_PAR_INPUT, /**< ::lysc_action_inout */
352 LYEXT_PAR_OUTPUT, /**< ::lysc_action_inout */
353 LYEXT_PAR_TYPE, /**< ::lysc_type */
354 LYEXT_PAR_TYPE_BIT, /**< ::lysc_type_bitenum_item */
355 LYEXT_PAR_TYPE_ENUM, /**< ::lysc_type_bitenum_item */
Radek Krejci0935f412019-08-20 16:15:18 +0200356 LYEXT_PAR_MUST, /**< ::lysc_must */
357 LYEXT_PAR_PATTERN, /**< ::lysc_pattern */
358 LYEXT_PAR_LENGTH, /**< ::lysc_range */
359 LYEXT_PAR_RANGE, /**< ::lysc_range */
360 LYEXT_PAR_WHEN, /**< ::lysc_when */
361 LYEXT_PAR_IDENT, /**< ::lysc_ident */
362 LYEXT_PAR_EXT, /**< ::lysc_ext */
Michal Vasko69730152020-10-09 16:30:07 +0200363 LYEXT_PAR_IMPORT /**< ::lysp_import */
Michal Vasko033278d2020-08-24 11:24:52 +0200364// LYEXT_PAR_TPDF, /**< ::lysp_tpdf */
365// LYEXT_PAR_EXTINST, /**< ::lysp_ext_instance */
366// LYEXT_PAR_REFINE, /**< ::lysp_refine */
367// LYEXT_PAR_DEVIATION, /**< ::lysp_deviation */
368// LYEXT_PAR_DEVIATE, /**< ::lysp_deviate */
369// LYEXT_PAR_INCLUDE, /**< ::lysp_include */
370// LYEXT_PAR_REVISION, /**< ::lysp_revision */
Radek Krejci0e59c312019-08-15 15:34:15 +0200371} LYEXT_PARENT;
372
373/**
Radek Krejci0935f412019-08-20 16:15:18 +0200374 * @brief Stringify extension instance parent type.
375 * @param[in] type Parent type to stringify.
376 * @return Constant string with the name of the parent statement.
377 */
378const char *lyext_parent2str(LYEXT_PARENT type);
379
380/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200381 * @brief Enum of substatements in which extension instances can appear.
382 */
383typedef enum {
384 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
385 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
386 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
387 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
388 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
389 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
390 lys_node_choice and lys_deviate */
391 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
392 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
393 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
394 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
395 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
396 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
397 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
398 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
399 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
400 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
401 belongs-to's prefix) and lys_import */
402 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
403 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
404 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
405 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
406 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
407 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
408 lys_node_leaflist and lys_deviate */
409 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
410 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
411 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
412 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
413 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
414 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
415 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
416 lys_node_anydata and lys_deviate */
417 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
418 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
419 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
420 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
421 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
422 lys_node_leaflist and lys_deviate */
423 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
424 lys_node_leaflist and lys_deviate */
425 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
426 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
Michal Vasko69730152020-10-09 16:30:07 +0200427 LYEXT_SUBSTMT_IFFEATURE /**< extension of the if-feature statement */
Radek Krejci0e59c312019-08-15 15:34:15 +0200428} LYEXT_SUBSTMT;
429
430/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200431 * @brief YANG import-stmt
432 */
433struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200434 struct lys_module *module; /**< pointer to the imported module
435 (mandatory, but resolved when the referring module is completely parsed) */
436 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200437 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200438 const char *dsc; /**< description */
439 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200440 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200441 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
442};
443
444/**
445 * @brief YANG include-stmt
446 */
447struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100448 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200449 (mandatory, but resolved when the referring module is completely parsed) */
450 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200451 const char *dsc; /**< description */
452 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200453 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200454 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
455};
456
457/**
458 * @brief YANG extension-stmt
459 */
460struct lysp_ext {
461 const char *name; /**< extension name */
462 const char *argument; /**< argument name, NULL if not specified */
463 const char *dsc; /**< description statement */
464 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200465 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200466 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */
Michal Vasko5fe75f12020-03-02 13:52:37 +0100467
468 struct lysc_ext *compiled; /**< pointer to the compiled extension definition */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200469};
470
471/**
472 * @brief Helper structure for generic storage of the extension instances content.
473 */
474struct lysp_stmt {
475 const char *stmt; /**< identifier of the statement */
476 const char *arg; /**< statement's argument */
477 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200478 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
David Sedlákb9d75c42019-08-14 10:49:42 +0200479 uint16_t flags; /**< statement flags, can be set to LYS_YIN_ATTR */
Radek Krejci335332a2019-09-05 13:03:35 +0200480 enum ly_stmt kw; /**< numeric respresentation of the stmt value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200481};
482
David Sedlákae4b4512019-08-14 10:45:56 +0200483#define LYS_YIN 0x1 /**< used to specify input format of extension instance */
484
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200485/**
486 * @brief YANG extension instance
487 */
488struct lysp_ext_instance {
David Sedlákbbd06ca2019-06-27 14:15:38 +0200489 const char *name; /**< extension identifier, including possible prefix */
490 const char *argument; /**< optional value of the extension's argument */
Radek Krejci335332a2019-09-05 13:03:35 +0200491 void *parent; /**< pointer to the parent element holding the extension instance(s), use
492 ::lysp_ext_instance#parent_type to access the schema element */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200493 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200494 struct lysc_ext_instance *compiled; /**< pointer to the compiled data if any - in case the source format is YIN,
495 some of the information (argument) are available only after compilation */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200496 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200497 LY_ARRAY_COUNT_TYPE insubstmt_index; /**< in case the instance is in a substatement, this identifies
David Sedlákbbd06ca2019-06-27 14:15:38 +0200498 the index of that substatement */
David Sedlákae4b4512019-08-14 10:45:56 +0200499 uint8_t yin; /** flag for YIN source format, can be set to LYS_YIN */
Radek Krejci335332a2019-09-05 13:03:35 +0200500 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200501};
502
503/**
504 * @brief YANG feature-stmt
505 */
506struct lysp_feature {
507 const char *name; /**< feature name (mandatory) */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100508 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
509 struct lysc_iffeature *iffeatures_c; /**< compiled if-features */
510 struct lysp_feature **depfeatures; /**< list of pointers to other features depending on this one
511 ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200512 const char *dsc; /**< description statement */
513 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200514 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100515 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values and
516 LYS_FENABLED are allowed */
517};
518
519/**
520 * @brief Compiled YANG if-feature-stmt
521 */
522struct lysc_iffeature {
523 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
524 struct lysp_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200525};
526
527/**
Michal Vasko7f45cf22020-10-01 12:49:44 +0200528 * @brief Qualified name (optional prefix followed by an identifier).
529 */
530struct lysp_qname {
531 const char *str; /**< qualified name string */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200532 const struct lysp_module *mod; /**< module to resolve any prefixes found in the string, it must be
Michal Vasko7f45cf22020-10-01 12:49:44 +0200533 stored explicitly because of deviations/refines */
534};
535
536/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200537 * @brief YANG identity-stmt
538 */
539struct lysp_ident {
540 const char *name; /**< identity name (mandatory), including possible prefix */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200541 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200542 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200543 const char *dsc; /**< description statement */
544 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200545 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200546 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
547};
548
Michal Vasko71e64ca2018-09-07 16:30:29 +0200549/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200550 * @brief Covers restrictions: range, length, pattern, must
551 */
552struct lysp_restr {
Michal Vasko7f45cf22020-10-01 12:49:44 +0200553 struct lysp_qname arg; /**< The restriction expression/value (mandatory);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200554 in case of pattern restriction, the first byte has a special meaning:
555 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
556 const char *emsg; /**< error-message */
557 const char *eapptag; /**< error-app-tag value */
558 const char *dsc; /**< description */
559 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200560 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200561};
562
563/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200564 * @brief YANG revision-stmt
565 */
566struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200567 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200568 const char *dsc; /**< description statement */
569 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200570 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200571};
572
573/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200574 * @brief Enumeration/Bit value definition
575 */
576struct lysp_type_enum {
577 const char *name; /**< name (mandatory) */
578 const char *dsc; /**< description statement */
579 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200580 int64_t value; /**< enum's value or bit's position */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200581 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200582 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200583 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
584 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200585};
586
587/**
588 * @brief YANG type-stmt
589 *
590 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
591 */
592struct lysp_type {
593 const char *name; /**< name of the type (mandatory) */
594 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
595 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200596 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
597 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
598 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Michal Vasko004d3152020-06-11 19:59:22 +0200599 struct lyxp_expr *path; /**< parsed path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200600 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200601 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
602 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200603
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200604 const struct lysp_module *pmod; /**< (sub)module where the type is defined (needed for deviations) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100605 struct lysc_type *compiled; /**< pointer to the compiled type */
606
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200607 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
608 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100609 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200610};
611
612/**
613 * @brief YANG typedef-stmt
614 */
615struct lysp_tpdf {
616 const char *name; /**< name of the newly defined type (mandatory) */
617 const char *units; /**< units of the newly defined type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200618 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 +0200619 const char *dsc; /**< description statement */
620 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200621 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200622 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100623 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200624};
625
626/**
627 * @brief YANG grouping-stmt
628 */
629struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100630 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
631 uint16_t nodetype; /**< LYS_GROUPING */
632 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200633 const char *name; /**< grouping name (mandatory) */
634 const char *dsc; /**< description statement */
635 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200636 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
637 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200638 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200639 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
640 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
641 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200642};
643
644/**
645 * @brief YANG when-stmt
646 */
647struct lysp_when {
648 const char *cond; /**< specified condition (mandatory) */
649 const char *dsc; /**< description statement */
650 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200651 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200652};
653
654/**
655 * @brief YANG refine-stmt
656 */
657struct lysp_refine {
658 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
659 const char *dsc; /**< description statement */
660 const char *ref; /**< reference statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200661 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200662 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200663 const char *presence; /**< presence description */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200664 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200665 uint32_t min; /**< min-elements constraint */
666 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200667 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200668 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
669};
670
671/**
Michal Vasko82a83432019-11-14 12:33:04 +0100672 * @brief YANG uses-augment-stmt and augment-stmt (compatible with struct lysp_node )
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200673 */
674struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100675 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
676 uint16_t nodetype; /**< LYS_AUGMENT */
677 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Michal Vasko82a83432019-11-14 12:33:04 +0100678 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200679 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
680 const char *dsc; /**< description statement */
681 const char *ref; /**< reference statement */
682 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200683 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Michal Vasko82a83432019-11-14 12:33:04 +0100684 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200685 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
686 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200687};
688
689/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200690 * @ingroup schematree
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200691 * @defgroup deviatetypes Deviate types
Radek Krejci8678fa42020-08-18 16:07:28 +0200692 *
693 * Type of the deviate operation (used as ::lysp_deviate.mod)
694 *
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200695 * @{
696 */
697#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
698#define LYS_DEV_ADD 2 /**< deviate type add */
699#define LYS_DEV_DELETE 3 /**< deviate type delete */
700#define LYS_DEV_REPLACE 4 /**< deviate type replace */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200701/** @} deviatetypes */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200702
703/**
704 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
705 */
706struct lysp_deviate {
707 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
708 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200709 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200710};
711
712struct lysp_deviate_add {
713 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
714 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200715 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200716 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200717 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200718 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
719 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200720 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
721 uint32_t min; /**< min-elements constraint */
722 uint32_t max; /**< max-elements constraint, 0 means unbounded */
723};
724
725struct lysp_deviate_del {
726 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
727 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200728 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200729 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200730 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200731 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
732 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200733};
734
735struct lysp_deviate_rpl {
736 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
737 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200738 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200739 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200740 const char *units; /**< units of the values */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200741 struct lysp_qname dflt; /**< default value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200742 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
743 uint32_t min; /**< min-elements constraint */
744 uint32_t max; /**< max-elements constraint, 0 means unbounded */
745};
746
747struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200748 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200749 const char *dsc; /**< description statement */
750 const char *ref; /**< reference statement */
Michal Vasko22df3f02020-08-24 13:29:22 +0200751 struct lysp_deviate *deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200752 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200753};
754
Radek Krejci4f28eda2018-11-12 11:46:16 +0100755/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100756 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200757 * @defgroup spnodeflags Parsed schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100758 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200759 * Various flags for parsed schema nodes (used as ::lysp_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100760 *
761 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
762 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200763 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100764 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
765 * 5 - list 10 - input 15 - typedef 20 - deviate
766 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200767 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
768 * 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
769 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200770 * 1 LYS_CONFIG_W |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200771 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
772 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200773 * 2 LYS_CONFIG_R |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200774 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
775 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
776 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
777 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
778 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
779 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
780 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
781 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
782 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
783 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
784 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
785 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
786 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100787 * LYS_FENABLED | | | | | | | | | | | |x| | | | | | | | | | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200788 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
789 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
790 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
791 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
792 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
793 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
794 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
795 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
796 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
797 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
798 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
799 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
800 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
801 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
802 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
803 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
804 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
805 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
806 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200807 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
David Sedlákae4b4512019-08-14 10:45:56 +0200808 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x|
Michal Vasko5297a432020-08-31 12:27:51 +0200809 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
810 * 12 LYS_YIN_ARGUMENT | | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejcif56e2a42019-09-09 14:15:25 +0200811 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100812 *
813 */
814
815/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100816 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200817 * @defgroup scnodeflags Compiled schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100818 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200819 * Various flags for compiled schema nodes (used as ::lysc_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100820 *
Radek Krejci61e042e2019-09-10 15:53:09 +0200821 * 1 - container 6 - anydata/anyxml 11 - identity
822 * 2 - choice 7 - case 12 - extension
823 * 3 - leaf 8 - notification 13 - bitenum
Michal Vasko03ff5a72019-09-11 13:49:33 +0200824 * 4 - leaflist 9 - rpc/action 14 - when
Michal Vaskoecd62de2019-11-13 12:35:11 +0100825 * 5 - list 10 - feature
Radek Krejci4f28eda2018-11-12 11:46:16 +0100826 *
Michal Vaskoecd62de2019-11-13 12:35:11 +0100827 * 1 1 1 1 1
828 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
829 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
830 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | |
831 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
832 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | |
833 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
834 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x|x|x|x| |x|
835 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
836 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x|x|x|x| |x|
837 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
838 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x|x|x|x| |x|
839 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
840 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
841 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
842 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
843 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | |
844 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
845 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
846 * LYS_PRESENCE |x| | | | | | | | | | | | | |
847 * LYS_UNIQUE | | |x| | | | | | | | | | | |
848 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
849 * 9 LYS_KEY | | |x| | | | | | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100850 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
851 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
852 * LYS_ISENUM | | | | | | | | | | | | |x| |
853 * LYS_KEYLESS | | | | |x| | | | | | | | | |
854 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
855 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
856 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
857 * 12 LYS_SET_CONFIG |x|x|x|x|x|x| | | | | | | | |
858 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100859 *
860 */
861
862/**
863 * @defgroup snodeflags Schema nodes flags
Radek Krejci8678fa42020-08-18 16:07:28 +0200864 *
865 * Various flags for schema nodes ([parsed](@ref spnodeflags) as well as [compiled](@ref scnodeflags)).
866 *
Radek Krejci4f28eda2018-11-12 11:46:16 +0100867 * @{
868 */
Michal Vasko1bf09392020-03-27 12:38:10 +0100869#define LYS_CONFIG_W 0x01 /**< config true; also set for input children nodes */
870#define LYS_CONFIG_R 0x02 /**< config false; also set for output and notification children nodes */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200871#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100872#define LYS_STATUS_CURR 0x04 /**< status current; */
873#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
874#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
875#define LYS_STATUS_MASK 0x1C /**< mask for status value */
876#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100877 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
878 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
879 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
880 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100881#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
882 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
883 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100884#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Michal Vaskoc118ae22020-08-06 14:51:09 +0200885#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, but it is not only for explicit presence
886 containers, but also for NP containers with some meaning, applicable only to
887 ::lysc_node_container */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100888#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
889#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 +0200890#define LYS_KEYLESS 0x200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100891#define LYS_FENABLED 0x20 /**< feature enabled flag, applicable only to ::lysp_feature. */
Radek Krejcife909632019-02-12 15:34:42 +0100892#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 +0100893 ::lysc_node_list/::lysp_node_list */
894#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
895 ::lysc_node_list/::lysp_node_list */
896#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
897#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
898#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
899#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200900#define LYS_USED_GRP 0x400 /**< internal flag for validating not-instantiated groupings
901 (resp. do not validate again the instantiated groupings). */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100902#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100903#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200904#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100905
906#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
907#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
908#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
909#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
910#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
911#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
912#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
913#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
914#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
915#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100916#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 +0100917 cases of choice. This information is important for refines, since it is prohibited to make leafs
918 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100919 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
920 between own default or the default values taken from the type. */
921#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 +0100922#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 +0100923
Radek Krejcif56e2a42019-09-09 14:15:25 +0200924#define LYS_SINGLEQUOTED 0x100 /**< flag for single-quoted argument of an extension instance's substatement, only when the source is YANG */
925#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 +0200926
Radek Krejcif56e2a42019-09-09 14:15:25 +0200927#define LYS_YIN_ATTR 0x400 /**< flag to identify YIN attribute parsed as extension's substatement, only when the source is YIN */
928#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 +0200929
Radek Krejci693262f2019-04-29 15:23:20 +0200930#define LYS_ISENUM 0x200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
931
Radek Krejcife909632019-02-12 15:34:42 +0100932#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200933/** @} snodeflags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200934
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200935/**
936 * @brief Generic YANG data node
937 */
938struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100939 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200940 uint16_t nodetype; /**< type of the node (mandatory) */
941 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100942 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200943 const char *name; /**< node name (mandatory) */
944 const char *dsc; /**< description statement */
945 const char *ref; /**< reference statement */
946 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200947 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)),
948 must be qname because of refines */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200949 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200950};
951
952/**
953 * @brief Extension structure of the lysp_node for YANG container
954 */
955struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100956 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200957 uint16_t nodetype; /**< LYS_CONTAINER */
958 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
959 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
960 const char *name; /**< node name (mandatory) */
961 const char *dsc; /**< description statement */
962 const char *ref; /**< reference statement */
963 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200964 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200965 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200966
967 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200968 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200969 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200970 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
971 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200972 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200973 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
974 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200975};
976
977struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100978 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200979 uint16_t nodetype; /**< LYS_LEAF */
980 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
981 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
982 const char *name; /**< node name (mandatory) */
983 const char *dsc; /**< description statement */
984 const char *ref; /**< reference statement */
985 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200986 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200987 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200988
989 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200990 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200991 struct lysp_type type; /**< type of the leaf node (mandatory) */
992 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200993 struct lysp_qname dflt; /**< default value, it may or may not be a qualified name */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200994};
995
996struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100997 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200998 uint16_t nodetype; /**< LYS_LEAFLIST */
999 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1000 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1001 const char *name; /**< node name (mandatory) */
1002 const char *dsc; /**< description statement */
1003 const char *ref; /**< reference statement */
1004 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001005 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001006 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001007
1008 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001009 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001010 struct lysp_type type; /**< type of the leaf node (mandatory) */
1011 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001012 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)), they may or
1013 may not be qualified names */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001014 uint32_t min; /**< min-elements constraint */
1015 uint32_t max; /**< max-elements constraint, 0 means unbounded */
1016};
1017
1018struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001019 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001020 uint16_t nodetype; /**< LYS_LIST */
1021 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1022 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1023 const char *name; /**< node name (mandatory) */
1024 const char *dsc; /**< description statement */
1025 const char *ref; /**< reference statement */
1026 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001027 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001028 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001029
1030 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001031 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001032 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001033 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1034 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001035 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001036 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1037 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001038 struct lysp_qname *uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001039 uint32_t min; /**< min-elements constraint */
1040 uint32_t max; /**< max-elements constraint, 0 means unbounded */
1041};
1042
1043struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001044 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001045 uint16_t nodetype; /**< LYS_CHOICE */
1046 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1047 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1048 const char *name; /**< node name (mandatory) */
1049 const char *dsc; /**< description statement */
1050 const char *ref; /**< reference statement */
1051 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001052 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001053 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001054
1055 /* choice */
1056 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001057 struct lysp_qname dflt; /**< default case */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001058};
1059
1060struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001061 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001062 uint16_t nodetype; /**< LYS_CASE */
1063 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1064 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1065 const char *name; /**< node name (mandatory) */
1066 const char *dsc; /**< description statement */
1067 const char *ref; /**< reference statement */
1068 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001069 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001070 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001071
1072 /* case */
1073 struct lysp_node *child; /**< list of data nodes (linked list) */
1074};
1075
1076struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001077 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001078 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001079 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1080 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1081 const char *name; /**< node name (mandatory) */
1082 const char *dsc; /**< description statement */
1083 const char *ref; /**< reference statement */
1084 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001085 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001086 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001087
1088 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001089 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001090};
1091
1092struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001093 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +02001094 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001095 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1096 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1097 const char *name; /**< grouping name reference (mandatory) */
1098 const char *dsc; /**< description statement */
1099 const char *ref; /**< reference statement */
1100 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001101 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001102 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001103
1104 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001105 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
1106 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001107};
1108
1109/**
1110 * @brief YANG input-stmt and output-stmt
1111 */
1112struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001113 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001114 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001115 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1116 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1117 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001118 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001119 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001120};
1121
1122/**
1123 * @brief YANG rpc-stmt and action-stmt
1124 */
1125struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001126 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vasko1bf09392020-03-27 12:38:10 +01001127 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001128 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001129 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001130 const char *name; /**< grouping name reference (mandatory) */
1131 const char *dsc; /**< description statement */
1132 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001133 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001134 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1135 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1136
1137 /* action */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001138 struct lysp_action_inout input; /**< RPC's/Action's input */
1139 struct lysp_action_inout output; /**< RPC's/Action's output */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001140};
1141
1142/**
1143 * @brief YANG notification-stmt
1144 */
1145struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +01001146 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1147 uint16_t nodetype; /**< LYS_NOTIF */
1148 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001149 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001150 const char *name; /**< grouping name reference (mandatory) */
1151 const char *dsc; /**< description statement */
1152 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001153 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001154 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001155 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001156
1157 /* notif */
1158 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1159 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001160};
1161
1162/**
Radek Krejcif0fceb62018-09-05 14:58:45 +02001163 * @brief supported YANG schema version values
1164 */
1165typedef enum LYS_VERSION {
1166 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
Radek Krejci96e48da2020-09-04 13:18:06 +02001167 LYS_VERSION_1_0 = 1, /**< YANG 1 (1.0) */
Radek Krejcif0fceb62018-09-05 14:58:45 +02001168 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
1169} LYS_VERSION;
1170
1171/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001172 * @brief Printable YANG schema tree structure representing YANG module.
1173 *
1174 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
1175 */
1176struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001177 struct lys_module *mod; /**< covering module structure */
1178
Radek Krejcib7db73a2018-10-24 14:18:40 +02001179 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1180 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001181 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1182 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001183 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1184 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1185 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1186 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1187 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001188 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001189 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1190 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1191 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1192 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001193 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001194
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001195 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001196 uint8_t parsing : 1; /**< flag for circular check */
1197 uint8_t is_submod : 1; /**< always 0 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001198};
1199
1200struct lysp_submodule {
Michal Vaskoc3781c32020-10-06 14:04:08 +02001201 struct lys_module *mod; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001202
1203 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1204 in the list is always the last (newest) revision of the module */
1205 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1206 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
1207 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1208 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1209 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1210 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1211 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
1212 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
1213 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
1214 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1215 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1216 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001217 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001218
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001219 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001220 uint8_t parsing : 1; /**< flag for circular check */
1221 uint8_t is_submod : 1; /**< always 1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001222
Michal Vaskoc3781c32020-10-06 14:04:08 +02001223 uint8_t latest_revision : 2; /**< flag to mark the latest available revision:
Radek Krejci086c7132018-10-26 15:29:04 +02001224 1 - the latest revision in searchdirs was not searched yet and this is the
1225 latest revision in the current context
1226 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001227 const char *name; /**< name of the module (mandatory) */
1228 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1229 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
1230 const char *org; /**< party/company responsible for the module */
1231 const char *contact; /**< contact information for the module */
1232 const char *dsc; /**< description of the module */
1233 const char *ref; /**< cross-reference for the module */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001234};
1235
1236/**
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001237 * @brief Get the parsed module or submodule name.
1238 *
1239 * @param[in] PMOD Parsed module or submodule.
1240 * @return Module or submodule name.
1241 */
1242#define LYSP_MODULE_NAME(PMOD) (PMOD->is_submod ? ((struct lysp_submodule *)PMOD)->name : ((struct lysp_module *)PMOD)->mod->name)
1243
1244/**
1245 * @brief Free the printable YANG schema tree structure. Works for both modules and submodules.
Radek Krejci3f5e3db2018-10-11 15:57:47 +02001246 *
1247 * @param[in] module Printable YANG schema tree structure to free.
1248 */
1249void lysp_module_free(struct lysp_module *module);
1250
1251/**
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001252 * @brief Compiled prefix data pair mapping of prefixes to modules. In case the format is ::LY_PREF_SCHEMA_RESOLVED,
1253 * the expected prefix data is a sized array of these structures.
1254 */
1255struct lysc_prefix {
1256 char *prefix; /**< used prefix */
1257 const struct lys_module *mod; /**< mapping to a module */
1258};
1259
1260/**
Radek Krejci0e59c312019-08-15 15:34:15 +02001261 * @brief Compiled YANG extension-stmt
1262 */
1263struct lysc_ext {
1264 const char *name; /**< extension name */
1265 const char *argument; /**< argument name, NULL if not specified */
Radek Krejci0e59c312019-08-15 15:34:15 +02001266 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1267 struct lyext_plugin *plugin; /**< Plugin implementing the specific extension */
Radek Krejci0935f412019-08-20 16:15:18 +02001268 struct lys_module *module; /**< module structure */
Michal Vasko6f4cbb62020-02-28 11:15:47 +01001269 uint32_t refcount; /**< reference counter since extension definition is shared among all its instances */
Radek Krejci0e59c312019-08-15 15:34:15 +02001270 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
1271};
1272
1273/**
Radek Krejcice8c1592018-10-29 15:35:51 +01001274 * @brief YANG extension instance
1275 */
1276struct lysc_ext_instance {
Radek Krejciad5963b2019-09-06 16:03:05 +02001277 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
1278 this identifies the index of the substatement for this extension instance */
Radek Krejci28681fa2019-09-06 13:08:45 +02001279 struct lys_module *module; /**< module where the extension instantiated is defined */
Radek Krejciad5963b2019-09-06 16:03:05 +02001280 struct lysc_ext *def; /**< pointer to the extension definition */
Radek Krejcice8c1592018-10-29 15:35:51 +01001281 void *parent; /**< pointer to the parent element holding the extension instance(s), use
1282 ::lysc_ext_instance#parent_type to access the schema element */
1283 const char *argument; /**< optional value of the extension's argument */
1284 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +01001285 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001286 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0e59c312019-08-15 15:34:15 +02001287 void *data; /**< private plugins's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +01001288};
1289
1290/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001291 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001292 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001293struct lysc_when {
1294 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko175012e2019-11-06 15:49:14 +01001295 struct lysc_node *context; /**< context node for evaluating the expression, NULL if the context is root node */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001296 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001297 const char *dsc; /**< description */
1298 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001299 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001300 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Michal Vaskoecd62de2019-11-13 12:35:11 +01001301 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS is allowed */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001302};
1303
1304/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001305 * @brief YANG identity-stmt
1306 */
1307struct lysc_ident {
1308 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +01001309 const char *dsc; /**< description */
1310 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001311 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001312 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
1313 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1314 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1315};
1316
1317/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001318 * @defgroup ifftokens if-feature expression tokens
Radek Krejci8678fa42020-08-18 16:07:28 +02001319 * Tokens of if-feature expression used in ::lysc_iffeature.expr.
Radek Krejci151a5b72018-10-19 14:21:44 +02001320 *
1321 * @{
1322 */
1323#define LYS_IFF_NOT 0x00 /**< operand "not" */
1324#define LYS_IFF_AND 0x01 /**< operand "and" */
1325#define LYS_IFF_OR 0x02 /**< operand "or" */
1326#define LYS_IFF_F 0x03 /**< feature */
Radek Krejci2ff0d572020-05-21 15:27:28 +02001327/** @} ifftokens */
Radek Krejci151a5b72018-10-19 14:21:44 +02001328
1329/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001330 * @brief Compiled YANG revision statement
1331 */
1332struct lysc_revision {
1333 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1334 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1335};
1336
Radek Krejci2167ee12018-11-02 16:09:07 +01001337struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001338 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001339 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001340 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1341 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001342 };
Radek Krejci693262f2019-04-29 15:23:20 +02001343 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001344 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1345 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001346 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001347 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001348 const char *dsc; /**< description */
1349 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001350 const char *emsg; /**< error-message */
1351 const char *eapptag; /**< error-app-tag value */
1352 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1353};
1354
1355struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001356 const char *expr; /**< original, not compiled, regular expression */
1357 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001358 const char *dsc; /**< description */
1359 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001360 const char *emsg; /**< error-message */
1361 const char *eapptag; /**< error-app-tag value */
1362 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0f969882020-08-21 16:56:47 +02001363 uint32_t inverted : 1; /**< invert-match flag */
1364 uint32_t refcount : 31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001365};
1366
1367struct lysc_must {
Radek Krejci2167ee12018-11-02 16:09:07 +01001368 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001369 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001370 const char *dsc; /**< description */
1371 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001372 const char *emsg; /**< error-message */
1373 const char *eapptag; /**< error-app-tag value */
1374 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1375};
1376
1377struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001378 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001379 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 +01001380 LY_DATA_TYPE basetype; /**< Base type of the type */
1381 uint32_t refcount; /**< reference counter for type sharing */
1382};
1383
1384struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001385 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001386 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 +01001387 LY_DATA_TYPE basetype; /**< Base type of the type */
1388 uint32_t refcount; /**< reference counter for type sharing */
1389 struct lysc_range *range; /**< Optional range limitation */
1390};
1391
1392struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001393 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001394 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 +01001395 LY_DATA_TYPE basetype; /**< Base type of the type */
1396 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001397 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001398 struct lysc_range *range; /**< Optional range limitation */
1399};
1400
1401struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001402 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001403 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 +01001404 LY_DATA_TYPE basetype; /**< Base type of the type */
1405 uint32_t refcount; /**< reference counter for type sharing */
1406 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001407 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001408};
1409
Radek Krejci693262f2019-04-29 15:23:20 +02001410struct lysc_type_bitenum_item {
1411 const char *name; /**< enumeration identifier */
1412 const char *dsc; /**< description */
1413 const char *ref; /**< reference */
1414 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci693262f2019-04-29 15:23:20 +02001415 union {
1416 int32_t value; /**< integer value associated with the enumeration */
1417 uint32_t position; /**< non-negative integer value associated with the bit */
1418 };
1419 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1420 values are allowed */
1421};
1422
Radek Krejci2167ee12018-11-02 16:09:07 +01001423struct lysc_type_enum {
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 Krejci693262f2019-04-29 15:23:20 +02001428 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1429};
1430
1431struct lysc_type_bits {
1432 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001433 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 +02001434 LY_DATA_TYPE basetype; /**< Base type of the type */
1435 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001436 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1437 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001438};
1439
1440struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001441 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001442 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 +01001443 LY_DATA_TYPE basetype; /**< Base type of the type */
1444 uint32_t refcount; /**< reference counter for type sharing */
Michal Vasko004d3152020-06-11 19:59:22 +02001445 struct lyxp_expr *path; /**< parsed target path, compiled path cannot be stored because of type sharing */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001446 struct lysc_prefix *prefixes; /**< resolved prefixes used in the path */
Radek Krejci412ddfa2018-11-23 11:44:11 +01001447 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001448 uint8_t require_instance; /**< require-instance flag */
1449};
1450
1451struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001452 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001453 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 +01001454 LY_DATA_TYPE basetype; /**< Base type of the type */
1455 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001456 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001457 mandatory (at least 1 item) */
1458};
1459
1460struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001461 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001462 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 +01001463 LY_DATA_TYPE basetype; /**< Base type of the type */
1464 uint32_t refcount; /**< reference counter for type sharing */
1465 uint8_t require_instance; /**< require-instance flag */
1466};
1467
Radek Krejci2167ee12018-11-02 16:09:07 +01001468struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001469 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001470 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 +01001471 LY_DATA_TYPE basetype; /**< Base type of the type */
1472 uint32_t refcount; /**< reference counter for type sharing */
1473 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1474};
1475
1476struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001477 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001478 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 +01001479 LY_DATA_TYPE basetype; /**< Base type of the type */
1480 uint32_t refcount; /**< reference counter for type sharing */
1481 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001482};
1483
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001484struct lysc_action_inout {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001485 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001486 struct lysc_node *data; /**< first child node (linked list) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001487 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1488};
1489
Michal Vasko60ea6352020-06-29 13:39:39 +02001490/**
1491 * @brief Maximum number of hashes stored in a schema node.
1492 */
1493#define LYS_NODE_HASH_COUNT 4
1494
Radek Krejci056d0a82018-12-06 16:57:25 +01001495struct lysc_action {
Michal Vasko1bf09392020-03-27 12:38:10 +01001496 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
Radek Krejci056d0a82018-12-06 16:57:25 +01001497 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001498 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejci95710c92019-02-11 15:49:55 +01001499 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001500 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1501
Radek Krejcifc11bd72019-04-11 16:00:05 +02001502 struct lysc_ext_instance *input_exts; /**< list of the extension instances of input ([sized array](@ref sizedarrays)) */
1503 struct lysc_ext_instance *output_exts; /**< list of the extension instances of outpu ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001504
Radek Krejci056d0a82018-12-06 16:57:25 +01001505 const char *name; /**< action/RPC name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001506 const char *dsc; /**< description */
1507 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001508 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001509
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001510 struct lysc_action_inout input; /**< RPC's/action's input */
1511 struct lysc_action_inout output; /**< RPC's/action's output */
Michal Vaskoceab6dd2020-10-09 16:53:36 +02001512 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001513 void *priv; /** private arbitrary user data, not used by libyang */
1514
Radek Krejci056d0a82018-12-06 16:57:25 +01001515};
1516
1517struct lysc_notif {
1518 uint16_t nodetype; /**< LYS_NOTIF */
1519 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001520 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejci95710c92019-02-11 15:49:55 +01001521 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001522 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1523
Radek Krejcifc11bd72019-04-11 16:00:05 +02001524 struct lysc_node *data; /**< first child node (linked list) */
1525 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1526
Radek Krejci056d0a82018-12-06 16:57:25 +01001527 const char *name; /**< Notification name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001528 const char *dsc; /**< description */
1529 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001530 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskoceab6dd2020-10-09 16:53:36 +02001531 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001532 void *priv; /** private arbitrary user data, not used by libyang */
Radek Krejci056d0a82018-12-06 16:57:25 +01001533};
1534
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001535/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001536 * @brief Compiled YANG data node
1537 */
1538struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001539 uint16_t nodetype; /**< type of the node (mandatory) */
1540 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001541 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001542 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001543 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1544 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1545 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1546 never NULL. If there is no sibling node, pointer points to the node
1547 itself. In case of the first node, this pointer points to the last
1548 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001549 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001550 const char *dsc; /**< description */
1551 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001552 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001553 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001554 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001555};
1556
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001557struct lysc_node_container {
1558 uint16_t nodetype; /**< LYS_CONTAINER */
1559 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001560 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001561 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001562 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1563 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1564 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1565 never NULL. If there is no sibling node, pointer points to the node
1566 itself. In case of the first node, this pointer points to the last
1567 node in the list. */
1568 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001569 const char *dsc; /**< description */
1570 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001571 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001572 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001573 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001574
1575 struct lysc_node *child; /**< first child node (linked list) */
1576 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1577 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1578 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001579};
1580
Radek Krejcia3045382018-11-22 14:30:31 +01001581struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001582 uint16_t nodetype; /**< LYS_CASE */
1583 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001584 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
Radek Krejci056d0a82018-12-06 16:57:25 +01001585 struct lys_module *module; /**< module structure */
Radek Krejci056d0a82018-12-06 16:57:25 +01001586 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1587 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1588 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1589 never NULL. If there is no sibling node, pointer points to the node
1590 itself. In case of the first node, this pointer points to the last
1591 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001592 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001593 const char *dsc; /**< description */
1594 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001595 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001596 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001597 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci056d0a82018-12-06 16:57:25 +01001598
Radek Krejcia3045382018-11-22 14:30:31 +01001599 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 +01001600 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001601};
1602
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001603struct lysc_node_choice {
1604 uint16_t nodetype; /**< LYS_CHOICE */
1605 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001606 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001607 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001608 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1609 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1610 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1611 never NULL. If there is no sibling node, pointer points to the node
1612 itself. In case of the first node, this pointer points to the last
1613 node in the list. */
1614 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001615 const char *dsc; /**< description */
1616 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001617 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001618 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001619 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001620
Radek Krejcia9026eb2018-12-12 16:04:47 +01001621 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1622 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1623 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001624 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001625};
1626
1627struct lysc_node_leaf {
1628 uint16_t nodetype; /**< LYS_LEAF */
1629 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001630 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001631 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001632 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1633 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1634 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1635 never NULL. If there is no sibling node, pointer points to the node
1636 itself. In case of the first node, this pointer points to the last
1637 node in the list. */
1638 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001639 const char *dsc; /**< description */
1640 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001641 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001642 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001643 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001644
1645 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1646 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001647
Radek Krejci4f28eda2018-11-12 11:46:16 +01001648 const char *units; /**< units of the leaf's type */
Radek Krejcia1911222019-07-22 17:24:50 +02001649 struct lyd_value *dflt; /**< default value */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001650};
1651
1652struct lysc_node_leaflist {
1653 uint16_t nodetype; /**< LYS_LEAFLIST */
1654 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001655 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001656 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001657 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1658 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1659 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1660 never NULL. If there is no sibling node, pointer points to the node
1661 itself. In case of the first node, this pointer points to the last
1662 node in the list. */
1663 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001664 const char *dsc; /**< description */
1665 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001666 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001667 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001668 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001669
1670 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1671 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1672
Radek Krejci0e5d8382018-11-28 16:37:53 +01001673 const char *units; /**< units of the leaf's type */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001674 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values */
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001675
Radek Krejci0e5d8382018-11-28 16:37:53 +01001676 uint32_t min; /**< min-elements constraint */
1677 uint32_t max; /**< max-elements constraint */
1678
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001679};
1680
1681struct lysc_node_list {
1682 uint16_t nodetype; /**< LYS_LIST */
1683 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001684 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001685 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001686 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1687 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1688 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1689 never NULL. If there is no sibling node, pointer points to the node
1690 itself. In case of the first node, this pointer points to the last
1691 node in the list. */
1692 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001693 const char *dsc; /**< description */
1694 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001695 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001696 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001697 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001698
1699 struct lysc_node *child; /**< first child node (linked list) */
1700 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1701 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1702 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1703
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001704 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1705 uint32_t min; /**< min-elements constraint */
1706 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001707};
1708
1709struct lysc_node_anydata {
1710 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1711 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001712 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001713 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001714 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1715 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1716 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1717 never NULL. If there is no sibling node, pointer points to the node
1718 itself. In case of the first node, this pointer points to the last
1719 node in the list. */
1720 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001721 const char *dsc; /**< description */
1722 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001723 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001724 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001725 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejci9800fb82018-12-13 14:26:23 +01001726
1727 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001728};
1729
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001730/**
1731 * @brief Compiled YANG schema tree structure representing YANG module.
1732 *
1733 * Semantically validated YANG schema tree for data tree parsing.
1734 * Contains only the necessary information for the data validation.
1735 */
1736struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001737 struct lys_module *mod; /**< covering module structure */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001738
Radek Krejci2a408df2018-10-29 16:32:26 +01001739 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1740 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1741 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001742 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001743};
1744
1745/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001746 * @brief Get the groupings sized array of the given (parsed) schema node.
1747 * Decides the node's type and in case it has a groupings array, returns it.
1748 * @param[in] node Node to examine.
1749 * @return The node's groupings sized array if any, NULL otherwise.
1750 */
1751const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1752
1753/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001754 * @brief Get the typedefs sized array of the given (parsed) schema node.
1755 * Decides the node's type and in case it has a typedefs array, returns it.
1756 * @param[in] node Node to examine.
1757 * @return The node's typedefs sized array if any, NULL otherwise.
1758 */
1759const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1760
1761/**
1762 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1763 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1764 * @param[in] node Node to examine.
1765 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1766 */
1767const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1768
1769/**
1770 * @brief Get the Notifications sized array of the given (parsed) schema node.
1771 * Decides the node's type and in case it has a Notifications array, returns it.
1772 * @param[in] node Node to examine.
1773 * @return The node's Notifications sized array if any, NULL otherwise.
1774 */
1775const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1776
1777/**
1778 * @brief Get the children linked list of the given (parsed) schema node.
1779 * Decides the node's type and in case it has a children list, returns it.
1780 * @param[in] node Node to examine.
1781 * @return The node's children linked list if any, NULL otherwise.
1782 */
1783const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1784
1785/**
1786 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1787 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1788 * @param[in] node Node to examine.
1789 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1790 */
1791const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1792
1793/**
1794 * @brief Get the Notifications sized array of the given (compiled) schema node.
1795 * Decides the node's type and in case it has a Notifications array, returns it.
1796 * @param[in] node Node to examine.
1797 * @return The node's Notifications sized array if any, NULL otherwise.
1798 */
1799const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1800
1801/**
1802 * @brief Get the children linked list of the given (compiled) schema node.
Michal Vasko208a04a2020-10-21 15:17:12 +02001803 * Skips over input and output nodes. To return them, use ::lysc_node_children_full().
Michal Vasko2a668712020-10-21 11:48:09 +02001804 *
Radek Krejci056d0a82018-12-06 16:57:25 +01001805 * @param[in] node Node to examine.
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001806 * @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 +01001807 * @return The node's children linked list if any, NULL otherwise.
1808 */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001809const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Radek Krejci056d0a82018-12-06 16:57:25 +01001810
1811/**
Michal Vasko2a668712020-10-21 11:48:09 +02001812 * @brief Get the children linked list of the given (compiled) schema node.
Michal Vasko208a04a2020-10-21 15:17:12 +02001813 * Returns all children node types including input and output. To skip them, use ::lysc_node_children().
Michal Vasko2a668712020-10-21 11:48:09 +02001814 *
1815 * @param[in] node Node to examine.
1816 * @param[in] flags Config flag to distinguish input (LYS_CONFIG_W) and output (LYS_CONFIG_R) child in case of RPC/action node.
1817 * @return Children linked list if any,
1818 * @return NULL otherwise.
1819 */
Michal Vasko208a04a2020-10-21 15:17:12 +02001820const struct lysc_node *lysc_node_children_full(const struct lysc_node *node, uint16_t flags);
Michal Vasko2a668712020-10-21 11:48:09 +02001821
1822/**
1823 * @brief Get the parent pointer from any type of (compiled) schema node.
Michal Vasko208a04a2020-10-21 15:17:12 +02001824 * Returns input or output for direct descendants of RPC/action nodes.
1825 * To skip them, use ::lysc_node.parent pointer directly.
Michal Vasko2a668712020-10-21 11:48:09 +02001826 *
1827 * @param[in] node Node whose parent to get.
1828 * @return Node parent.
1829 * @return NULL is there is none.
1830 */
Michal Vasko208a04a2020-10-21 15:17:12 +02001831const struct lysc_node *lysc_node_parent_full(const struct lysc_node *node);
Michal Vasko2a668712020-10-21 11:48:09 +02001832
1833/**
Michal Vaskof1ab44f2020-10-22 08:58:32 +02001834 * @brief Callback to be called for every schema node in a DFS traversal.
1835 *
1836 * @param[in] node Current node.
1837 * @param[in] data Arbitrary user data.
1838 * @param[out] dfs_continue Set to true if the current subtree should be skipped and continue with siblings instead.
1839 * @return LY_SUCCESS on success,
1840 * @return LY_ERR value to terminate DFS and return this value.
1841 */
1842typedef LY_ERR (*lysc_dfs_clb)(struct lysc_node *node, void *data, ly_bool *dfs_continue);
1843
1844/**
1845 * @brief DFS traversal of all the schema nodes in a (sub)tree including any actions and nested notifications.
1846 *
1847 * Node with children, actions, and notifications is traversed in this order:
1848 * 1) each child subtree;
1849 * 2) each action subtree;
1850 * 3) each notification subtree.
1851 *
1852 * For algorithm illustration or traversal with actions and notifications skipped, see ::LYSC_TREE_DFS_BEGIN.
1853 *
1854 * @param[in] root Schema root to fully traverse.
1855 * @param[in] dfs_clb Callback to call for each node.
1856 * @param[in] data Arbitrary user data passed to @p dfs_clb.
1857 * @return LY_SUCCESS on success,
1858 * @return LY_ERR value returned by @p dfs_clb.
1859 */
1860LY_ERR lysc_tree_dfs_full(const struct lysc_node *root, lysc_dfs_clb dfs_clb, void *data);
1861
1862/**
1863 * @brief DFS traversal of all the schema nodes in a module including RPCs and notifications.
1864 *
1865 * For more details, see ::lysc_tree_dfs_full().
1866 *
1867 * @param[in] mod Module to fully traverse.
1868 * @param[in] dfs_clb Callback to call for each node.
1869 * @param[in] data Arbitrary user data passed to @p dfs_clb.
1870 * @return LY_SUCCESS on success,
1871 * @return LY_ERR value returned by @p dfs_clb.
1872 */
1873LY_ERR lysc_module_dfs_full(const struct lys_module *mod, lysc_dfs_clb dfs_clb, void *data);
1874
1875/**
Michal Vaskod975f862020-06-23 13:29:28 +02001876 * @brief Examine whether a node is user-ordered list or leaf-list.
1877 *
Radek Krejci8678fa42020-08-18 16:07:28 +02001878 * @param[in] schema Schema node to examine.
Michal Vaskod975f862020-06-23 13:29:28 +02001879 * @return non-zero if it is,
Radek Krejci857189e2020-09-01 13:26:36 +02001880 * @return Boolean value whether the @p node is user-ordered or not.
Michal Vaskod975f862020-06-23 13:29:28 +02001881 */
Radek Krejci857189e2020-09-01 13:26:36 +02001882ly_bool lysc_is_userordered(const struct lysc_node *schema);
Michal Vaskod975f862020-06-23 13:29:28 +02001883
1884/**
Michal Vasko2fd91b92020-07-17 16:39:02 +02001885 * @brief Set a schema private pointer to a user pointer.
1886 *
1887 * @param[in] node Node, whose private field will be assigned. Works also for RPCs, actions, and notifications.
1888 * @param[in] priv Arbitrary user-specified pointer.
Radek Krejciaf9cd802020-10-06 21:59:47 +02001889 * @param[out] prev_priv_p Optional previous private object of the \p node. Note, that
Michal Vasko2fd91b92020-07-17 16:39:02 +02001890 * the caller is in this case responsible (if it is necessary) for freeing the replaced private object.
1891 * @return LY_ERR value.
1892 */
Radek Krejciaf9cd802020-10-06 21:59:47 +02001893LY_ERR lysc_set_private(const struct lysc_node *node, void *priv, void **prev_priv_p);
Michal Vasko2fd91b92020-07-17 16:39:02 +02001894
1895/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001896 * @brief Get how the if-feature statement currently evaluates.
1897 *
1898 * @param[in] iff Compiled if-feature statement to evaluate.
Michal Vasko28d78432020-05-26 13:10:53 +02001899 * @return LY_SUCCESS if the statement evaluates to true,
1900 * @return LY_ENOT if it evaluates to false,
1901 * @return LY_ERR on error.
Radek Krejci151a5b72018-10-19 14:21:44 +02001902 */
Michal Vasko28d78432020-05-26 13:10:53 +02001903LY_ERR lysc_iffeature_value(const struct lysc_iffeature *iff);
Radek Krejci151a5b72018-10-19 14:21:44 +02001904
1905/**
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001906 * @brief Get the next feature in the module or submodules.
Radek Krejci151a5b72018-10-19 14:21:44 +02001907 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001908 * @param[in] last Last returned feature.
1909 * @param[in] pmod Parsed module and submodoules whose features to iterate over.
1910 * @param[in,out] idx Submodule index, set to 0 on first call.
1911 * @return Next found feature, NULL if the last has already been returned.
Radek Krejci151a5b72018-10-19 14:21:44 +02001912 */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001913struct lysp_feature *lysp_feature_next(const struct lysp_feature *last, const struct lysp_module *pmod, uint32_t *idx);
Radek Krejci151a5b72018-10-19 14:21:44 +02001914
Radek Krejcibed13942020-10-19 16:06:28 +02001915/**
1916 * @defgroup findxpathoptions Atomize XPath options
1917 * Options to modify behavior of ::lys_find_xpath() and ::lys_find_xpath_atoms() searching for schema nodes in schema tree.
1918 * @{
1919 */
1920#define LYS_FIND_XP_SCHEMA 0x04 /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */
1921#define LYS_FIND_XP_OUTPUT 0x08 /**< Search RPC/action output nodes instead of input ones. */
1922/*
1923 * }@
1924 */
Michal Vasko072de482020-08-05 13:27:21 +02001925
Radek Krejci151a5b72018-10-19 14:21:44 +02001926/**
Michal Vasko40308e72020-10-20 16:38:40 +02001927 * @brief Get all the schema nodes that are required for @p xpath to be evaluated (atoms).
Michal Vasko519fd602020-05-26 12:17:39 +02001928 *
1929 * @param[in] ctx_node XPath schema context node.
Michal Vasko40308e72020-10-20 16:38:40 +02001930 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_PREF_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02001931 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko519fd602020-05-26 12:17:39 +02001932 * @param[out] set Set of found atoms (schema nodes).
1933 * @return LY_SUCCESS on success, @p set is returned.
Michal Vasko40308e72020-10-20 16:38:40 +02001934 * @return LY_ERR value on error.
Michal Vasko519fd602020-05-26 12:17:39 +02001935 */
Radek Krejcibed13942020-10-19 16:06:28 +02001936LY_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 +02001937
Michal Vasko072de482020-08-05 13:27:21 +02001938/**
Michal Vasko40308e72020-10-20 16:38:40 +02001939 * @brief Get all the schema nodes that are required for @p path to be evaluated (atoms).
1940 *
1941 * @param[in] path Compiled path to use.
1942 * @param[out] set Set of found atoms (schema nodes).
1943 * @return LY_SUCCESS on success, @p set is returned.
1944 * @return LY_ERR value on error.
1945 */
1946LY_ERR lys_find_path_atoms(const struct ly_path *path, struct ly_set **set);
1947
1948/**
1949 * @brief Get all the schema nodes that are required for @p expr to be evaluated (atoms).
Michal Vasko072de482020-08-05 13:27:21 +02001950 *
1951 * @param[in] ctx_node XPath schema context node.
Michal Vasko40308e72020-10-20 16:38:40 +02001952 * @param[in] cur_mod Current module for the expression (where it was "instantiated").
1953 * @param[in] expr Parsed expression to use.
1954 * @param[in] prefixes Sized array of compiled prefixes.
1955 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
1956 * @param[out] set Set of found atoms (schema nodes).
1957 * @return LY_SUCCESS on success, @p set is returned.
1958 * @return LY_ERR value on error.
1959 */
1960LY_ERR lys_find_expr_atoms(const struct lysc_node *ctx_node, const struct lys_module *cur_mod,
1961 const struct lyxp_expr *expr, const struct lysc_prefix *prefixes, uint32_t options, struct ly_set **set);
1962
1963/**
1964 * @brief Evaluate an @p xpath expression on schema nodes.
1965 *
1966 * @param[in] ctx_node XPath schema context node.
1967 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_PREF_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02001968 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko072de482020-08-05 13:27:21 +02001969 * @param[out] set Set of found schema nodes.
1970 * @return LY_SUCCESS on success, @p set is returned.
1971 * @return LY_ERR value if an error occurred.
1972 */
Radek Krejci1deb5be2020-08-26 16:43:36 +02001973LY_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 +02001974
1975/**
Michal Vasko03ff5a72019-09-11 13:49:33 +02001976 * @brief Types of the different schema paths.
1977 */
1978typedef enum {
Michal Vasko65de0402020-08-03 16:34:19 +02001979 LYSC_PATH_LOG, /**< Descriptive path format used in log messages */
1980 LYSC_PATH_DATA /**< Similar to ::LYSC_PATH_LOG except that schema-only nodes (choice, case) are skipped */
Michal Vasko03ff5a72019-09-11 13:49:33 +02001981} LYSC_PATH_TYPE;
1982
1983/**
Radek Krejci327de162019-06-14 12:52:07 +02001984 * @brief Generate path of the given node in the requested format.
1985 *
1986 * @param[in] node Schema path of this node will be generated.
1987 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001988 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
1989 * If NULL, memory for the complete path is allocated.
1990 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02001991 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001992 * 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 +02001993 */
Michal Vasko03ff5a72019-09-11 13:49:33 +02001994char *lysc_path(const struct lysc_node *node, LYSC_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02001995
1996/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001997 * @brief Available YANG schema tree structures representing YANG module.
1998 */
1999struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002000 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
2001 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01002002 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002003 const char *ns; /**< namespace of the module (module - mandatory) */
2004 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
2005 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
2006 const char *org; /**< party/company responsible for the module */
2007 const char *contact; /**< contact information for the module */
2008 const char *dsc; /**< description of the module */
2009 const char *ref; /**< cross-reference for the module */
2010
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002011 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01002012 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
2013 Available only for implemented modules. */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002014
Radek Krejci80d281e2020-09-14 17:42:54 +02002015 struct lysc_ident *identities; /**< List of compiled identities of the module ([sized array](@ref sizedarrays))
2016 Identities are outside the compiled tree to allow their linkage to the identities from
2017 the implemented modules. This avoids problems when the module became implemented in
2018 future (no matter if implicitly via augment/deviate or explicitly via
2019 ::lys_set_implemented()). Note that if the module is not implemented (compiled), the
2020 identities cannot be instantiated in data (in identityrefs). */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002021
2022 struct lys_module **augmented_by;/**< List of modules that augment this module ([sized array](@ref sizedarrays)) */
2023 struct lys_module **deviated_by; /**< List of modules that deviate this module ([sized array](@ref sizedarrays)) */
2024
Michal Vasko89b5c072020-10-06 13:52:44 +02002025 ly_bool implemented; /**< flag if the module is implemented, not just imported */
Radek Krejci95710c92019-02-11 15:49:55 +01002026 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002027 1 - the latest revision in searchdirs was not searched yet and this is the
2028 latest revision in the current context
2029 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002030};
2031
Radek Krejci151a5b72018-10-19 14:21:44 +02002032/**
Michal Vasko82c31e62020-07-17 15:30:40 +02002033 * @brief Get the current real status of the specified feature in the module.
2034 *
2035 * If the feature is enabled, but some of its if-features are false, the feature is considered
2036 * disabled.
Radek Krejci151a5b72018-10-19 14:21:44 +02002037 *
2038 * @param[in] module Module where the feature is defined.
2039 * @param[in] feature Name of the feature to inspect.
Michal Vasko82c31e62020-07-17 15:30:40 +02002040 * @return LY_SUCCESS if the feature is enabled,
2041 * @return LY_ENOT if the feature is disabled,
2042 * @return LY_ENOTFOUND if the feature was not found.
Radek Krejci151a5b72018-10-19 14:21:44 +02002043 */
Michal Vasko82c31e62020-07-17 15:30:40 +02002044LY_ERR lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02002045
2046/**
Radek Krejcia3045382018-11-22 14:30:31 +01002047 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
2048 * be from an augment.
2049 *
Radek Krejci8678fa42020-08-18 16:07:28 +02002050 * ::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 +01002051 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
2052 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
2053 * \p parent and \p module parameters.
2054 *
2055 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
2056 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
2057 * all the schema nodes are iteratively returned.
2058 *
2059 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
2060 * @param[in] parent Parent of the subtree where the function starts processing.
2061 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
2062 * module must be specified.
2063 * @param[in] options [ORed options](@ref sgetnextflags).
2064 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
2065 */
2066const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002067 const struct lysc_module *module, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002068
2069/**
Radek Krejci8678fa42020-08-18 16:07:28 +02002070 * @defgroup sgetnextflags Options for ::lys_getnext().
2071 *
2072 * Various options setting behavior of ::lys_getnext().
2073 *
Radek Krejcia3045382018-11-22 14:30:31 +01002074 * @{
2075 */
Radek Krejci8678fa42020-08-18 16:07:28 +02002076#define LYS_GETNEXT_WITHCHOICE 0x01 /**< ::lys_getnext() option to allow returning #LYS_CHOICE nodes instead of looking into them */
2077#define LYS_GETNEXT_NOCHOICE 0x02 /**< ::lys_getnext() option to ignore (kind of conditional) nodes within choice node */
2078#define LYS_GETNEXT_WITHCASE 0x04 /**< ::lys_getnext() option to allow returning #LYS_CASE nodes instead of looking into them */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002079#define LYS_GETNEXT_INTONPCONT 0x08 /**< ::lys_getnext() option to look into non-presence container, instead of returning container itself */
2080#define LYS_GETNEXT_OUTPUT 0x10 /**< ::lys_getnext() option to provide RPC's/action's output schema nodes instead of input schema nodes
Radek Krejci6eeb58f2019-02-22 16:29:37 +01002081 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01002082/** @} sgetnextflags */
2083
2084/**
2085 * @brief Get child node according to the specified criteria.
2086 *
2087 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
2088 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
2089 * @param[in] name Name of the node to find.
2090 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
2091 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
2092 * Used as a bitmask, so multiple nodetypes can be specified.
2093 * @param[in] options [ORed options](@ref sgetnextflags).
2094 * @return Found node if any.
2095 */
Michal Vaskoe444f752020-02-10 12:20:06 +01002096const struct lysc_node *lys_find_child(const struct lysc_node *parent, const struct lys_module *module,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002097 const char *name, size_t name_len, uint16_t nodetype, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002098
2099/**
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002100 * @brief Make the specific module implemented.
2101 *
2102 * @param[in] mod Module to make implemented. It is not an error
2103 * to provide already implemented module, it just does nothing.
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002104 * @param[in] features Optional array of features ended with NULL to be enabled if the module is being implemented.
2105 * NULL for all features disabled and '*' for all enabled.
Michal Vaskoe444f752020-02-10 12:20:06 +01002106 * @return LY_SUCCESS on success.
2107 * @return LY_EDENIED in case the context contains some other revision of the same module which is already implemented.
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002108 * @return LY_ERR on other errors during module compilation.
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002109 */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002110LY_ERR lys_set_implemented(struct lys_module *mod, const char **features);
Radek Krejcia3045382018-11-22 14:30:31 +01002111
Radek Krejci084289f2019-07-09 17:35:30 +02002112/**
2113 * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
2114 *
2115 * 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 +02002116 * require-instance restriction), use ::lyd_value_validate().
Radek Krejci084289f2019-07-09 17:35:30 +02002117 *
2118 * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
2119 * @param[in] node Schema node for the @p value.
Michal Vaskof937cfe2020-08-03 16:07:12 +02002120 * @param[in] value String value to be checked, expected to be in JSON format.
Radek Krejci084289f2019-07-09 17:35:30 +02002121 * @param[in] value_len Length of the given @p value (mandatory).
Radek Krejci084289f2019-07-09 17:35:30 +02002122 * @return LY_SUCCESS on success
2123 * @return LY_ERR value if an error occurred.
2124 */
Michal Vaskof937cfe2020-08-03 16:07:12 +02002125LY_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 +02002126
Radek Krejci0935f412019-08-20 16:15:18 +02002127/**
2128 * @brief Stringify schema nodetype.
Michal Vaskod43d71a2020-08-07 14:54:58 +02002129 *
Radek Krejci0935f412019-08-20 16:15:18 +02002130 * @param[in] nodetype Nodetype to stringify.
2131 * @return Constant string with the name of the node's type.
2132 */
2133const char *lys_nodetype2str(uint16_t nodetype);
2134
Michal Vaskod43d71a2020-08-07 14:54:58 +02002135/**
2136 * @brief Getter for original XPath expression from a parsed expression.
2137 *
2138 * @param[in] path Parsed expression.
2139 * @return Original string expression.
2140 */
2141const char *lyxp_get_expr(const struct lyxp_expr *path);
2142
Radek Krejci2ff0d572020-05-21 15:27:28 +02002143/** @} schematree */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002144
Radek Krejci70853c52018-10-15 14:46:16 +02002145#ifdef __cplusplus
2146}
2147#endif
2148
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002149#endif /* LY_TREE_SCHEMA_H_ */