blob: 47307c93906b9d43173b5cc0f28ad652bc869beb [file] [log] [blame]
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001/**
2 * @file tree_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief libyang representation of YANG schema trees.
5 *
6 * Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_TREE_SCHEMA_H_
16#define LY_TREE_SCHEMA_H_
17
Radek Krejci54579462019-04-30 12:47:06 +020018#define PCRE2_CODE_UNIT_WIDTH 8
19
20#include <pcre2.h>
Radek Krejci535ea9f2020-05-29 16:01:05 +020021
Radek Krejci5aeea3a2018-09-05 13:29:36 +020022#include <stdint.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020023#include <stdio.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020024
Radek Krejcie7b95092019-05-15 11:03:07 +020025#include "log.h"
26#include "tree.h"
Radek Krejcice8c1592018-10-29 15:35:51 +010027
Radek Krejci70853c52018-10-15 14:46:16 +020028#ifdef __cplusplus
29extern "C" {
30#endif
31
Radek Krejcica376bd2020-06-11 16:04:06 +020032struct ly_ctx;
Radek Krejci47fab892020-11-05 17:02:41 +010033struct ly_path;
Radek Krejcica376bd2020-06-11 16:04:06 +020034struct ly_set;
Radek Krejci47fab892020-11-05 17:02:41 +010035struct lys_module;
36struct lysc_node;
37struct lyxp_expr;
Radek Krejcica376bd2020-06-11 16:04:06 +020038
Radek Krejci5aeea3a2018-09-05 13:29:36 +020039/**
Radek Krejci8678fa42020-08-18 16:07:28 +020040 * @page howtoSchema YANG Modules
41 *
42 * To be able to work with YANG data instances, libyang has to represent YANG data models. All the processed modules are stored
43 * in libyang [context](@ref howtoContext) and loaded using [parser functions](@ref howtoSchemaParsers). It means, that there is
44 * no way to create/change YANG module programmatically. However, all the YANG model definitions are available and can be examined
45 * through the C structures. All the context's modules together form YANG Schema for the data being instantiated.
46 *
47 * Any YANG module is represented as ::lys_module. In fact, the module is represented in two different formats. As ::lys_module.parsed,
48 * there is a parsed schema reflecting the source YANG module. It is exactly what is read from the input. This format is good for
49 * converting from one format to another (YANG to YIN and vice versa), but it is not very useful for validating/manipulating YANG
50 * data. Therefore, there is ::lys_module.compiled storing the compiled YANG module. It is based on the parsed module, but all the
51 * references are resolved. It means that, for example, there are no `grouping`s or `typedef`s since they are supposed to be placed instead of
52 * `uses` or `type` references. This split also means, that the YANG module is fully validated after compilation of the parsed
53 * representation of the module. YANG submodules are available only in the parsed representation. When a submodule is compiled, it
54 * is fully integrated into its main module.
55 *
56 * The context can contain even modules without the compiled representation. Such modules are still useful as imports of other
57 * modules. The grouping or typedef definition can be even compiled into the importing modules. This is actually the main
58 * difference between the imported and implemented modules in the libyang context. The implemented modules are compiled while the
59 * imported modules are only parsed.
60 *
Radek Krejcib100b192020-10-26 08:37:45 +010061 * By default, the module is implemented (and compiled) in case it is explicitly loaded or referenced in another module as
62 * target of leafref, augment or deviation. This behavior can be changed via context options ::LY_CTX_ALL_IMPLEMENTED, when
63 * all the modules in the context are marked as implemented (note the problem with multiple revisions of a single module),
64 * or by ::LY_CTX_REF_IMPLEMENTED option, extending the set of references making the module implemented by when, must and
65 * default statements.
Radek Krejci8678fa42020-08-18 16:07:28 +020066 *
67 * All modules with deviation definition are always marked as implemented. The imported (not implemented) module can be set implemented by ::lys_set_implemented(). But
68 * the implemented module cannot be changed back to just imported module. Note also that only one revision of a specific module
69 * can be implemented in a single context. The imported modules are used only as a
70 * source of definitions for types and groupings for uses statements. The data in such modules are ignored - caller
71 * is not allowed to create the data (including instantiating identities) defined in the model via data parsers,
72 * the default nodes are not added into any data tree and mandatory nodes are not checked in the data trees.
73 *
Michal Vasko14ed9cd2021-01-28 14:16:25 +010074 * The compiled schema tree nodes are able to hold private objects (::lysc_node.priv as a pointer to a structure,
75 * function, variable, ...) used by a caller application.
Radek Krejci8678fa42020-08-18 16:07:28 +020076 * Note that the object is not freed by libyang when the context is being destroyed. So the caller is responsible
77 * for freeing the provided structure after the context is destroyed or the private pointer is set to NULL in
78 * appropriate schema nodes where the object was previously set. This can be automated via destructor function
79 * to free these private objects. The destructor is passed to the ::ly_ctx_destroy() function.
80 *
81 * Despite all the schema structures and their members are available as part of the libyang API and callers can use
82 * it to navigate through the schema tree structure or to obtain various information, we recommend to use the following
83 * macros for the specific actions.
84 * - ::LYSC_TREE_DFS_BEGIN and ::LYSC_TREE_DFS_END to traverse the schema tree (depth-first).
85 * - ::LY_LIST_FOR and ::LY_ARRAY_FOR as described on @ref howtoStructures page.
86 *
87 * Further information about modules handling can be found on the following pages:
88 * - @subpage howtoSchemaParsers
89 * - @subpage howtoSchemaFeatures
90 * - @subpage howtoPlugins
91 * - @subpage howtoSchemaPrinters
92 *
93 * \note There are many functions to access information from the schema trees. Details are available in
94 * the [Schema Tree module](@ref schematree).
95 *
96 * For information about difference between implemented and imported modules, see the
97 * [context description](@ref howtoContext).
98 *
99 * Functions List (not assigned to above subsections)
100 * --------------------------------------------------
101 * - ::lys_getnext()
102 * - ::lys_nodetype2str()
103 * - ::lys_set_implemented()
104 * - ::lys_value_validate()
105 *
Michal Vaskod5cfa6e2020-11-23 16:56:08 +0100106 * - ::lysc_has_when()
107 *
Michal Vasko544e58a2021-01-28 14:33:41 +0100108 * - ::lysc_node_child()
Radek Krejci8678fa42020-08-18 16:07:28 +0200109 * - ::lysc_node_actions()
110 * - ::lysc_node_notifs()
111 *
Michal Vasko544e58a2021-01-28 14:33:41 +0100112 * - ::lysp_node_child()
Radek Krejci8678fa42020-08-18 16:07:28 +0200113 * - ::lysp_node_actions()
114 * - ::lysp_node_notifs()
115 * - ::lysp_node_groupings()
116 * - ::lysp_node_typedefs()
117 */
118
119/**
120 * @page howtoSchemaFeatures YANG Features
121 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100122 * YANG feature statement is an important part of the language which can significantly affect the meaning of the schemas.
123 * Modifying features may have similar effects as loading/removing schema from the context so it is limited to context
124 * preparation period before working with data. YANG features, respectively their use in if-feature
125 * statements, are evaluated as part of schema compilation so a feature-specific compiled schema tree is generated
126 * as a result.
Radek Krejci8678fa42020-08-18 16:07:28 +0200127 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100128 * To enable any features, they must currently be specified when implementing a new schema with ::lys_parse() or
129 * ::ly_ctx_load_module(). To later examine what the status of a feature is, check its ::LYS_FENABLED flag or
130 * 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 +0200131 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100132 * To iterate over all features of a particular YANG module, use ::lysp_feature_next().
Radek Krejci8678fa42020-08-18 16:07:28 +0200133 *
134 * Note, that the feature's state can affect some of the output formats (e.g. Tree format).
135 *
136 * Functions List
137 * --------------
Radek Krejci8678fa42020-08-18 16:07:28 +0200138 * - ::lys_feature_value()
Radek Krejci8678fa42020-08-18 16:07:28 +0200139 * - ::lysc_iffeature_value()
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100140 * - ::lysp_feature_next()
Radek Krejci8678fa42020-08-18 16:07:28 +0200141 */
142
143/**
Radek Krejci2ff0d572020-05-21 15:27:28 +0200144 * @ingroup trees
Radek Krejci8678fa42020-08-18 16:07:28 +0200145 * @defgroup schematree Schema Tree
Radek Krejci2ff0d572020-05-21 15:27:28 +0200146 * @{
147 *
148 * Data structures and functions to manipulate and access schema tree.
149 */
150
Michal Vasko64246d82020-08-19 12:35:00 +0200151/* *INDENT-OFF* */
152
Radek Krejci2ff0d572020-05-21 15:27:28 +0200153/**
Michal Vasko208a04a2020-10-21 15:17:12 +0200154 * @brief Macro to iterate via all elements in a schema (sub)tree including input and output.
155 * Note that __actions__ and __notifications__ of traversed nodes __are ignored__! To traverse
156 * on all the nodes including those, use ::lysc_tree_dfs_full() instead.
157 *
158 * 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 +0200159 *
160 * The function follows deep-first search algorithm:
161 * <pre>
162 * 1
163 * / \
164 * 2 4
165 * / / \
166 * 3 5 6
167 * </pre>
168 *
169 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
Radek Krejci2a9fc652021-01-22 17:44:34 +0100170 * START can be any of the lysc_node* types (including lysc_node_action and lysc_node_notif),
Radek Krejci0935f412019-08-20 16:15:18 +0200171 * ELEM variable must be of the struct lysc_node* type.
172 *
173 * To skip a particular subtree, instead of the continue statement, set LYSC_TREE_DFS_continue
174 * variable to non-zero value.
175 *
176 * Use with opening curly bracket '{' after the macro.
177 *
178 * @param START Pointer to the starting element processed first.
179 * @param ELEM Iterator intended for use in the block.
180 */
181#define LYSC_TREE_DFS_BEGIN(START, ELEM) \
Radek Krejci857189e2020-09-01 13:26:36 +0200182 { ly_bool LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
Michal Vasko14ed9cd2021-01-28 14:16:25 +0100183 for ((ELEM) = (LYSC_TREE_DFS_next) = (struct lysc_node *)(START); \
Radek Krejci0935f412019-08-20 16:15:18 +0200184 (ELEM); \
185 (ELEM) = (LYSC_TREE_DFS_next), LYSC_TREE_DFS_continue = 0)
186
187/**
188 * @brief Macro to iterate via all elements in a (sub)tree. This is the closing part
189 * to the #LYSC_TREE_DFS_BEGIN - they always have to be used together.
190 *
191 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
Radek Krejci2a9fc652021-01-22 17:44:34 +0100192 * START can be a pointer to any of the lysc_node* types (including lysc_node_action and lysc_node_notif),
Radek Krejci0935f412019-08-20 16:15:18 +0200193 * ELEM variable must be pointer to the lysc_node type.
194 *
195 * Use with closing curly bracket '}' after the macro.
196 *
197 * @param START Pointer to the starting element processed first.
198 * @param ELEM Iterator intended for use in the block.
199 */
Radek Krejci0935f412019-08-20 16:15:18 +0200200#define LYSC_TREE_DFS_END(START, ELEM) \
201 /* select element for the next run - children first */ \
202 if (LYSC_TREE_DFS_continue) { \
203 (LYSC_TREE_DFS_next) = NULL; \
204 } else { \
Michal Vasko544e58a2021-01-28 14:33:41 +0100205 (LYSC_TREE_DFS_next) = (struct lysc_node *)lysc_node_child(ELEM); \
Michal Vasko208a04a2020-10-21 15:17:12 +0200206 } \
Radek Krejci0935f412019-08-20 16:15:18 +0200207 if (!(LYSC_TREE_DFS_next)) { \
Michal Vasko208a04a2020-10-21 15:17:12 +0200208 /* no children, try siblings */ \
209 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
Radek Krejci0935f412019-08-20 16:15:18 +0200210 } \
211 while (!(LYSC_TREE_DFS_next)) { \
212 /* parent is already processed, go to its sibling */ \
Radek Krejci7d95fbb2021-01-26 17:33:13 +0100213 (ELEM) = (ELEM)->parent; \
Michal Vasko208a04a2020-10-21 15:17:12 +0200214 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
215 } }
216
217/**
218 * @brief Helper macro for #LYSC_TREE_DFS_END, should not be used directly!
219 */
220#define _LYSC_TREE_DFS_NEXT(START, ELEM, NEXT) \
221 if ((ELEM) == (struct lysc_node *)(START)) { \
222 /* we are done, no next element to process */ \
223 break; \
224 } \
Michal Vasko544e58a2021-01-28 14:33:41 +0100225 (NEXT) = (ELEM)->next;
Radek Krejci0935f412019-08-20 16:15:18 +0200226
Michal Vasko64246d82020-08-19 12:35:00 +0200227/* *INDENT-ON* */
228
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200229#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
230
Michal Vasko7f45cf22020-10-01 12:49:44 +0200231#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
232#define LYS_CONTAINER 0x0001 /**< container statement node */
233#define LYS_CHOICE 0x0002 /**< choice statement node */
234#define LYS_LEAF 0x0004 /**< leaf statement node */
235#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
236#define LYS_LIST 0x0010 /**< list statement node */
237#define LYS_ANYXML 0x0020 /**< anyxml statement node */
238#define LYS_ANYDATA 0x0060 /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
239#define LYS_CASE 0x0080 /**< case statement node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200240
Michal Vasko7f45cf22020-10-01 12:49:44 +0200241#define LYS_RPC 0x0100 /**< RPC statement node */
242#define LYS_ACTION 0x0200 /**< action statement node */
243#define LYS_NOTIF 0x0400 /**< notification statement node */
Radek Krejcie7b95092019-05-15 11:03:07 +0200244
Michal Vasko7f45cf22020-10-01 12:49:44 +0200245#define LYS_USES 0x0800 /**< uses statement node */
246#define LYS_INPUT 0x1000 /**< RPC/action input node */
247#define LYS_OUTPUT 0x2000 /**< RPC/action output node */
248#define LYS_GROUPING 0x4000
249#define LYS_AUGMENT 0x8000
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100250
Radek Krejcif13b87b2020-12-01 22:02:17 +0100251#define LYS_NODETYPE_MASK 0xffff /**< Mask for nodetypes, the value is limited for 16 bits */
252
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200253/**
Radek Krejcid6b76452019-09-03 17:03:03 +0200254 * @brief List of YANG statements
255 */
256enum ly_stmt {
257 LY_STMT_NONE = 0,
Radek Krejcieccf6602021-02-05 19:42:54 +0100258 LY_STMT_ACTION, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node_action *`.
259 Note that due to compatibility with `struct lysc_node *`, the compiled actions can be actually
260 mixed in the linked list with other ::lysc_node based nodes if the storage is shared. */
261 LY_STMT_ANYDATA, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
262 Note that due to ::lysc_node compatibility the anydata can be actually mixed in
263 the linked list with other ::lysc_node based nodes if the storage is shared. */
264 LY_STMT_ANYXML, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
265 Note that due to ::lysc_node compatibility the anyxml can be actually mixed in
266 the linked list with other ::lysc_node based nodes if the storage is shared. */
Radek Krejcid6b76452019-09-03 17:03:03 +0200267 LY_STMT_ARGUMENT,
Radek Krejcieccf6602021-02-05 19:42:54 +0100268 LY_STMT_ARG_TEXT,
269 LY_STMT_ARG_VALUE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200270 LY_STMT_AUGMENT,
271 LY_STMT_BASE,
272 LY_STMT_BELONGS_TO,
273 LY_STMT_BIT,
Radek Krejcieccf6602021-02-05 19:42:54 +0100274 LY_STMT_CASE, /**< TODO is it possible to compile cases without the parent choice? */
275 LY_STMT_CHOICE, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
276 Note that due to ::lysc_node compatibility the choice can be actually mixed in
277 the linked list with other ::lysc_node based nodes if the storage is shared. */
278 LY_STMT_CONFIG, /**< in ::lysc_ext_substmt.storage stored as a pointer to `uint16_t`, only cardinality < #LY_STMT_CARD_SOME is allowed */
Radek Krejcid6b76452019-09-03 17:03:03 +0200279 LY_STMT_CONTACT,
Radek Krejcieccf6602021-02-05 19:42:54 +0100280 LY_STMT_CONTAINER, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
281 Note that due to ::lysc_node compatibility the container can be actually mixed in
282 the linked list with other ::lysc_node based nodes if the storage is shared. */
283 LY_STMT_DEFAULT,
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,
Radek Krejcieccf6602021-02-05 19:42:54 +0100291 LY_STMT_EXTENSION_INSTANCE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200292 LY_STMT_FEATURE,
293 LY_STMT_FRACTION_DIGITS,
294 LY_STMT_GROUPING,
295 LY_STMT_IDENTITY,
Radek Krejci8678fa42020-08-18 16:07:28 +0200296 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 +0200297 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_iffeature *` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200298 LY_STMT_IMPORT,
299 LY_STMT_INCLUDE,
300 LY_STMT_INPUT,
301 LY_STMT_KEY,
302 LY_STMT_LEAF,
303 LY_STMT_LEAF_LIST,
304 LY_STMT_LENGTH,
Radek Krejcieccf6602021-02-05 19:42:54 +0100305 LY_STMT_LIST, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
306 Note that due to ::lysc_node compatibility the list can be actually mixed in
307 the linked list with other ::lysc_node based nodes if the storage is shared. */
308 LY_STMT_MANDATORY, /**< in ::lysc_ext_substmt.storage stored as a pointer to `uint16_t`, only cardinality < #LY_STMT_CARD_SOME is allowed */
Radek Krejcid6b76452019-09-03 17:03:03 +0200309 LY_STMT_MAX_ELEMENTS,
310 LY_STMT_MIN_ELEMENTS,
311 LY_STMT_MODIFIER,
312 LY_STMT_MODULE,
313 LY_STMT_MUST,
314 LY_STMT_NAMESPACE,
315 LY_STMT_NOTIFICATION,
316 LY_STMT_ORDERED_BY,
317 LY_STMT_ORGANIZATION,
318 LY_STMT_OUTPUT,
319 LY_STMT_PATH,
320 LY_STMT_PATTERN,
321 LY_STMT_POSITION,
322 LY_STMT_PREFIX,
323 LY_STMT_PRESENCE,
324 LY_STMT_RANGE,
325 LY_STMT_REFERENCE,
326 LY_STMT_REFINE,
327 LY_STMT_REQUIRE_INSTANCE,
328 LY_STMT_REVISION,
329 LY_STMT_REVISION_DATE,
Radek Krejcieccf6602021-02-05 19:42:54 +0100330 LY_STMT_RPC, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node_action *`.
331 Note that due to compatibility with `struct lysc_node *`, the compiled RPCs can be actually
332 mixed in the linked list with other ::lysc_node based nodes if the storage is shared. */
333 LY_STMT_STATUS, /**< in ::lysc_ext_substmt.storage stored as a pointer to `uint16_t`, only cardinality < #LY_STMT_CARD_SOME is allowed */
Radek Krejcid6b76452019-09-03 17:03:03 +0200334 LY_STMT_SUBMODULE,
Radek Krejcieccf6602021-02-05 19:42:54 +0100335 LY_STMT_SYNTAX_SEMICOLON,
336 LY_STMT_SYNTAX_LEFT_BRACE,
337 LY_STMT_SYNTAX_RIGHT_BRACE,
338 LY_STMT_TYPE, /**< in ::lysc_ext_substmt.storage stored as a pointer to `struct lysc_type *` (cardinality < #LY_STMT_CARD_SOME)
339 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_type **` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200340 LY_STMT_TYPEDEF,
341 LY_STMT_UNIQUE,
Radek Krejcieccf6602021-02-05 19:42:54 +0100342 LY_STMT_UNITS, /**< in ::lysc_ext_substmt.storage stored as a pointer to `const char *` (cardinality < #LY_STMT_CARD_SOME)
343 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200344 LY_STMT_USES,
345 LY_STMT_VALUE,
346 LY_STMT_WHEN,
347 LY_STMT_YANG_VERSION,
Radek Krejcieccf6602021-02-05 19:42:54 +0100348 LY_STMT_YIN_ELEMENT
Radek Krejcid6b76452019-09-03 17:03:03 +0200349};
350
351/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200352 * @brief Extension instance structure parent enumeration
353 */
354typedef enum {
Radek Krejci0935f412019-08-20 16:15:18 +0200355 LYEXT_PAR_MODULE, /**< ::lysc_module */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100356 LYEXT_PAR_NODE, /**< ::lysc_node (and the derived structures including ::lysc_node_action and ::lysc_node_notif) */
357 LYEXT_PAR_INPUT, /**< ::lysc_node_action_inout */
358 LYEXT_PAR_OUTPUT, /**< ::lysc_node_action_inout */
Radek Krejci0935f412019-08-20 16:15:18 +0200359 LYEXT_PAR_TYPE, /**< ::lysc_type */
360 LYEXT_PAR_TYPE_BIT, /**< ::lysc_type_bitenum_item */
361 LYEXT_PAR_TYPE_ENUM, /**< ::lysc_type_bitenum_item */
Radek Krejci0935f412019-08-20 16:15:18 +0200362 LYEXT_PAR_MUST, /**< ::lysc_must */
363 LYEXT_PAR_PATTERN, /**< ::lysc_pattern */
364 LYEXT_PAR_LENGTH, /**< ::lysc_range */
365 LYEXT_PAR_RANGE, /**< ::lysc_range */
366 LYEXT_PAR_WHEN, /**< ::lysc_when */
367 LYEXT_PAR_IDENT, /**< ::lysc_ident */
368 LYEXT_PAR_EXT, /**< ::lysc_ext */
Michal Vasko69730152020-10-09 16:30:07 +0200369 LYEXT_PAR_IMPORT /**< ::lysp_import */
Radek Krejcif13b87b2020-12-01 22:02:17 +0100370#if 0
371 LYEXT_PAR_TPDF, /**< ::lysp_tpdf */
372 LYEXT_PAR_EXTINST, /**< ::lysp_ext_instance */
373 LYEXT_PAR_REFINE, /**< ::lysp_refine */
374 LYEXT_PAR_DEVIATION, /**< ::lysp_deviation */
375 LYEXT_PAR_DEVIATE, /**< ::lysp_deviate */
376 LYEXT_PAR_INCLUDE, /**< ::lysp_include */
377 LYEXT_PAR_REVISION /**< ::lysp_revision */
378#endif
Radek Krejci0e59c312019-08-15 15:34:15 +0200379} LYEXT_PARENT;
380
381/**
Radek Krejci0935f412019-08-20 16:15:18 +0200382 * @brief Stringify extension instance parent type.
383 * @param[in] type Parent type to stringify.
384 * @return Constant string with the name of the parent statement.
385 */
386const char *lyext_parent2str(LYEXT_PARENT type);
387
388/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200389 * @brief Enum of substatements in which extension instances can appear.
390 */
391typedef enum {
Radek Krejcieccf6602021-02-05 19:42:54 +0100392 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
393 LYEXT_SUBSTMT_ARGUMENT = LY_STMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
394 LYEXT_SUBSTMT_BASE = LY_STMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
395 LYEXT_SUBSTMT_BELONGS_TO = LY_STMT_BELONGS_TO, /**< extension of the belongs-to statement, can appear in lys_submodule */
396 LYEXT_SUBSTMT_CONFIG = LY_STMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
397 LYEXT_SUBSTMT_CONTACT = LY_STMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
398 LYEXT_SUBSTMT_DEFAULT = LY_STMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
399 lys_node_choice and lys_deviate */
400 LYEXT_SUBSTMT_DESCRIPTION = LY_STMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
401 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
402 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
403 LYEXT_SUBSTMT_ERROR_APP_TAG = LY_STMT_ERROR_APP_TAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
404 LYEXT_SUBSTMT_ERROR_MESSAGE = LY_STMT_ERROR_MESSAGE, /**< extension of the error-message statement, can appear in lys_restr */
405 LYEXT_SUBSTMT_FRACTION_DIGITS = LY_STMT_FRACTION_DIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
406 LYEXT_SUBSTMT_IF_FEATURE = LY_STMT_IF_FEATURE, /**< extension of the if-feature statement */
407 LYEXT_SUBSTMT_KEY = LY_STMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
408 LYEXT_SUBSTMT_MANDATORY = LY_STMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
409 lys_node_anydata and lys_deviate */
410 LYEXT_SUBSTMT_MAX_ELEMENTS = LY_STMT_MAX_ELEMENTS, /**< extension of the max-elements statement, can appear in lys_node_list,
411 lys_node_leaflist and lys_deviate */
412 LYEXT_SUBSTMT_MIN_ELEMENTS = LY_STMT_MIN_ELEMENTS, /**< extension of the min-elements statement, can appear in lys_node_list,
413 lys_node_leaflist and lys_deviate */
414 LYEXT_SUBSTMT_MODIFIER = LY_STMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
415 LYEXT_SUBSTMT_NAMESPACE = LY_STMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
416 LYEXT_SUBSTMT_ORDERED_BY = LY_STMT_ORDERED_BY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
417 LYEXT_SUBSTMT_ORGANIZATION = LY_STMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
418 LYEXT_SUBSTMT_PATH = LY_STMT_PATH, /**< extension of the path statement, can appear in lys_type */
419 LYEXT_SUBSTMT_POSITION = LY_STMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
420 LYEXT_SUBSTMT_PREFIX = LY_STMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
421 belongs-to's prefix) and lys_import */
422 LYEXT_SUBSTMT_PRESENCE = LY_STMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
423 LYEXT_SUBSTMT_REFERENCE = LY_STMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
424 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
425 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
426 LYEXT_SUBSTMT_REQUIRE_INSTANCE = LY_STMT_REQUIRE_INSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
427 LYEXT_SUBSTMT_REVISION_DATE = LY_STMT_REVISION_DATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
428 LYEXT_SUBSTMT_STATUS = LY_STMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
429 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
430 LYEXT_SUBSTMT_UNIQUE = LY_STMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
431 LYEXT_SUBSTMT_UNITS = LY_STMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
432 lys_node_leaflist and lys_deviate */
433 LYEXT_SUBSTMT_VALUE = LY_STMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
434 LYEXT_SUBSTMT_YANG_VERSION = LY_STMT_YANG_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
435 LYEXT_SUBSTMT_YIN_ELEMENT = LY_STMT_YIN_ELEMENT /**< extension of the yin-element statement, can appear in lys_ext */
Radek Krejci0e59c312019-08-15 15:34:15 +0200436} LYEXT_SUBSTMT;
437
438/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200439 * @brief YANG import-stmt
440 */
441struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200442 struct lys_module *module; /**< pointer to the imported module
443 (mandatory, but resolved when the referring module is completely parsed) */
444 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200445 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200446 const char *dsc; /**< description */
447 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200448 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100449 uint16_t flags; /**< LYS_INTERNAL value (@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200450 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
451};
452
453/**
454 * @brief YANG include-stmt
455 */
456struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100457 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200458 (mandatory, but resolved when the referring module is completely parsed) */
459 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200460 const char *dsc; /**< description */
461 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200462 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200463 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
Radek Krejci771928a2021-01-19 13:42:36 +0100464 ly_bool injected; /**< flag to mark includes copied into main module from submodules,
465 only for backward compatibility with YANG 1.0, which does not require the
466 main module to include all submodules. */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200467};
468
469/**
470 * @brief YANG extension-stmt
471 */
472struct lysp_ext {
473 const char *name; /**< extension name */
474 const char *argument; /**< argument name, NULL if not specified */
475 const char *dsc; /**< description statement */
476 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200477 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200478 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */
Michal Vasko5fe75f12020-03-02 13:52:37 +0100479
480 struct lysc_ext *compiled; /**< pointer to the compiled extension definition */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200481};
482
483/**
484 * @brief Helper structure for generic storage of the extension instances content.
485 */
486struct lysp_stmt {
487 const char *stmt; /**< identifier of the statement */
488 const char *arg; /**< statement's argument */
Michal Vaskofc2cd072021-02-24 13:17:17 +0100489 LY_PREFIX_FORMAT format; /**< prefix format of the identifier/argument (::LY_PREF_XML is YIN format) */
490 void *prefix_data; /**< Format-specific data for prefix resolution (see ::ly_type_store_resolve_prefix()) */
491
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200492 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200493 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
David Sedlákb9d75c42019-08-14 10:49:42 +0200494 uint16_t flags; /**< statement flags, can be set to LYS_YIN_ATTR */
Radek Krejci335332a2019-09-05 13:03:35 +0200495 enum ly_stmt kw; /**< numeric respresentation of the stmt value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200496};
497
David Sedlákae4b4512019-08-14 10:45:56 +0200498#define LYS_YIN 0x1 /**< used to specify input format of extension instance */
499
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200500/**
501 * @brief YANG extension instance
502 */
503struct lysp_ext_instance {
David Sedlákbbd06ca2019-06-27 14:15:38 +0200504 const char *name; /**< extension identifier, including possible prefix */
505 const char *argument; /**< optional value of the extension's argument */
Michal Vaskofc2cd072021-02-24 13:17:17 +0100506 LY_PREFIX_FORMAT format; /**< prefix format of the extension name/argument (::LY_PREF_XML is YIN format) */
507 void *prefix_data; /**< Format-specific data for prefix resolution
508 (see ::ly_type_store_resolve_prefix()) */
509
Radek Krejci335332a2019-09-05 13:03:35 +0200510 void *parent; /**< pointer to the parent element holding the extension instance(s), use
511 ::lysp_ext_instance#parent_type to access the schema element */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200512 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200513 struct lysc_ext_instance *compiled; /**< pointer to the compiled data if any - in case the source format is YIN,
514 some of the information (argument) are available only after compilation */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200515 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200516 LY_ARRAY_COUNT_TYPE insubstmt_index; /**< in case the instance is in a substatement, this identifies
David Sedlákbbd06ca2019-06-27 14:15:38 +0200517 the index of that substatement */
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100518 uint16_t flags; /**< LYS_INTERNAL value (@ref snodeflags) */
Radek Krejci335332a2019-09-05 13:03:35 +0200519 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200520};
521
522/**
523 * @brief YANG feature-stmt
524 */
525struct lysp_feature {
526 const char *name; /**< feature name (mandatory) */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100527 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
528 struct lysc_iffeature *iffeatures_c; /**< compiled if-features */
529 struct lysp_feature **depfeatures; /**< list of pointers to other features depending on this one
530 ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200531 const char *dsc; /**< description statement */
532 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200533 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100534 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values and
535 LYS_FENABLED are allowed */
536};
537
538/**
539 * @brief Compiled YANG if-feature-stmt
540 */
541struct lysc_iffeature {
542 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
543 struct lysp_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200544};
545
546/**
Michal Vasko7f45cf22020-10-01 12:49:44 +0200547 * @brief Qualified name (optional prefix followed by an identifier).
548 */
549struct lysp_qname {
550 const char *str; /**< qualified name string */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200551 const struct lysp_module *mod; /**< module to resolve any prefixes found in the string, it must be
Michal Vasko7f45cf22020-10-01 12:49:44 +0200552 stored explicitly because of deviations/refines */
553};
554
555/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200556 * @brief YANG identity-stmt
557 */
558struct lysp_ident {
559 const char *name; /**< identity name (mandatory), including possible prefix */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200560 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200561 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200562 const char *dsc; /**< description statement */
563 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200564 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200565 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
566};
567
Michal Vasko71e64ca2018-09-07 16:30:29 +0200568/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200569 * @brief Covers restrictions: range, length, pattern, must
570 */
571struct lysp_restr {
Radek Krejcif13b87b2020-12-01 22:02:17 +0100572#define LYSP_RESTR_PATTERN_ACK 0x06
573#define LYSP_RESTR_PATTERN_NACK 0x15
Michal Vasko7f45cf22020-10-01 12:49:44 +0200574 struct lysp_qname arg; /**< The restriction expression/value (mandatory);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200575 in case of pattern restriction, the first byte has a special meaning:
576 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
577 const char *emsg; /**< error-message */
578 const char *eapptag; /**< error-app-tag value */
579 const char *dsc; /**< description */
580 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200581 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200582};
583
584/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200585 * @brief YANG revision-stmt
586 */
587struct lysp_revision {
Radek Krejcicb3e6472021-01-06 08:19:01 +0100588 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200589 const char *dsc; /**< description statement */
590 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200591 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200592};
593
594/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200595 * @brief Enumeration/Bit value definition
596 */
597struct lysp_type_enum {
598 const char *name; /**< name (mandatory) */
599 const char *dsc; /**< description statement */
600 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200601 int64_t value; /**< enum's value or bit's position */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200602 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200603 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200604 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
605 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200606};
607
608/**
609 * @brief YANG type-stmt
610 *
611 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
612 */
613struct lysp_type {
614 const char *name; /**< name of the type (mandatory) */
615 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
616 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200617 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
618 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
619 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Michal Vasko004d3152020-06-11 19:59:22 +0200620 struct lyxp_expr *path; /**< parsed path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200621 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200622 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
623 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200624
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200625 const struct lysp_module *pmod; /**< (sub)module where the type is defined (needed for deviations) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100626 struct lysc_type *compiled; /**< pointer to the compiled type */
627
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200628 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
629 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100630 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200631};
632
633/**
634 * @brief YANG typedef-stmt
635 */
636struct lysp_tpdf {
637 const char *name; /**< name of the newly defined type (mandatory) */
638 const char *units; /**< units of the newly defined type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200639 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 +0200640 const char *dsc; /**< description statement */
641 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200642 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200643 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100644 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200645};
646
647/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200648 * @brief YANG when-stmt
649 */
650struct lysp_when {
651 const char *cond; /**< specified condition (mandatory) */
652 const char *dsc; /**< description statement */
653 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200654 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200655};
656
657/**
658 * @brief YANG refine-stmt
659 */
660struct lysp_refine {
661 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
662 const char *dsc; /**< description statement */
663 const char *ref; /**< reference statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200664 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200665 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200666 const char *presence; /**< presence description */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200667 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200668 uint32_t min; /**< min-elements constraint */
669 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200670 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200671 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
672};
673
674/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200675 * @ingroup schematree
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200676 * @defgroup deviatetypes Deviate types
Radek Krejci8678fa42020-08-18 16:07:28 +0200677 *
678 * Type of the deviate operation (used as ::lysp_deviate.mod)
679 *
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200680 * @{
681 */
682#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
683#define LYS_DEV_ADD 2 /**< deviate type add */
684#define LYS_DEV_DELETE 3 /**< deviate type delete */
685#define LYS_DEV_REPLACE 4 /**< deviate type replace */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200686/** @} deviatetypes */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200687
688/**
689 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
690 */
691struct lysp_deviate {
692 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
693 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200694 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200695};
696
697struct lysp_deviate_add {
698 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
699 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200700 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200701 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200702 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200703 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
704 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200705 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
706 uint32_t min; /**< min-elements constraint */
707 uint32_t max; /**< max-elements constraint, 0 means unbounded */
708};
709
710struct lysp_deviate_del {
711 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
712 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200713 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200714 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200715 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200716 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
717 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200718};
719
720struct lysp_deviate_rpl {
721 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
722 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200723 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200724 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200725 const char *units; /**< units of the values */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200726 struct lysp_qname dflt; /**< default value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200727 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
728 uint32_t min; /**< min-elements constraint */
729 uint32_t max; /**< max-elements constraint, 0 means unbounded */
730};
731
732struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200733 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200734 const char *dsc; /**< description statement */
735 const char *ref; /**< reference statement */
Michal Vasko22df3f02020-08-24 13:29:22 +0200736 struct lysp_deviate *deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200737 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200738};
739
Radek Krejci4f28eda2018-11-12 11:46:16 +0100740/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100741 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200742 * @defgroup spnodeflags Parsed schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100743 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200744 * Various flags for parsed schema nodes (used as ::lysp_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100745 *
746 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
747 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200748 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100749 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
750 * 5 - list 10 - input 15 - typedef 20 - deviate
751 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200752 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
753 * 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
754 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200755 * 1 LYS_CONFIG_W |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200756 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
757 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200758 * 2 LYS_CONFIG_R |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200759 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
760 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
761 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
762 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
763 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
764 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
765 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
766 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
767 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
768 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
769 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
770 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
771 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100772 * LYS_FENABLED | | | | | | | | | | | |x| | | | | | | | | | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200773 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
774 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
775 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
776 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
777 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
778 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
779 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
780 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
781 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
782 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
783 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
784 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
785 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
786 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
787 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
788 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
789 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
790 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
791 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200792 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
David Sedlákae4b4512019-08-14 10:45:56 +0200793 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x|
Michal Vasko5297a432020-08-31 12:27:51 +0200794 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
795 * 12 LYS_YIN_ARGUMENT | | | | | | | | | | | | | | | | | | | | | | |x|
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100796 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
797 * 13 LYS_INTERNAL |x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|
Radek Krejcif56e2a42019-09-09 14:15:25 +0200798 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100799 *
800 */
801
802/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100803 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200804 * @defgroup scnodeflags Compiled schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100805 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200806 * Various flags for compiled schema nodes (used as ::lysc_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100807 *
Radek Krejci61e042e2019-09-10 15:53:09 +0200808 * 1 - container 6 - anydata/anyxml 11 - identity
809 * 2 - choice 7 - case 12 - extension
810 * 3 - leaf 8 - notification 13 - bitenum
Michal Vasko03ff5a72019-09-11 13:49:33 +0200811 * 4 - leaflist 9 - rpc/action 14 - when
Michal Vaskoecd62de2019-11-13 12:35:11 +0100812 * 5 - list 10 - feature
Radek Krejci4f28eda2018-11-12 11:46:16 +0100813 *
Michal Vaskoecd62de2019-11-13 12:35:11 +0100814 * 1 1 1 1 1
815 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
816 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskod09b7622021-01-26 09:14:13 +0100817 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100818 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskod09b7622021-01-26 09:14:13 +0100819 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100820 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
821 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x|x|x|x| |x|
822 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
823 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x|x|x|x| |x|
824 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
825 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x|x|x|x| |x|
826 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
827 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
828 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
829 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
830 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | |
831 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
832 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
833 * LYS_PRESENCE |x| | | | | | | | | | | | | |
834 * LYS_UNIQUE | | |x| | | | | | | | | | | |
835 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
836 * 9 LYS_KEY | | |x| | | | | | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100837 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
838 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
Michal Vaskod1e53b92021-01-28 13:11:06 +0100839 * LYS_IS_ENUM | | | | | | | | | | | | |x| |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100840 * LYS_KEYLESS | | | | |x| | | | | | | | | |
Christian Hopps7cfa9612021-02-04 11:45:41 -0500841 * LYS_SET_PRESENCE |x| | | | | | | | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100842 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
843 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
844 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
845 * 12 LYS_SET_CONFIG |x|x|x|x|x|x| | | | | | | | |
Michal Vaskod1e53b92021-01-28 13:11:06 +0100846 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
847 * 13 LYS_IS_INPUT |x|x|x|x|x|x|x| | | | | | | |
848 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
849 * 14 LYS_IS_OUTPUT |x|x|x|x|x|x|x| | | | | | | |
850 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
851 * 15 LYS_IS_NOTIF |x|x|x|x|x|x|x| | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100852 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100853 *
854 */
855
856/**
857 * @defgroup snodeflags Schema nodes flags
Radek Krejci8678fa42020-08-18 16:07:28 +0200858 *
859 * Various flags for schema nodes ([parsed](@ref spnodeflags) as well as [compiled](@ref scnodeflags)).
860 *
Radek Krejci4f28eda2018-11-12 11:46:16 +0100861 * @{
862 */
Michal Vaskod1e53b92021-01-28 13:11:06 +0100863#define LYS_CONFIG_W 0x01 /**< config true; */
864#define LYS_CONFIG_R 0x02 /**< config false; */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200865#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100866#define LYS_STATUS_CURR 0x04 /**< status current; */
867#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
868#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
869#define LYS_STATUS_MASK 0x1C /**< mask for status value */
870#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100871 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
872 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
873 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
874 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100875#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
876 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
877 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100878#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Michal Vaskoc118ae22020-08-06 14:51:09 +0200879#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, but it is not only for explicit presence
880 containers, but also for NP containers with some meaning, applicable only to
881 ::lysc_node_container */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100882#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
Michal Vaskod1e53b92021-01-28 13:11:06 +0100883#define LYS_KEY 0x0100 /**< flag for leafs being a key of a list, applicable only to ::lysc_node_leaf */
884#define LYS_KEYLESS 0x0200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100885#define LYS_FENABLED 0x20 /**< feature enabled flag, applicable only to ::lysp_feature. */
Radek Krejcife909632019-02-12 15:34:42 +0100886#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 +0100887 ::lysc_node_list/::lysp_node_list */
888#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
889 ::lysc_node_list/::lysp_node_list */
890#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
891#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
Michal Vaskod1e53b92021-01-28 13:11:06 +0100892#define LYS_YINELEM_FALSE 0x0100 /**< yin-element false for extension's argument */
893#define LYS_YINELEM_MASK 0x0180 /**< mask for yin-element value */
894#define LYS_USED_GRP 0x0400 /**< internal flag for validating not-instantiated groupings
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200895 (resp. do not validate again the instantiated groupings). */
Michal Vaskod1e53b92021-01-28 13:11:06 +0100896#define LYS_SET_VALUE 0x0200 /**< value attribute is set */
897#define LYS_SET_MIN 0x0200 /**< min attribute is set */
898#define LYS_SET_MAX 0x0400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100899
900#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
901#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
902#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
903#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
904#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
905#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
906#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
907#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
908#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
909#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100910#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 +0100911 cases of choice. This information is important for refines, since it is prohibited to make leafs
912 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100913 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
914 between own default or the default values taken from the type. */
Christian Hopps7cfa9612021-02-04 11:45:41 -0500915#define LYS_SET_PRESENCE 0x0200 /**< flag to know if container presence property was set explicitly */
Radek Krejciccd20f12019-02-15 14:12:27 +0100916#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 +0100917#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 +0100918
Michal Vaskod1e53b92021-01-28 13:11:06 +0100919#define LYS_SINGLEQUOTED 0x0100 /**< flag for single-quoted argument of an extension instance's substatement, only when the source is YANG */
920#define LYS_DOUBLEQUOTED 0x0200 /**< flag for double-quoted argument of an extension instance's substatement, only when the source is YANG */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200921
Michal Vaskod1e53b92021-01-28 13:11:06 +0100922#define LYS_YIN_ATTR 0x0400 /**< flag to identify YIN attribute parsed as extension's substatement, only when the source is YIN */
923#define LYS_YIN_ARGUMENT 0x0800 /**< flag to identify statement representing extension's argument, only when the source is YIN */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200924
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100925#define LYS_INTERNAL 0x1000 /**< flag to identify internal parsed statements that should not be printed */
926
Michal Vaskod1e53b92021-01-28 13:11:06 +0100927#define LYS_IS_ENUM 0x0200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
928
929#define LYS_IS_INPUT 0x1000 /**< flag for nodes that are in the subtree of an input statement */
930
931#define LYS_IS_OUTPUT 0x2000 /**< flag for nodes that are in the subtree of an output statement */
932
933#define LYS_IS_NOTIF 0x4000 /**< flag for nodes that are in the subtree of a notification statement */
Radek Krejci693262f2019-04-29 15:23:20 +0200934
Radek Krejcife909632019-02-12 15:34:42 +0100935#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200936/** @} snodeflags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200937
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200938/**
939 * @brief Generic YANG data node
940 */
941struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100942 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200943 uint16_t nodetype; /**< type of the node (mandatory) */
944 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100945 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200946 const char *name; /**< node name (mandatory) */
947 const char *dsc; /**< description statement */
948 const char *ref; /**< reference statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200949 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)),
950 must be qname because of refines */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200951 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200952};
953
954/**
955 * @brief Extension structure of the lysp_node for YANG container
956 */
957struct lysp_node_container {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100958 union {
959 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
960 struct {
961 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
962 uint16_t nodetype; /**< LYS_CONTAINER */
963 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
964 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
965 const char *name; /**< node name (mandatory) */
966 const char *dsc; /**< description statement */
967 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100968 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
969 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
970 };
971 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200972
973 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200974 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +0100975 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200976 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200977 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100978 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200979 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100980 struct lysp_node_action *actions;/**< list of actions (linked list) */
981 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200982};
983
984struct lysp_node_leaf {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100985 union {
986 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
987 struct {
988 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
989 uint16_t nodetype; /**< LYS_LEAF */
990 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
991 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
992 const char *name; /**< node name (mandatory) */
993 const char *dsc; /**< description statement */
994 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100995 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
996 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
997 };
998 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200999
1000 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001001 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001002 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001003 struct lysp_type type; /**< type of the leaf node (mandatory) */
1004 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001005 struct lysp_qname dflt; /**< default value, it may or may not be a qualified name */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001006};
1007
1008struct lysp_node_leaflist {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001009 union {
1010 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1011 struct {
1012 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1013 uint16_t nodetype; /**< LYS_LEAFLIST */
1014 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1015 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1016 const char *name; /**< node name (mandatory) */
1017 const char *dsc; /**< description statement */
1018 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001019 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1020 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1021 };
1022 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001023
1024 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001025 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001026 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001027 struct lysp_type type; /**< type of the leaf node (mandatory) */
1028 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001029 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)), they may or
1030 may not be qualified names */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001031 uint32_t min; /**< min-elements constraint */
1032 uint32_t max; /**< max-elements constraint, 0 means unbounded */
1033};
1034
1035struct lysp_node_list {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001036 union {
1037 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1038 struct {
1039 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1040 uint16_t nodetype; /**< LYS_LIST */
1041 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1042 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1043 const char *name; /**< node name (mandatory) */
1044 const char *dsc; /**< description statement */
1045 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001046 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1047 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1048 };
1049 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001050
1051 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001052 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001053 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001054 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001055 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001056 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001057 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001058 struct lysp_node_action *actions;/**< list of actions (linked list) */
1059 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001060 struct lysp_qname *uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001061 uint32_t min; /**< min-elements constraint */
1062 uint32_t max; /**< max-elements constraint, 0 means unbounded */
1063};
1064
1065struct lysp_node_choice {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001066 union {
1067 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1068 struct {
1069 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1070 uint16_t nodetype; /**< LYS_CHOICE */
1071 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1072 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1073 const char *name; /**< node name (mandatory) */
1074 const char *dsc; /**< description statement */
1075 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001076 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1077 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1078 };
1079 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001080
1081 /* choice */
1082 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001083 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001084 struct lysp_qname dflt; /**< default case */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001085};
1086
1087struct lysp_node_case {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001088 union {
1089 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1090 struct {
1091 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1092 uint16_t nodetype; /**< LYS_CASE */
1093 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1094 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1095 const char *name; /**< node name (mandatory) */
1096 const char *dsc; /**< description statement */
1097 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001098 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1099 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1100 };
1101 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001102
1103 /* case */
1104 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001105 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001106};
1107
1108struct lysp_node_anydata {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001109 union {
1110 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1111 struct {
1112 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1113 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1114 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1115 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1116 const char *name; /**< node name (mandatory) */
1117 const char *dsc; /**< description statement */
1118 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001119 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1120 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1121 };
1122 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001123
1124 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001125 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001126 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001127};
1128
1129struct lysp_node_uses {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001130 union {
1131 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1132 struct {
1133 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1134 uint16_t nodetype; /**< LYS_USES */
1135 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1136 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1137 const char *name; /**< grouping name reference (mandatory) */
1138 const char *dsc; /**< description statement */
1139 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001140 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1141 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1142 };
1143 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001144
1145 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001146 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001147 struct lysp_node_augment *augments; /**< list of augments (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001148 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001149};
1150
1151/**
1152 * @brief YANG input-stmt and output-stmt
1153 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001154struct lysp_node_action_inout {
1155 union {
1156 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1157 struct {
1158 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1159 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
1160 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1161 struct lysp_node *next; /**< NULL */
1162 const char *name; /**< empty string */
1163 const char *dsc; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1164 const char *ref; /**< ALWAYS NULL, compatibility member with ::lysp_node */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001165 struct lysp_qname *iffeatures; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1166 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1167 };
1168 }; /**< common part corresponding to ::lysp_node */
1169
1170 /* inout */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001171 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1172 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001173 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci01180ac2021-01-27 08:48:22 +01001174 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001175};
1176
1177/**
1178 * @brief YANG rpc-stmt and action-stmt
1179 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001180struct lysp_node_action {
1181 union {
1182 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1183 struct {
1184 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1185 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
1186 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1187 struct lysp_node_action *next; /**< pointer to the next action (NULL if there is no one) */
1188 const char *name; /**< grouping name reference (mandatory) */
1189 const char *dsc; /**< description statement */
1190 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001191 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1192 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1193 };
1194 }; /**< common part corresponding to ::lysp_node */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001195
1196 /* action */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001197 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1198 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
1199
1200 struct lysp_node_action_inout input; /**< RPC's/Action's input */
1201 struct lysp_node_action_inout output; /**< RPC's/Action's output */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001202};
1203
1204/**
1205 * @brief YANG notification-stmt
1206 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001207struct lysp_node_notif {
1208 union {
1209 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1210 struct {
1211 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1212 uint16_t nodetype; /**< LYS_NOTIF */
1213 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1214 struct lysp_node_notif *next; /**< pointer to the next notification (NULL if there is no one) */
1215 const char *name; /**< grouping name reference (mandatory) */
1216 const char *dsc; /**< description statement */
1217 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001218 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1219 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1220 };
1221 }; /**< common part corresponding to ::lysp_node */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001222
1223 /* notif */
1224 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001225 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1226 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci01180ac2021-01-27 08:48:22 +01001227 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001228};
1229
1230/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001231 * @brief YANG grouping-stmt
1232 */
1233struct lysp_node_grp {
1234 union {
1235 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1236 struct {
1237 struct lysp_node *parent;/**< parent node (NULL if this is a top-level grouping) */
1238 uint16_t nodetype; /**< LYS_GROUPING */
1239 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1240 struct lysp_node_grp *next; /**< pointer to the next grouping (NULL if there is no one) */
1241 const char *name; /**< grouping name (mandatory) */
1242 const char *dsc; /**< description statement */
1243 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001244 struct lysp_qname *iffeatures; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1245 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1246 };
1247 }; /**< common part corresponding to ::lysp_node */
1248
1249 /* grp */
1250 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1251 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci01180ac2021-01-27 08:48:22 +01001252 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001253 struct lysp_node_action *actions; /**< list of actions (linked list) */
1254 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
1255};
1256
1257/**
1258 * @brief YANG uses-augment-stmt and augment-stmt (compatible with struct lysp_node )
1259 */
1260struct lysp_node_augment {
1261 union {
1262 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1263 struct {
1264 struct lysp_node *parent;/**< parent node (NULL if this is a top-level augment) */
1265 uint16_t nodetype; /**< LYS_AUGMENT */
1266 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1267 struct lysp_node_augment *next; /**< pointer to the next augment (NULL if there is no one) */
1268 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
1269 const char *dsc; /**< description statement */
1270 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001271 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1272 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1273 };
1274 }; /**< common part corresponding to ::lysp_node */
1275
1276 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001277 struct lysp_when *when; /**< when statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001278 struct lysp_node_action *actions;/**< list of actions (linked list) */
1279 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
1280};
1281
1282/**
Radek Krejcif0fceb62018-09-05 14:58:45 +02001283 * @brief supported YANG schema version values
1284 */
1285typedef enum LYS_VERSION {
1286 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
Radek Krejci96e48da2020-09-04 13:18:06 +02001287 LYS_VERSION_1_0 = 1, /**< YANG 1 (1.0) */
Radek Krejcif0fceb62018-09-05 14:58:45 +02001288 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
1289} LYS_VERSION;
1290
1291/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001292 * @brief Printable YANG schema tree structure representing YANG module.
1293 *
1294 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
1295 */
1296struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001297 struct lys_module *mod; /**< covering module structure */
1298
Radek Krejcib7db73a2018-10-24 14:18:40 +02001299 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1300 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001301 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1302 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001303 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1304 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1305 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1306 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001307 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001308 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001309 struct lysp_node_augment *augments; /**< list of augments (linked list) */
1310 struct lysp_node_action *rpcs; /**< list of RPCs (linked list) */
1311 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001312 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001313 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001314
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001315 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001316 uint8_t parsing : 1; /**< flag for circular check */
1317 uint8_t is_submod : 1; /**< always 0 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001318};
1319
1320struct lysp_submodule {
Michal Vaskoc3781c32020-10-06 14:04:08 +02001321 struct lys_module *mod; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001322
1323 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1324 in the list is always the last (newest) revision of the module */
1325 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1326 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
1327 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1328 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1329 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1330 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001331 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001332 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001333 struct lysp_node_augment *augments; /**< list of augments (linked list) */
1334 struct lysp_node_action *rpcs; /**< list of RPCs (linked list) */
1335 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001336 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001337 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001338
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001339 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001340 uint8_t parsing : 1; /**< flag for circular check */
1341 uint8_t is_submod : 1; /**< always 1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001342
Michal Vaskoc3781c32020-10-06 14:04:08 +02001343 uint8_t latest_revision : 2; /**< flag to mark the latest available revision:
Radek Krejci086c7132018-10-26 15:29:04 +02001344 1 - the latest revision in searchdirs was not searched yet and this is the
1345 latest revision in the current context
1346 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001347 const char *name; /**< name of the module (mandatory) */
1348 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1349 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
1350 const char *org; /**< party/company responsible for the module */
1351 const char *contact; /**< contact information for the module */
1352 const char *dsc; /**< description of the module */
1353 const char *ref; /**< cross-reference for the module */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001354};
1355
1356/**
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001357 * @brief Get the parsed module or submodule name.
1358 *
1359 * @param[in] PMOD Parsed module or submodule.
1360 * @return Module or submodule name.
1361 */
1362#define LYSP_MODULE_NAME(PMOD) (PMOD->is_submod ? ((struct lysp_submodule *)PMOD)->name : ((struct lysp_module *)PMOD)->mod->name)
1363
1364/**
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001365 * @brief Compiled prefix data pair mapping of prefixes to modules. In case the format is ::LY_PREF_SCHEMA_RESOLVED,
1366 * the expected prefix data is a sized array of these structures.
1367 */
1368struct lysc_prefix {
1369 char *prefix; /**< used prefix */
1370 const struct lys_module *mod; /**< mapping to a module */
1371};
1372
1373/**
Radek Krejci0e59c312019-08-15 15:34:15 +02001374 * @brief Compiled YANG extension-stmt
1375 */
1376struct lysc_ext {
1377 const char *name; /**< extension name */
1378 const char *argument; /**< argument name, NULL if not specified */
Radek Krejci0e59c312019-08-15 15:34:15 +02001379 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1380 struct lyext_plugin *plugin; /**< Plugin implementing the specific extension */
Radek Krejci0935f412019-08-20 16:15:18 +02001381 struct lys_module *module; /**< module structure */
Michal Vasko6f4cbb62020-02-28 11:15:47 +01001382 uint32_t refcount; /**< reference counter since extension definition is shared among all its instances */
Radek Krejci0e59c312019-08-15 15:34:15 +02001383 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
1384};
1385
1386/**
Radek Krejcice8c1592018-10-29 15:35:51 +01001387 * @brief YANG extension instance
1388 */
1389struct lysc_ext_instance {
Radek Krejciad5963b2019-09-06 16:03:05 +02001390 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
1391 this identifies the index of the substatement for this extension instance */
Radek Krejci28681fa2019-09-06 13:08:45 +02001392 struct lys_module *module; /**< module where the extension instantiated is defined */
Radek Krejciad5963b2019-09-06 16:03:05 +02001393 struct lysc_ext *def; /**< pointer to the extension definition */
Radek Krejcice8c1592018-10-29 15:35:51 +01001394 void *parent; /**< pointer to the parent element holding the extension instance(s), use
1395 ::lysc_ext_instance#parent_type to access the schema element */
1396 const char *argument; /**< optional value of the extension's argument */
1397 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +01001398 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001399 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0e59c312019-08-15 15:34:15 +02001400 void *data; /**< private plugins's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +01001401};
1402
1403/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001404 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001405 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001406struct lysc_when {
1407 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko175012e2019-11-06 15:49:14 +01001408 struct lysc_node *context; /**< context node for evaluating the expression, NULL if the context is root node */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001409 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001410 const char *dsc; /**< description */
1411 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001412 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001413 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Michal Vaskoecd62de2019-11-13 12:35:11 +01001414 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS is allowed */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001415};
1416
1417/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001418 * @brief YANG identity-stmt
1419 */
1420struct lysc_ident {
1421 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +01001422 const char *dsc; /**< description */
1423 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001424 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001425 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
1426 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1427 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1428};
1429
1430/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001431 * @defgroup ifftokens if-feature expression tokens
Radek Krejci8678fa42020-08-18 16:07:28 +02001432 * Tokens of if-feature expression used in ::lysc_iffeature.expr.
Radek Krejci151a5b72018-10-19 14:21:44 +02001433 *
1434 * @{
1435 */
1436#define LYS_IFF_NOT 0x00 /**< operand "not" */
1437#define LYS_IFF_AND 0x01 /**< operand "and" */
1438#define LYS_IFF_OR 0x02 /**< operand "or" */
1439#define LYS_IFF_F 0x03 /**< feature */
Radek Krejci2ff0d572020-05-21 15:27:28 +02001440/** @} ifftokens */
Radek Krejci151a5b72018-10-19 14:21:44 +02001441
1442/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001443 * @brief Compiled YANG revision statement
1444 */
1445struct lysc_revision {
1446 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1447 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1448};
1449
Radek Krejci2167ee12018-11-02 16:09:07 +01001450struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001451 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001452 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001453 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1454 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001455 };
Radek Krejci693262f2019-04-29 15:23:20 +02001456 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001457 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1458 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001459 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001460 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001461 const char *dsc; /**< description */
1462 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001463 const char *emsg; /**< error-message */
1464 const char *eapptag; /**< error-app-tag value */
1465 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1466};
1467
1468struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001469 const char *expr; /**< original, not compiled, regular expression */
1470 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001471 const char *dsc; /**< description */
1472 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001473 const char *emsg; /**< error-message */
1474 const char *eapptag; /**< error-app-tag value */
1475 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0f969882020-08-21 16:56:47 +02001476 uint32_t inverted : 1; /**< invert-match flag */
1477 uint32_t refcount : 31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001478};
1479
1480struct lysc_must {
Radek Krejci2167ee12018-11-02 16:09:07 +01001481 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001482 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001483 const char *dsc; /**< description */
1484 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001485 const char *emsg; /**< error-message */
1486 const char *eapptag; /**< error-app-tag value */
1487 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1488};
1489
1490struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001491 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001492 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001493 LY_DATA_TYPE basetype; /**< Base type of the type */
1494 uint32_t refcount; /**< reference counter for type sharing */
1495};
1496
1497struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001498 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001499 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 +01001500 LY_DATA_TYPE basetype; /**< Base type of the type */
1501 uint32_t refcount; /**< reference counter for type sharing */
1502 struct lysc_range *range; /**< Optional range limitation */
1503};
1504
1505struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001506 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001507 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 +01001508 LY_DATA_TYPE basetype; /**< Base type of the type */
1509 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001510 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001511 struct lysc_range *range; /**< Optional range limitation */
1512};
1513
1514struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001515 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001516 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 +01001517 LY_DATA_TYPE basetype; /**< Base type of the type */
1518 uint32_t refcount; /**< reference counter for type sharing */
1519 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001520 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001521};
1522
Radek Krejci693262f2019-04-29 15:23:20 +02001523struct lysc_type_bitenum_item {
1524 const char *name; /**< enumeration identifier */
1525 const char *dsc; /**< description */
1526 const char *ref; /**< reference */
1527 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci693262f2019-04-29 15:23:20 +02001528 union {
1529 int32_t value; /**< integer value associated with the enumeration */
1530 uint32_t position; /**< non-negative integer value associated with the bit */
1531 };
1532 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1533 values are allowed */
1534};
1535
Radek Krejci2167ee12018-11-02 16:09:07 +01001536struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001537 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001538 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 +01001539 LY_DATA_TYPE basetype; /**< Base type of the type */
1540 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001541 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1542};
1543
1544struct lysc_type_bits {
1545 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001546 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 +02001547 LY_DATA_TYPE basetype; /**< Base type of the type */
1548 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001549 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1550 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001551};
1552
1553struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001554 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001555 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 +01001556 LY_DATA_TYPE basetype; /**< Base type of the type */
1557 uint32_t refcount; /**< reference counter for type sharing */
Michal Vasko004d3152020-06-11 19:59:22 +02001558 struct lyxp_expr *path; /**< parsed target path, compiled path cannot be stored because of type sharing */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001559 struct lysc_prefix *prefixes; /**< resolved prefixes used in the path */
Michal Vaskoc0792ca2020-12-01 12:03:21 +01001560 const struct lys_module *cur_mod;/**< current module for the leafref (path) */
Radek Krejci412ddfa2018-11-23 11:44:11 +01001561 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001562 uint8_t require_instance; /**< require-instance flag */
1563};
1564
1565struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001566 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001567 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 +01001568 LY_DATA_TYPE basetype; /**< Base type of the type */
1569 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001570 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001571 mandatory (at least 1 item) */
1572};
1573
1574struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001575 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001576 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 +01001577 LY_DATA_TYPE basetype; /**< Base type of the type */
1578 uint32_t refcount; /**< reference counter for type sharing */
1579 uint8_t require_instance; /**< require-instance flag */
1580};
1581
Radek Krejci2167ee12018-11-02 16:09:07 +01001582struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001583 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001584 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 +01001585 LY_DATA_TYPE basetype; /**< Base type of the type */
1586 uint32_t refcount; /**< reference counter for type sharing */
1587 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1588};
1589
1590struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001591 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcie7b95092019-05-15 11:03:07 +02001592 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 +01001593 LY_DATA_TYPE basetype; /**< Base type of the type */
1594 uint32_t refcount; /**< reference counter for type sharing */
1595 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001596};
1597
Michal Vasko60ea6352020-06-29 13:39:39 +02001598/**
1599 * @brief Maximum number of hashes stored in a schema node.
1600 */
1601#define LYS_NODE_HASH_COUNT 4
1602
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001603/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001604 * @brief Compiled YANG data node
1605 */
1606struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001607 uint16_t nodetype; /**< type of the node (mandatory) */
1608 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001609 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001610 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001611 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1612 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1613 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1614 never NULL. If there is no sibling node, pointer points to the node
1615 itself. In case of the first node, this pointer points to the last
1616 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001617 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001618 const char *dsc; /**< description */
1619 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001620 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko2fd91b92020-07-17 16:39:02 +02001621 void *priv; /**< private arbitrary user data, not used by libyang */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001622};
1623
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001624struct lysc_node_action_inout {
1625 union {
1626 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1627 struct {
1628 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
1629 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1630 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1631 struct lys_module *module; /**< module structure */
Radek Krejci5960c312021-01-27 20:24:22 +01001632 struct lysc_node *parent;/**< parent node (NULL in case of top level node) */
Michal Vasko544e58a2021-01-28 14:33:41 +01001633 struct lysc_node *next; /**< next sibling node (output node for input, NULL for output) */
1634 struct lysc_node *prev; /**< pointer to the previous sibling node (input and output node pointing to each other) */
Radek Krejci5960c312021-01-27 20:24:22 +01001635 const char *name; /**< "input" or "output" */
1636 const char *dsc; /**< ALWAYS NULL, compatibility member with ::lysc_node */
1637 const char *ref; /**< ALWAYS NULL, compatibility member with ::lysc_node */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001638 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001639 void *priv; /** private arbitrary user data, not used by libyang */
1640 };
1641 };
1642
Radek Krejci9a3823e2021-01-27 20:26:46 +01001643 struct lysc_node *child; /**< first child node (linked list) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001644 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1645};
1646
1647struct lysc_node_action {
1648 union {
1649 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1650 struct {
1651 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
1652 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1653 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1654 struct lys_module *module; /**< module structure */
1655 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1656 struct lysc_node_action *next; /**< next sibling node (NULL if there is no one) */
1657 struct lysc_node_action *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1658 never NULL. If there is no sibling node, pointer points to the node
1659 itself. In case of the first node, this pointer points to the last
1660 node in the list. */
1661 const char *name; /**< action/RPC name (mandatory) */
1662 const char *dsc; /**< description */
1663 const char *ref; /**< reference */
1664 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001665 void *priv; /** private arbitrary user data, not used by libyang */
1666 };
1667 };
1668
Radek Krejci9a3823e2021-01-27 20:26:46 +01001669 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)),
1670 the action/RPC nodes do not contain the when statement on their own, but they can
1671 inherit it from the parent's uses. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001672 struct lysc_node_action_inout input; /**< RPC's/action's input */
1673 struct lysc_node_action_inout output; /**< RPC's/action's output */
1674
1675};
1676
1677struct lysc_node_notif {
1678 union {
1679 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1680 struct {
1681 uint16_t nodetype; /**< LYS_NOTIF */
1682 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1683 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1684 struct lys_module *module; /**< module structure */
1685 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1686 struct lysc_node_notif *next; /**< next sibling node (NULL if there is no one) */
1687 struct lysc_node_notif *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1688 never NULL. If there is no sibling node, pointer points to the node
1689 itself. In case of the first node, this pointer points to the last
1690 node in the list. */
1691 const char *name; /**< Notification name (mandatory) */
1692 const char *dsc; /**< description */
1693 const char *ref; /**< reference */
1694 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001695 void *priv; /** private arbitrary user data, not used by libyang */
1696 };
1697 };
1698
Radek Krejci9a3823e2021-01-27 20:26:46 +01001699 struct lysc_node *child; /**< first child node (linked list) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001700 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001701 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)),
1702 the notification nodes do not contain the when statement on their own, but they can
1703 inherit it from the parent's uses. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001704};
1705
1706struct lysc_node_container {
1707 union {
1708 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1709 struct {
1710 uint16_t nodetype; /**< LYS_CONTAINER */
1711 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1712 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1713 struct lys_module *module; /**< module structure */
1714 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) */
1721 const char *dsc; /**< description */
1722 const char *ref; /**< reference */
1723 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001724 void *priv; /**< private arbitrary user data, not used by libyang */
1725 };
1726 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001727
1728 struct lysc_node *child; /**< first child node (linked list) */
1729 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001730 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001731 struct lysc_node_action *actions;/**< first of actions nodes (linked list) */
1732 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001733};
1734
Radek Krejcia3045382018-11-22 14:30:31 +01001735struct lysc_node_case {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001736 union {
1737 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1738 struct {
1739 uint16_t nodetype; /**< LYS_CASE */
1740 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1741 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
1742 struct lys_module *module; /**< module structure */
1743 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1744 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1745 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejci056d0a82018-12-06 16:57:25 +01001746 never NULL. If there is no sibling node, pointer points to the node
1747 itself. In case of the first node, this pointer points to the last
1748 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001749 const char *name; /**< name of the case, including the implicit case */
1750 const char *dsc; /**< description */
1751 const char *ref; /**< reference */
1752 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001753 void *priv; /**< private arbitrary user data, not used by libyang */
1754 };
1755 };
Radek Krejci056d0a82018-12-06 16:57:25 +01001756
Radek Krejcia3045382018-11-22 14:30:31 +01001757 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 +01001758 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001759 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcia3045382018-11-22 14:30:31 +01001760};
1761
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001762struct lysc_node_choice {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001763 union {
1764 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1765 struct {
1766 uint16_t nodetype; /**< LYS_CHOICE */
1767 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1768 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
1769 struct lys_module *module; /**< module structure */
1770 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1771 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1772 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001773 never NULL. If there is no sibling node, pointer points to the node
1774 itself. In case of the first node, this pointer points to the last
1775 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001776 const char *name; /**< node name (mandatory) */
1777 const char *dsc; /**< description */
1778 const char *ref; /**< reference */
1779 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001780 void *priv; /**< private arbitrary user data, not used by libyang */
1781 };
1782 };
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001783
Radek Krejcia9026eb2018-12-12 16:04:47 +01001784 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1785 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1786 case is simple. */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001787 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001788 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001789};
1790
1791struct lysc_node_leaf {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001792 union {
1793 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1794 struct {
1795 uint16_t nodetype; /**< LYS_LEAF */
1796 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1797 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1798 struct lys_module *module; /**< module structure */
1799 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1800 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1801 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001802 never NULL. If there is no sibling node, pointer points to the node
1803 itself. In case of the first node, this pointer points to the last
1804 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001805 const char *name; /**< node name (mandatory) */
1806 const char *dsc; /**< description */
1807 const char *ref; /**< reference */
1808 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001809 void *priv; /**< private arbitrary user data, not used by libyang */
1810 };
1811 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001812
1813 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001814 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001815 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001816
Radek Krejci4f28eda2018-11-12 11:46:16 +01001817 const char *units; /**< units of the leaf's type */
Radek Krejcia1911222019-07-22 17:24:50 +02001818 struct lyd_value *dflt; /**< default value */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001819};
1820
1821struct lysc_node_leaflist {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001822 union {
1823 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1824 struct {
1825 uint16_t nodetype; /**< LYS_LEAFLIST */
1826 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1827 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1828 struct lys_module *module; /**< module structure */
1829 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1830 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1831 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001832 never NULL. If there is no sibling node, pointer points to the node
1833 itself. In case of the first node, this pointer points to the last
1834 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001835 const char *name; /**< node name (mandatory) */
1836 const char *dsc; /**< description */
1837 const char *ref; /**< reference */
1838 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001839 void *priv; /**< private arbitrary user data, not used by libyang */
1840 };
1841 };
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001842
1843 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001844 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001845 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1846
Radek Krejci0e5d8382018-11-28 16:37:53 +01001847 const char *units; /**< units of the leaf's type */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001848 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values */
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001849
Radek Krejci0e5d8382018-11-28 16:37:53 +01001850 uint32_t min; /**< min-elements constraint */
1851 uint32_t max; /**< max-elements constraint */
1852
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001853};
1854
1855struct lysc_node_list {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001856 union {
1857 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1858 struct {
1859 uint16_t nodetype; /**< LYS_LIST */
1860 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1861 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1862 struct lys_module *module; /**< module structure */
1863 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1864 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1865 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001866 never NULL. If there is no sibling node, pointer points to the node
1867 itself. In case of the first node, this pointer points to the last
1868 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001869 const char *name; /**< node name (mandatory) */
1870 const char *dsc; /**< description */
1871 const char *ref; /**< reference */
1872 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001873 void *priv; /**< private arbitrary user data, not used by libyang */
1874 };
1875 };
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001876
1877 struct lysc_node *child; /**< first child node (linked list) */
1878 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001879 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001880 struct lysc_node_action *actions;/**< first of actions nodes (linked list) */
1881 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001882
Radek Krejci2a9fc652021-01-22 17:44:34 +01001883 struct lysc_node_leaf ***uniques;/**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001884 uint32_t min; /**< min-elements constraint */
1885 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001886};
1887
1888struct lysc_node_anydata {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001889 union {
1890 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1891 struct {
1892 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1893 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1894 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1895 struct lys_module *module; /**< module structure */
1896 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1897 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1898 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001899 never NULL. If there is no sibling node, pointer points to the node
1900 itself. In case of the first node, this pointer points to the last
1901 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001902 const char *name; /**< node name (mandatory) */
1903 const char *dsc; /**< description */
1904 const char *ref; /**< reference */
1905 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001906 void *priv; /**< private arbitrary user data, not used by libyang */
1907 };
1908 };
Radek Krejci9800fb82018-12-13 14:26:23 +01001909
1910 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001911 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001912};
1913
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001914/**
1915 * @brief Compiled YANG schema tree structure representing YANG module.
1916 *
1917 * Semantically validated YANG schema tree for data tree parsing.
1918 * Contains only the necessary information for the data validation.
1919 */
1920struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001921 struct lys_module *mod; /**< covering module structure */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001922
Radek Krejci2a408df2018-10-29 16:32:26 +01001923 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001924 struct lysc_node_action *rpcs; /**< first of actions nodes (linked list) */
1925 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001926 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001927};
1928
1929/**
Radek Krejci490a5462020-11-05 08:44:42 +01001930 * @brief Examine whether a node is user-ordered list or leaf-list.
1931 *
1932 * @param[in] lysc_node Schema node to examine.
1933 * @return Boolean value whether the @p node is user-ordered or not.
1934 */
1935#define lysc_is_userordered(lysc_node) \
1936 ((!lysc_node || !(lysc_node->nodetype & (LYS_LEAFLIST | LYS_LIST)) || !(lysc_node->flags & LYS_ORDBY_USER)) ? 0 : 1)
1937
1938/**
1939 * @brief Examine whether a node is a list's key.
1940 *
1941 * @param[in] lysc_node Schema node to examine.
1942 * @return Boolean value whether the @p node is a key or not.
1943 */
1944#define lysc_is_key(lysc_node) \
Michal Vaskobce7ee32021-02-04 11:05:25 +01001945 ((!lysc_node || (lysc_node->nodetype != LYS_LEAF) || !(lysc_node->flags & LYS_KEY)) ? 0 : 1)
Radek Krejci490a5462020-11-05 08:44:42 +01001946
1947/**
Michal Vasko5c123b02020-12-04 14:34:04 +01001948 * @brief Examine whether a node is a non-presence container.
1949 *
1950 * @param[in] lysc_node Schema node to examine.
1951 * @return Boolean value whether the @p node is a NP container or not.
1952 */
1953#define lysc_is_np_cont(lysc_node) \
Michal Vaskobce7ee32021-02-04 11:05:25 +01001954 ((!lysc_node || (lysc_node->nodetype != LYS_CONTAINER) || (lysc_node->flags & LYS_PRESENCE)) ? 0 : 1)
1955
1956/**
1957 * @brief Examine whether a node is a key-less list or a state leaf-list.
1958 *
1959 * @param[in] lysc_node Schema node to examine.
1960 * @return Boolean value whether the @p node is a list with duplicate instances allowed.
1961 */
1962#define lysc_is_dup_inst_list(lysc_node) \
1963 ((lysc_node && (((lysc_node->nodetype == LYS_LIST) && (lysc_node->flags & LYS_KEYLESS)) || \
1964 ((lysc_node->nodetype == LYS_LEAFLIST) && (lysc_node->flags & LYS_CONFIG_R)))) ? 1 : 0)
Michal Vasko5c123b02020-12-04 14:34:04 +01001965
1966/**
Michal Vaskod5cfa6e2020-11-23 16:56:08 +01001967 * @brief Check whether the schema node data instance existence depends on any when conditions.
1968 * This node and any direct parent choice and case schema nodes are also examined for when conditions.
1969 *
1970 * Be careful, this function is not recursive and checks only conditions that apply to this node directly.
1971 * Meaning if there are any conditions associated with any data parent instance of @p node, they are not returned.
1972 *
1973 * @param[in] node Schema node to examine.
1974 * @return When condition associated with the node data instance, NULL if there is none.
1975 */
1976const struct lysc_when *lysc_has_when(const struct lysc_node *node);
1977
1978/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001979 * @brief Get the groupings linked list of the given (parsed) schema node.
Radek Krejci53ea6152018-12-13 15:21:15 +01001980 * Decides the node's type and in case it has a groupings array, returns it.
1981 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01001982 * @return The node's groupings linked list if any, NULL otherwise.
Radek Krejci53ea6152018-12-13 15:21:15 +01001983 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001984const struct lysp_node_grp *lysp_node_groupings(const struct lysp_node *node);
Radek Krejci53ea6152018-12-13 15:21:15 +01001985
1986/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001987 * @brief Get the typedefs sized array of the given (parsed) schema node.
1988 * Decides the node's type and in case it has a typedefs array, returns it.
1989 * @param[in] node Node to examine.
1990 * @return The node's typedefs sized array if any, NULL otherwise.
1991 */
1992const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1993
1994/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001995 * @brief Get the actions/RPCs linked list of the given (parsed) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01001996 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1997 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01001998 * @return The node's actions/RPCs linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01001999 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01002000const struct lysp_node_action *lysp_node_actions(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002001
2002/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01002003 * @brief Get the Notifications linked list of the given (parsed) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01002004 * Decides the node's type and in case it has a Notifications array, returns it.
2005 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01002006 * @return The node's Notifications linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01002007 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01002008const struct lysp_node_notif *lysp_node_notifs(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002009
2010/**
2011 * @brief Get the children linked list of the given (parsed) schema node.
2012 * Decides the node's type and in case it has a children list, returns it.
2013 * @param[in] node Node to examine.
2014 * @return The node's children linked list if any, NULL otherwise.
2015 */
Michal Vasko544e58a2021-01-28 14:33:41 +01002016const struct lysp_node *lysp_node_child(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002017
2018/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01002019 * @brief Get the actions/RPCs linked list of the given (compiled) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01002020 * Decides the node's type and in case it has a actions/RPCs array, returns it.
2021 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01002022 * @return The node's actions/RPCs linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01002023 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01002024const struct lysc_node_action *lysc_node_actions(const struct lysc_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002025
2026/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01002027 * @brief Get the Notifications linked list of the given (compiled) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01002028 * Decides the node's type and in case it has a Notifications array, returns it.
2029 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01002030 * @return The node's Notifications linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01002031 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01002032const struct lysc_node_notif *lysc_node_notifs(const struct lysc_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002033
2034/**
2035 * @brief Get the children linked list of the given (compiled) schema node.
Michal Vasko2a668712020-10-21 11:48:09 +02002036 *
Michal Vasko544e58a2021-01-28 14:33:41 +01002037 * Note that ::LYS_CHOICE has only ::LYS_CASE children.
2038 * Also, ::LYS_RPC and ::LYS_ACTION have the first child ::LYS_INPUT, its sibling is ::LYS_OUTPUT.
2039 *
Michal Vasko2a668712020-10-21 11:48:09 +02002040 * @param[in] node Node to examine.
Michal Vasko2a668712020-10-21 11:48:09 +02002041 * @return Children linked list if any,
2042 * @return NULL otherwise.
2043 */
Michal Vasko544e58a2021-01-28 14:33:41 +01002044const struct lysc_node *lysc_node_child(const struct lysc_node *node);
Michal Vasko2a668712020-10-21 11:48:09 +02002045
2046/**
Radek Krejci9a3823e2021-01-27 20:26:46 +01002047 * @brief Get the must statements list if present in the @p node
2048 *
2049 * @param[in] node Node to examine.
2050 * @return Pointer to the list of must restrictions ([sized array](@ref sizedarrays))
2051 * @return NULL if there is no must statement in the node, no matter if it is not even allowed or just present
2052 */
2053struct lysc_must *lysc_node_musts(const struct lysc_node *node);
2054
2055/**
2056 * @brief Get the when statements list if present in the @p node
2057 *
2058 * @param[in] node Node to examine.
2059 * @return Pointer to the list of pointers to when statements ([sized array](@ref sizedarrays))
2060 * @return NULL if there is no when statement in the node, no matter if it is not even allowed or just present
2061 */
2062struct lysc_when **lysc_node_when(const struct lysc_node *node);
2063
2064/**
Michal Vaskof1ab44f2020-10-22 08:58:32 +02002065 * @brief Callback to be called for every schema node in a DFS traversal.
2066 *
2067 * @param[in] node Current node.
2068 * @param[in] data Arbitrary user data.
2069 * @param[out] dfs_continue Set to true if the current subtree should be skipped and continue with siblings instead.
2070 * @return LY_SUCCESS on success,
2071 * @return LY_ERR value to terminate DFS and return this value.
2072 */
Radek Krejci01180ac2021-01-27 08:48:22 +01002073typedef LY_ERR (*lysc_dfs_clb)(struct lysc_node *node, void *child, ly_bool *dfs_continue);
Michal Vaskof1ab44f2020-10-22 08:58:32 +02002074
2075/**
2076 * @brief DFS traversal of all the schema nodes in a (sub)tree including any actions and nested notifications.
2077 *
2078 * Node with children, actions, and notifications is traversed in this order:
2079 * 1) each child subtree;
2080 * 2) each action subtree;
2081 * 3) each notification subtree.
2082 *
2083 * For algorithm illustration or traversal with actions and notifications skipped, see ::LYSC_TREE_DFS_BEGIN.
2084 *
2085 * @param[in] root Schema root to fully traverse.
2086 * @param[in] dfs_clb Callback to call for each node.
2087 * @param[in] data Arbitrary user data passed to @p dfs_clb.
2088 * @return LY_SUCCESS on success,
2089 * @return LY_ERR value returned by @p dfs_clb.
2090 */
2091LY_ERR lysc_tree_dfs_full(const struct lysc_node *root, lysc_dfs_clb dfs_clb, void *data);
2092
2093/**
2094 * @brief DFS traversal of all the schema nodes in a module including RPCs and notifications.
2095 *
2096 * For more details, see ::lysc_tree_dfs_full().
2097 *
2098 * @param[in] mod Module to fully traverse.
2099 * @param[in] dfs_clb Callback to call for each node.
2100 * @param[in] data Arbitrary user data passed to @p dfs_clb.
2101 * @return LY_SUCCESS on success,
2102 * @return LY_ERR value returned by @p dfs_clb.
2103 */
2104LY_ERR lysc_module_dfs_full(const struct lys_module *mod, lysc_dfs_clb dfs_clb, void *data);
2105
2106/**
Radek Krejci151a5b72018-10-19 14:21:44 +02002107 * @brief Get how the if-feature statement currently evaluates.
2108 *
2109 * @param[in] iff Compiled if-feature statement to evaluate.
Michal Vasko28d78432020-05-26 13:10:53 +02002110 * @return LY_SUCCESS if the statement evaluates to true,
2111 * @return LY_ENOT if it evaluates to false,
2112 * @return LY_ERR on error.
Radek Krejci151a5b72018-10-19 14:21:44 +02002113 */
Michal Vasko28d78432020-05-26 13:10:53 +02002114LY_ERR lysc_iffeature_value(const struct lysc_iffeature *iff);
Radek Krejci151a5b72018-10-19 14:21:44 +02002115
2116/**
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002117 * @brief Get the next feature in the module or submodules.
Radek Krejci151a5b72018-10-19 14:21:44 +02002118 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002119 * @param[in] last Last returned feature.
2120 * @param[in] pmod Parsed module and submodoules whose features to iterate over.
2121 * @param[in,out] idx Submodule index, set to 0 on first call.
2122 * @return Next found feature, NULL if the last has already been returned.
Radek Krejci151a5b72018-10-19 14:21:44 +02002123 */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002124struct 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 +02002125
Radek Krejcibed13942020-10-19 16:06:28 +02002126/**
2127 * @defgroup findxpathoptions Atomize XPath options
2128 * Options to modify behavior of ::lys_find_xpath() and ::lys_find_xpath_atoms() searching for schema nodes in schema tree.
2129 * @{
2130 */
Michal Vaskocdad7122020-11-09 21:04:44 +01002131#define LYS_FIND_XP_SCHEMA 0x08 /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */
2132#define LYS_FIND_XP_OUTPUT 0x10 /**< Search RPC/action output nodes instead of input ones. */
Radek Krejci576f8fa2020-10-26 21:23:58 +01002133/** @} findxpathoptions */
Michal Vasko072de482020-08-05 13:27:21 +02002134
Radek Krejci151a5b72018-10-19 14:21:44 +02002135/**
Michal Vasko40308e72020-10-20 16:38:40 +02002136 * @brief Get all the schema nodes that are required for @p xpath to be evaluated (atoms).
Michal Vasko519fd602020-05-26 12:17:39 +02002137 *
Michal Vasko26512682021-01-11 11:35:40 +01002138 * @param[in] ctx libyang context to use. May be NULL if @p ctx_node is set.
2139 * @param[in] ctx_node XPath schema context node. Use NULL for the root node.
Michal Vasko40308e72020-10-20 16:38:40 +02002140 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_PREF_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02002141 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko519fd602020-05-26 12:17:39 +02002142 * @param[out] set Set of found atoms (schema nodes).
2143 * @return LY_SUCCESS on success, @p set is returned.
Michal Vasko40308e72020-10-20 16:38:40 +02002144 * @return LY_ERR value on error.
Michal Vasko519fd602020-05-26 12:17:39 +02002145 */
Michal Vasko26512682021-01-11 11:35:40 +01002146LY_ERR lys_find_xpath_atoms(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *xpath,
2147 uint32_t options, struct ly_set **set);
Michal Vasko519fd602020-05-26 12:17:39 +02002148
Michal Vasko072de482020-08-05 13:27:21 +02002149/**
Michal Vasko40308e72020-10-20 16:38:40 +02002150 * @brief Get all the schema nodes that are required for @p expr to be evaluated (atoms).
Michal Vasko072de482020-08-05 13:27:21 +02002151 *
Michal Vasko26512682021-01-11 11:35:40 +01002152 * @param[in] ctx_node XPath schema context node. Use NULL for the root node.
Michal Vasko40308e72020-10-20 16:38:40 +02002153 * @param[in] cur_mod Current module for the expression (where it was "instantiated").
2154 * @param[in] expr Parsed expression to use.
2155 * @param[in] prefixes Sized array of compiled prefixes.
2156 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
2157 * @param[out] set Set of found atoms (schema nodes).
2158 * @return LY_SUCCESS on success, @p set is returned.
2159 * @return LY_ERR value on error.
2160 */
2161LY_ERR lys_find_expr_atoms(const struct lysc_node *ctx_node, const struct lys_module *cur_mod,
2162 const struct lyxp_expr *expr, const struct lysc_prefix *prefixes, uint32_t options, struct ly_set **set);
2163
2164/**
2165 * @brief Evaluate an @p xpath expression on schema nodes.
2166 *
Michal Vasko26512682021-01-11 11:35:40 +01002167 * @param[in] ctx libyang context to use for absolute @p xpath. May be NULL if @p ctx_node is set.
2168 * @param[in] ctx_node XPath schema context node for relative @p xpath. Use NULL for the root node.
Michal Vasko40308e72020-10-20 16:38:40 +02002169 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_PREF_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02002170 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko072de482020-08-05 13:27:21 +02002171 * @param[out] set Set of found schema nodes.
2172 * @return LY_SUCCESS on success, @p set is returned.
2173 * @return LY_ERR value if an error occurred.
2174 */
Michal Vasko26512682021-01-11 11:35:40 +01002175LY_ERR lys_find_xpath(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *xpath, uint32_t options,
2176 struct ly_set **set);
Michal Vasko519fd602020-05-26 12:17:39 +02002177
2178/**
Radek Krejcibc5644c2020-10-27 14:53:17 +01002179 * @brief Get all the schema nodes that are required for @p path to be evaluated (atoms).
2180 *
2181 * @param[in] path Compiled path to use.
2182 * @param[out] set Set of found atoms (schema nodes).
2183 * @return LY_SUCCESS on success, @p set is returned.
2184 * @return LY_ERR value on error.
2185 */
2186LY_ERR lys_find_lypath_atoms(const struct ly_path *path, struct ly_set **set);
2187
2188/**
2189 * @brief Get all the schema nodes that are required for @p path to be evaluated (atoms).
2190 *
Michal Vasko26512682021-01-11 11:35:40 +01002191 * @param[in] ctx libyang context to use for absolute @p path. May be NULL if @p ctx_node is set.
2192 * @param[in] ctx_node XPath schema context node for relative @p path. Use NULL for the root node.
Radek Krejcibc5644c2020-10-27 14:53:17 +01002193 * @param[in] path JSON path to examine.
2194 * @param[in] output Search operation output instead of input.
2195 * @param[out] set Set of found atoms (schema nodes).
2196 * @return LY_ERR value on error.
2197 */
2198LY_ERR lys_find_path_atoms(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *path, ly_bool output,
2199 struct ly_set **set);
2200
2201/**
2202 * @brief Get a schema node based on the given data path (JSON format, see @ref howtoXPath).
2203 *
Michal Vasko26512682021-01-11 11:35:40 +01002204 * @param[in] ctx libyang context to use for absolute @p path. May be NULL if @p ctx_node is set.
2205 * @param[in] ctx_node XPath schema context node for relative @p path. Use NULL for the root node.
Radek Krejcibc5644c2020-10-27 14:53:17 +01002206 * @param[in] path JSON path of the node to get.
2207 * @param[in] output Search operation output instead of input.
2208 * @return Found schema node or NULL.
2209 */
2210const struct lysc_node *lys_find_path(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *path,
2211 ly_bool output);
2212
2213/**
Michal Vasko03ff5a72019-09-11 13:49:33 +02002214 * @brief Types of the different schema paths.
2215 */
2216typedef enum {
Michal Vasko65de0402020-08-03 16:34:19 +02002217 LYSC_PATH_LOG, /**< Descriptive path format used in log messages */
2218 LYSC_PATH_DATA /**< Similar to ::LYSC_PATH_LOG except that schema-only nodes (choice, case) are skipped */
Michal Vasko03ff5a72019-09-11 13:49:33 +02002219} LYSC_PATH_TYPE;
2220
2221/**
Radek Krejci327de162019-06-14 12:52:07 +02002222 * @brief Generate path of the given node in the requested format.
2223 *
2224 * @param[in] node Schema path of this node will be generated.
2225 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02002226 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
2227 * If NULL, memory for the complete path is allocated.
2228 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02002229 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02002230 * 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 +02002231 */
Michal Vasko03ff5a72019-09-11 13:49:33 +02002232char *lysc_path(const struct lysc_node *node, LYSC_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02002233
2234/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002235 * @brief Available YANG schema tree structures representing YANG module.
2236 */
2237struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002238 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
2239 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01002240 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002241 const char *ns; /**< namespace of the module (module - mandatory) */
2242 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
2243 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
2244 const char *org; /**< party/company responsible for the module */
2245 const char *contact; /**< contact information for the module */
2246 const char *dsc; /**< description of the module */
2247 const char *ref; /**< cross-reference for the module */
2248
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002249 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01002250 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
2251 Available only for implemented modules. */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002252
Radek Krejci80d281e2020-09-14 17:42:54 +02002253 struct lysc_ident *identities; /**< List of compiled identities of the module ([sized array](@ref sizedarrays))
2254 Identities are outside the compiled tree to allow their linkage to the identities from
2255 the implemented modules. This avoids problems when the module became implemented in
2256 future (no matter if implicitly via augment/deviate or explicitly via
2257 ::lys_set_implemented()). Note that if the module is not implemented (compiled), the
2258 identities cannot be instantiated in data (in identityrefs). */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002259
2260 struct lys_module **augmented_by;/**< List of modules that augment this module ([sized array](@ref sizedarrays)) */
2261 struct lys_module **deviated_by; /**< List of modules that deviate this module ([sized array](@ref sizedarrays)) */
2262
Michal Vasko89b5c072020-10-06 13:52:44 +02002263 ly_bool implemented; /**< flag if the module is implemented, not just imported */
Radek Krejci95710c92019-02-11 15:49:55 +01002264 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002265 1 - the latest revision in searchdirs was not searched yet and this is the
2266 latest revision in the current context
2267 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002268};
2269
Radek Krejci151a5b72018-10-19 14:21:44 +02002270/**
Michal Vasko82c31e62020-07-17 15:30:40 +02002271 * @brief Get the current real status of the specified feature in the module.
2272 *
2273 * If the feature is enabled, but some of its if-features are false, the feature is considered
2274 * disabled.
Radek Krejci151a5b72018-10-19 14:21:44 +02002275 *
2276 * @param[in] module Module where the feature is defined.
2277 * @param[in] feature Name of the feature to inspect.
Michal Vasko82c31e62020-07-17 15:30:40 +02002278 * @return LY_SUCCESS if the feature is enabled,
2279 * @return LY_ENOT if the feature is disabled,
2280 * @return LY_ENOTFOUND if the feature was not found.
Radek Krejci151a5b72018-10-19 14:21:44 +02002281 */
Michal Vasko82c31e62020-07-17 15:30:40 +02002282LY_ERR lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02002283
2284/**
Radek Krejcia3045382018-11-22 14:30:31 +01002285 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
2286 * be from an augment.
2287 *
Radek Krejci8678fa42020-08-18 16:07:28 +02002288 * ::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 +01002289 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
2290 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
2291 * \p parent and \p module parameters.
2292 *
2293 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
2294 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
2295 * all the schema nodes are iteratively returned.
2296 *
2297 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
2298 * @param[in] parent Parent of the subtree where the function starts processing.
2299 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
2300 * module must be specified.
2301 * @param[in] options [ORed options](@ref sgetnextflags).
2302 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
2303 */
2304const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002305 const struct lysc_module *module, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002306
2307/**
Radek Krejci8678fa42020-08-18 16:07:28 +02002308 * @defgroup sgetnextflags Options for ::lys_getnext().
2309 *
2310 * Various options setting behavior of ::lys_getnext().
2311 *
Radek Krejcia3045382018-11-22 14:30:31 +01002312 * @{
2313 */
Radek Krejci8678fa42020-08-18 16:07:28 +02002314#define LYS_GETNEXT_WITHCHOICE 0x01 /**< ::lys_getnext() option to allow returning #LYS_CHOICE nodes instead of looking into them */
2315#define LYS_GETNEXT_NOCHOICE 0x02 /**< ::lys_getnext() option to ignore (kind of conditional) nodes within choice node */
2316#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 +01002317#define LYS_GETNEXT_INTONPCONT 0x08 /**< ::lys_getnext() option to look into non-presence container, instead of returning container itself */
2318#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 +01002319 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01002320/** @} sgetnextflags */
2321
2322/**
2323 * @brief Get child node according to the specified criteria.
2324 *
2325 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
2326 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
2327 * @param[in] name Name of the node to find.
2328 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
2329 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
2330 * Used as a bitmask, so multiple nodetypes can be specified.
2331 * @param[in] options [ORed options](@ref sgetnextflags).
2332 * @return Found node if any.
2333 */
Michal Vaskoe444f752020-02-10 12:20:06 +01002334const struct lysc_node *lys_find_child(const struct lysc_node *parent, const struct lys_module *module,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002335 const char *name, size_t name_len, uint16_t nodetype, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002336
2337/**
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002338 * @brief Make the specific module implemented.
2339 *
Michal Vaskoe8988e92021-01-25 11:26:29 +01002340 * If the module is already implemented but with a different set of features, the whole context is recompiled.
2341 *
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002342 * @param[in] mod Module to make implemented. It is not an error
2343 * to provide already implemented module, it just does nothing.
Michal Vaskoe8988e92021-01-25 11:26:29 +01002344 * @param[in] features Optional array specifying the enabled features terminated with NULL overriding any previous
2345 * feature setting. The feature string '*' enables all the features and array of length 1 with only the terminating
2346 * NULL explicitly disables all the features. In case the parameter is NULL, the features are untouched - left disabled
2347 * in a newly implemented module or with the current features settings in case the module is already implemented.
Michal Vaskoe444f752020-02-10 12:20:06 +01002348 * @return LY_SUCCESS on success.
2349 * @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 +01002350 * @return LY_ERR on other errors during module compilation.
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002351 */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002352LY_ERR lys_set_implemented(struct lys_module *mod, const char **features);
Radek Krejcia3045382018-11-22 14:30:31 +01002353
Radek Krejci084289f2019-07-09 17:35:30 +02002354/**
2355 * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
2356 *
2357 * 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 +02002358 * require-instance restriction), use ::lyd_value_validate().
Radek Krejci084289f2019-07-09 17:35:30 +02002359 *
2360 * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
2361 * @param[in] node Schema node for the @p value.
Michal Vaskof937cfe2020-08-03 16:07:12 +02002362 * @param[in] value String value to be checked, expected to be in JSON format.
Radek Krejci084289f2019-07-09 17:35:30 +02002363 * @param[in] value_len Length of the given @p value (mandatory).
Radek Krejci084289f2019-07-09 17:35:30 +02002364 * @return LY_SUCCESS on success
2365 * @return LY_ERR value if an error occurred.
2366 */
Michal Vaskof937cfe2020-08-03 16:07:12 +02002367LY_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 +02002368
Radek Krejci0935f412019-08-20 16:15:18 +02002369/**
2370 * @brief Stringify schema nodetype.
Michal Vaskod43d71a2020-08-07 14:54:58 +02002371 *
Radek Krejci0935f412019-08-20 16:15:18 +02002372 * @param[in] nodetype Nodetype to stringify.
2373 * @return Constant string with the name of the node's type.
2374 */
2375const char *lys_nodetype2str(uint16_t nodetype);
2376
Michal Vaskod43d71a2020-08-07 14:54:58 +02002377/**
2378 * @brief Getter for original XPath expression from a parsed expression.
2379 *
2380 * @param[in] path Parsed expression.
2381 * @return Original string expression.
2382 */
2383const char *lyxp_get_expr(const struct lyxp_expr *path);
2384
Radek Krejci2ff0d572020-05-21 15:27:28 +02002385/** @} schematree */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002386
Radek Krejci70853c52018-10-15 14:46:16 +02002387#ifdef __cplusplus
2388}
2389#endif
2390
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002391#endif /* LY_TREE_SCHEMA_H_ */