blob: 1376071f3560439f812fcd4123d9d8aeee1e44a1 [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
Michal Vaskobabf0bd2021-08-31 14:55:39 +020025#include "config.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020026#include "log.h"
27#include "tree.h"
Radek Krejcice8c1592018-10-29 15:35:51 +010028
Radek Krejci70853c52018-10-15 14:46:16 +020029#ifdef __cplusplus
30extern "C" {
31#endif
32
Radek Krejcica376bd2020-06-11 16:04:06 +020033struct ly_ctx;
Radek Krejci47fab892020-11-05 17:02:41 +010034struct ly_path;
Radek Krejcica376bd2020-06-11 16:04:06 +020035struct ly_set;
Radek Krejci47fab892020-11-05 17:02:41 +010036struct lys_module;
37struct lysc_node;
38struct lyxp_expr;
Radek Krejcica376bd2020-06-11 16:04:06 +020039
Radek Krejci5aeea3a2018-09-05 13:29:36 +020040/**
Radek Krejci8678fa42020-08-18 16:07:28 +020041 * @page howtoSchema YANG Modules
42 *
43 * To be able to work with YANG data instances, libyang has to represent YANG data models. All the processed modules are stored
44 * in libyang [context](@ref howtoContext) and loaded using [parser functions](@ref howtoSchemaParsers). It means, that there is
45 * no way to create/change YANG module programmatically. However, all the YANG model definitions are available and can be examined
46 * through the C structures. All the context's modules together form YANG Schema for the data being instantiated.
47 *
48 * Any YANG module is represented as ::lys_module. In fact, the module is represented in two different formats. As ::lys_module.parsed,
49 * there is a parsed schema reflecting the source YANG module. It is exactly what is read from the input. This format is good for
50 * converting from one format to another (YANG to YIN and vice versa), but it is not very useful for validating/manipulating YANG
51 * data. Therefore, there is ::lys_module.compiled storing the compiled YANG module. It is based on the parsed module, but all the
52 * 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
53 * `uses` or `type` references. This split also means, that the YANG module is fully validated after compilation of the parsed
54 * representation of the module. YANG submodules are available only in the parsed representation. When a submodule is compiled, it
55 * is fully integrated into its main module.
56 *
57 * The context can contain even modules without the compiled representation. Such modules are still useful as imports of other
58 * modules. The grouping or typedef definition can be even compiled into the importing modules. This is actually the main
59 * difference between the imported and implemented modules in the libyang context. The implemented modules are compiled while the
60 * imported modules are only parsed.
61 *
Radek Krejcib100b192020-10-26 08:37:45 +010062 * By default, the module is implemented (and compiled) in case it is explicitly loaded or referenced in another module as
63 * target of leafref, augment or deviation. This behavior can be changed via context options ::LY_CTX_ALL_IMPLEMENTED, when
64 * all the modules in the context are marked as implemented (note the problem with multiple revisions of a single module),
65 * or by ::LY_CTX_REF_IMPLEMENTED option, extending the set of references making the module implemented by when, must and
66 * default statements.
Radek Krejci8678fa42020-08-18 16:07:28 +020067 *
68 * All modules with deviation definition are always marked as implemented. The imported (not implemented) module can be set implemented by ::lys_set_implemented(). But
69 * the implemented module cannot be changed back to just imported module. Note also that only one revision of a specific module
70 * can be implemented in a single context. The imported modules are used only as a
71 * source of definitions for types and groupings for uses statements. The data in such modules are ignored - caller
72 * is not allowed to create the data (including instantiating identities) defined in the model via data parsers,
73 * the default nodes are not added into any data tree and mandatory nodes are not checked in the data trees.
74 *
Michal Vasko14ed9cd2021-01-28 14:16:25 +010075 * The compiled schema tree nodes are able to hold private objects (::lysc_node.priv as a pointer to a structure,
aPiecek9922ea92021-04-12 07:59:20 +020076 * function, variable, ...) used by a caller application unless ::LY_CTX_SET_PRIV_PARSED is set, in that case
77 * the ::lysc_node.priv pointers are used by libyang.
Radek Krejci8678fa42020-08-18 16:07:28 +020078 * Note that the object is not freed by libyang when the context is being destroyed. So the caller is responsible
79 * for freeing the provided structure after the context is destroyed or the private pointer is set to NULL in
Radek Krejci90ed21e2021-04-12 14:47:46 +020080 * appropriate schema nodes where the object was previously set. Also ::lysc_tree_dfs_full() can be useful to manage
81 * the private data.
Radek Krejci8678fa42020-08-18 16:07:28 +020082 *
83 * Despite all the schema structures and their members are available as part of the libyang API and callers can use
84 * it to navigate through the schema tree structure or to obtain various information, we recommend to use the following
85 * macros for the specific actions.
86 * - ::LYSC_TREE_DFS_BEGIN and ::LYSC_TREE_DFS_END to traverse the schema tree (depth-first).
87 * - ::LY_LIST_FOR and ::LY_ARRAY_FOR as described on @ref howtoStructures page.
88 *
89 * Further information about modules handling can be found on the following pages:
90 * - @subpage howtoSchemaParsers
91 * - @subpage howtoSchemaFeatures
92 * - @subpage howtoPlugins
93 * - @subpage howtoSchemaPrinters
94 *
95 * \note There are many functions to access information from the schema trees. Details are available in
96 * the [Schema Tree module](@ref schematree).
97 *
98 * For information about difference between implemented and imported modules, see the
99 * [context description](@ref howtoContext).
100 *
101 * Functions List (not assigned to above subsections)
102 * --------------------------------------------------
103 * - ::lys_getnext()
104 * - ::lys_nodetype2str()
105 * - ::lys_set_implemented()
Radek Krejci8678fa42020-08-18 16:07:28 +0200106 *
Michal Vaskod5cfa6e2020-11-23 16:56:08 +0100107 * - ::lysc_has_when()
Michal Vaskoef53c812021-10-13 10:21:03 +0200108 * - ::lysc_owner_module()
Michal Vaskod5cfa6e2020-11-23 16:56:08 +0100109 *
Michal Vasko544e58a2021-01-28 14:33:41 +0100110 * - ::lysc_node_child()
Radek Krejci8678fa42020-08-18 16:07:28 +0200111 * - ::lysc_node_actions()
112 * - ::lysc_node_notifs()
113 *
Michal Vasko544e58a2021-01-28 14:33:41 +0100114 * - ::lysp_node_child()
Radek Krejci8678fa42020-08-18 16:07:28 +0200115 * - ::lysp_node_actions()
116 * - ::lysp_node_notifs()
117 * - ::lysp_node_groupings()
118 * - ::lysp_node_typedefs()
119 */
120
121/**
122 * @page howtoSchemaFeatures YANG Features
123 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100124 * YANG feature statement is an important part of the language which can significantly affect the meaning of the schemas.
125 * Modifying features may have similar effects as loading/removing schema from the context so it is limited to context
126 * preparation period before working with data. YANG features, respectively their use in if-feature
127 * statements, are evaluated as part of schema compilation so a feature-specific compiled schema tree is generated
128 * as a result.
Radek Krejci8678fa42020-08-18 16:07:28 +0200129 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100130 * To enable any features, they must currently be specified when implementing a new schema with ::lys_parse() or
131 * ::ly_ctx_load_module(). To later examine what the status of a feature is, check its ::LYS_FENABLED flag or
132 * 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 +0200133 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100134 * To iterate over all features of a particular YANG module, use ::lysp_feature_next().
Radek Krejci8678fa42020-08-18 16:07:28 +0200135 *
136 * Note, that the feature's state can affect some of the output formats (e.g. Tree format).
137 *
138 * Functions List
139 * --------------
Radek Krejci8678fa42020-08-18 16:07:28 +0200140 * - ::lys_feature_value()
Radek Krejci8678fa42020-08-18 16:07:28 +0200141 * - ::lysc_iffeature_value()
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100142 * - ::lysp_feature_next()
Radek Krejci8678fa42020-08-18 16:07:28 +0200143 */
144
145/**
Radek Krejci2ff0d572020-05-21 15:27:28 +0200146 * @ingroup trees
Radek Krejci8678fa42020-08-18 16:07:28 +0200147 * @defgroup schematree Schema Tree
Radek Krejci2ff0d572020-05-21 15:27:28 +0200148 * @{
149 *
150 * Data structures and functions to manipulate and access schema tree.
151 */
152
Michal Vasko64246d82020-08-19 12:35:00 +0200153/* *INDENT-OFF* */
154
Radek Krejci2ff0d572020-05-21 15:27:28 +0200155/**
Michal Vasko208a04a2020-10-21 15:17:12 +0200156 * @brief Macro to iterate via all elements in a schema (sub)tree including input and output.
157 * Note that __actions__ and __notifications__ of traversed nodes __are ignored__! To traverse
158 * on all the nodes including those, use ::lysc_tree_dfs_full() instead.
159 *
160 * 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 +0200161 *
162 * The function follows deep-first search algorithm:
163 * <pre>
164 * 1
165 * / \
166 * 2 4
167 * / / \
168 * 3 5 6
169 * </pre>
170 *
171 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
Radek Krejci2a9fc652021-01-22 17:44:34 +0100172 * START can be any of the lysc_node* types (including lysc_node_action and lysc_node_notif),
Radek Krejci0935f412019-08-20 16:15:18 +0200173 * ELEM variable must be of the struct lysc_node* type.
174 *
175 * To skip a particular subtree, instead of the continue statement, set LYSC_TREE_DFS_continue
176 * variable to non-zero value.
177 *
178 * Use with opening curly bracket '{' after the macro.
179 *
180 * @param START Pointer to the starting element processed first.
181 * @param ELEM Iterator intended for use in the block.
182 */
183#define LYSC_TREE_DFS_BEGIN(START, ELEM) \
Radek Krejci857189e2020-09-01 13:26:36 +0200184 { ly_bool LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
Michal Vasko14ed9cd2021-01-28 14:16:25 +0100185 for ((ELEM) = (LYSC_TREE_DFS_next) = (struct lysc_node *)(START); \
Radek Krejci0935f412019-08-20 16:15:18 +0200186 (ELEM); \
187 (ELEM) = (LYSC_TREE_DFS_next), LYSC_TREE_DFS_continue = 0)
188
189/**
190 * @brief Macro to iterate via all elements in a (sub)tree. This is the closing part
191 * to the #LYSC_TREE_DFS_BEGIN - they always have to be used together.
192 *
193 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
Radek Krejci2a9fc652021-01-22 17:44:34 +0100194 * 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 +0200195 * ELEM variable must be pointer to the lysc_node type.
196 *
197 * Use with closing curly bracket '}' after the macro.
198 *
199 * @param START Pointer to the starting element processed first.
200 * @param ELEM Iterator intended for use in the block.
201 */
Radek Krejci0935f412019-08-20 16:15:18 +0200202#define LYSC_TREE_DFS_END(START, ELEM) \
203 /* select element for the next run - children first */ \
204 if (LYSC_TREE_DFS_continue) { \
205 (LYSC_TREE_DFS_next) = NULL; \
206 } else { \
Michal Vasko544e58a2021-01-28 14:33:41 +0100207 (LYSC_TREE_DFS_next) = (struct lysc_node *)lysc_node_child(ELEM); \
Michal Vasko208a04a2020-10-21 15:17:12 +0200208 } \
Radek Krejci0935f412019-08-20 16:15:18 +0200209 if (!(LYSC_TREE_DFS_next)) { \
Michal Vasko208a04a2020-10-21 15:17:12 +0200210 /* no children, try siblings */ \
211 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
Radek Krejci0935f412019-08-20 16:15:18 +0200212 } \
213 while (!(LYSC_TREE_DFS_next)) { \
214 /* parent is already processed, go to its sibling */ \
Radek Krejci7d95fbb2021-01-26 17:33:13 +0100215 (ELEM) = (ELEM)->parent; \
Michal Vasko208a04a2020-10-21 15:17:12 +0200216 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
217 } }
218
219/**
220 * @brief Helper macro for #LYSC_TREE_DFS_END, should not be used directly!
221 */
222#define _LYSC_TREE_DFS_NEXT(START, ELEM, NEXT) \
223 if ((ELEM) == (struct lysc_node *)(START)) { \
224 /* we are done, no next element to process */ \
225 break; \
226 } \
Michal Vasko544e58a2021-01-28 14:33:41 +0100227 (NEXT) = (ELEM)->next;
Radek Krejci0935f412019-08-20 16:15:18 +0200228
Michal Vasko64246d82020-08-19 12:35:00 +0200229/* *INDENT-ON* */
230
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200231#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
232
Radek Krejcide7a9c42021-03-10 13:13:06 +0100233/**
234 * @defgroup schemanodetypes Schema Node Types
235 * Values of the ::lysp_node.nodetype and ::lysc_node.nodetype members.
236 * @{
237 */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200238#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
239#define LYS_CONTAINER 0x0001 /**< container statement node */
240#define LYS_CHOICE 0x0002 /**< choice statement node */
241#define LYS_LEAF 0x0004 /**< leaf statement node */
242#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
243#define LYS_LIST 0x0010 /**< list statement node */
244#define LYS_ANYXML 0x0020 /**< anyxml statement node */
245#define LYS_ANYDATA 0x0060 /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
246#define LYS_CASE 0x0080 /**< case statement node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200247
Michal Vasko7f45cf22020-10-01 12:49:44 +0200248#define LYS_RPC 0x0100 /**< RPC statement node */
249#define LYS_ACTION 0x0200 /**< action statement node */
250#define LYS_NOTIF 0x0400 /**< notification statement node */
Radek Krejcie7b95092019-05-15 11:03:07 +0200251
Michal Vasko7f45cf22020-10-01 12:49:44 +0200252#define LYS_USES 0x0800 /**< uses statement node */
253#define LYS_INPUT 0x1000 /**< RPC/action input node */
254#define LYS_OUTPUT 0x2000 /**< RPC/action output node */
255#define LYS_GROUPING 0x4000
256#define LYS_AUGMENT 0x8000
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100257
Radek Krejcif13b87b2020-12-01 22:02:17 +0100258#define LYS_NODETYPE_MASK 0xffff /**< Mask for nodetypes, the value is limited for 16 bits */
Radek Krejcide7a9c42021-03-10 13:13:06 +0100259/** @} schemanodetypes */
Radek Krejcif13b87b2020-12-01 22:02:17 +0100260
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200261/**
Radek Krejci61837f72021-03-02 19:53:59 +0100262 * @brief Generic test for operation statements.
263 *
264 * This macro matches a subset of schema nodes that maps to common ::lysc_node or ::lysp_node structures. To match all
265 * such nodes, use ::LY_STMT_IS_NODE()
266 *
267 * This macro matches action and RPC.
Radek Krejci6b88a462021-02-17 12:39:34 +0100268 */
269#define LY_STMT_IS_OP(STMT) (((STMT) == LY_STMT_ACTION) || ((STMT) == LY_STMT_RPC))
270
271/**
Radek Krejci61837f72021-03-02 19:53:59 +0100272 * @brief Generic test for schema data nodes.
Radek Krejci6b88a462021-02-17 12:39:34 +0100273 *
Radek Krejci61837f72021-03-02 19:53:59 +0100274 * This macro matches a subset of schema nodes that maps to common ::lysc_node or ::lysp_node structures. To match all
275 * such nodes, use ::LY_STMT_IS_NODE()
Radek Krejci6b88a462021-02-17 12:39:34 +0100276 *
Radek Krejci61837f72021-03-02 19:53:59 +0100277 * This macro matches anydata, anyxml, augment, case, choice, container, grouping, leaf, leaf-list, list and uses. Note
278 * that the list of statements that can appear in parsed or compiled schema trees differs (e.g. no uses in compiled tree).
Radek Krejci6b88a462021-02-17 12:39:34 +0100279 */
Radek Krejci61837f72021-03-02 19:53:59 +0100280#define LY_STMT_IS_DATA_NODE(STMT) (((STMT) >= LY_STMT_ANYDATA) && ((STMT) <= LY_STMT_LIST))
281
282/**
283 * @brief Generic test for any schema node that maps to common ::lysc_node or ::lysp_node structures.
284 *
285 * Note that the list of statements that can appear in parsed or compiled schema trees differs (e.g. no uses in compiled tree).
286 *
287 * To check for some of the subsets of this test, try ::LY_STMT_IS_DATA_NODE() or ::LY_STMT_IS_OP().
288 *
289 * This macro matches action, anydata, anyxml, augment, case, choice, container, grouping, input, leaf, leaf-list, list,
290 * notification, output, RPC and uses.
291 */
292#define LY_STMT_IS_NODE(STMT) (((STMT) >= LY_STMT_NOTIFICATION) && ((STMT) <= LY_STMT_LIST))
Radek Krejci6b88a462021-02-17 12:39:34 +0100293
294/**
Radek Krejcid6b76452019-09-03 17:03:03 +0200295 * @brief List of YANG statements
296 */
297enum ly_stmt {
298 LY_STMT_NONE = 0,
Radek Krejci6b88a462021-02-17 12:39:34 +0100299
300 LY_STMT_NOTIFICATION, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node_notif *`.
301 The RPCs/Actions and Notifications are expected in a separated lists than the rest of
302 data definition nodes as it is done in generic structures of libyang. */
Radek Krejci61837f72021-03-02 19:53:59 +0100303 LY_STMT_INPUT,
304 LY_STMT_OUTPUT,
Radek Krejci6b88a462021-02-17 12:39:34 +0100305
306/* LY_STMT_IS_OP */
Radek Krejcieccf6602021-02-05 19:42:54 +0100307 LY_STMT_ACTION, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node_action *`.
Radek Krejci6b88a462021-02-17 12:39:34 +0100308 The RPCs/Actions and Notifications are expected in a separated lists than the rest of
309 data definition nodes as it is done in generic structures of libyang. */
310 LY_STMT_RPC, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node_action *`.
311 The RPCs/Actions and Notifications are expected in a separated lists than the rest of
312 data definition nodes as it is done in generic structures of libyang. */
313
Radek Krejci61837f72021-03-02 19:53:59 +0100314/* LY_STMT_IS_DATA_NODE */
Radek Krejcieccf6602021-02-05 19:42:54 +0100315 LY_STMT_ANYDATA, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
Radek Krejci6b88a462021-02-17 12:39:34 +0100316 Note that due to ::lysc_node compatibility the anydata is expected to be actually
317 mixed in the linked list with other ::lysc_node based nodes. The RPCs/Actions and
318 Notifications are expected in a separated lists as it is done in generic structures
319 of libyang. */
Radek Krejcieccf6602021-02-05 19:42:54 +0100320 LY_STMT_ANYXML, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
Radek Krejci6b88a462021-02-17 12:39:34 +0100321 Note that due to ::lysc_node compatibility the anyxml is expected to be actually
322 mixed in the linked list with other ::lysc_node based nodes. The RPCs/Actions and
323 Notifications are expected in a separated lists as it is done in generic structures
324 of libyang. */
325 LY_STMT_AUGMENT,
326 LY_STMT_CASE, /**< TODO is it possible to compile cases without the parent choice? */
327 LY_STMT_CHOICE, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
328 Note that due to ::lysc_node compatibility the choice is expected to be actually
329 mixed in the linked list with other ::lysc_node based nodes. The RPCs/Actions and
330 Notifications are expected in a separated lists as it is done in generic structures
331 of libyang. */
332 LY_STMT_CONTAINER, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
333 Note that due to ::lysc_node compatibility the container is expected to be actually
334 mixed in the linked list with other ::lysc_node based nodes. The RPCs/Actions and
335 Notifications are expected in a separated lists as it is done in generic structures
336 of libyang. */
337 LY_STMT_GROUPING,
338 LY_STMT_LEAF, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
339 Note that due to ::lysc_node compatibility the leaf is expected to be actually
340 mixed in the linked list with other ::lysc_node based nodes. The RPCs/Actions and
341 Notifications are expected in a separated lists as it is done in generic structures
342 of libyang. */
343 LY_STMT_LEAF_LIST, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
344 Note that due to ::lysc_node compatibility the leaf-list is expected to be actually
345 mixed in the linked list with other ::lysc_node based nodes. The RPCs/Actions and
346 Notifications are expected in a separated lists as it is done in generic structures
347 of libyang. */
348 LY_STMT_LIST, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
349 Note that due to ::lysc_node compatibility the list is expected to be actually
350 mixed in the linked list with other ::lysc_node based nodes. The RPCs/Actions and
351 Notifications are expected in a separated lists as it is done in generic structures
352 of libyang. */
353 LY_STMT_USES,
354
355/* rest */
Radek Krejcid6b76452019-09-03 17:03:03 +0200356 LY_STMT_ARGUMENT,
Radek Krejcid6b76452019-09-03 17:03:03 +0200357 LY_STMT_BASE,
358 LY_STMT_BELONGS_TO,
359 LY_STMT_BIT,
Radek Krejcieccf6602021-02-05 19:42:54 +0100360 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 +0200361 LY_STMT_CONTACT,
Radek Krejcieccf6602021-02-05 19:42:54 +0100362 LY_STMT_DEFAULT,
Radek Krejci6b88a462021-02-17 12:39:34 +0100363 LY_STMT_DESCRIPTION, /**< in ::lysc_ext_substmt.storage stored as a pointer to `const char *` (cardinality < #LY_STMT_CARD_SOME)
364 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200365 LY_STMT_DEVIATE,
366 LY_STMT_DEVIATION,
367 LY_STMT_ENUM,
368 LY_STMT_ERROR_APP_TAG,
369 LY_STMT_ERROR_MESSAGE,
370 LY_STMT_EXTENSION,
Radek Krejcieccf6602021-02-05 19:42:54 +0100371 LY_STMT_EXTENSION_INSTANCE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200372 LY_STMT_FEATURE,
373 LY_STMT_FRACTION_DIGITS,
Radek Krejcid6b76452019-09-03 17:03:03 +0200374 LY_STMT_IDENTITY,
Radek Krejci6b88a462021-02-17 12:39:34 +0100375 LY_STMT_IF_FEATURE, /**< if-feature statements are not compiled, they are evaluated and the parent statement is
376 preserved only in case the evaluation of all the if-feature statements is true.
377 Therefore there is no storage expected. */
Radek Krejcid6b76452019-09-03 17:03:03 +0200378 LY_STMT_IMPORT,
379 LY_STMT_INCLUDE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200380 LY_STMT_KEY,
Radek Krejcid6b76452019-09-03 17:03:03 +0200381 LY_STMT_LENGTH,
Radek Krejcieccf6602021-02-05 19:42:54 +0100382 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 +0200383 LY_STMT_MAX_ELEMENTS,
384 LY_STMT_MIN_ELEMENTS,
385 LY_STMT_MODIFIER,
386 LY_STMT_MODULE,
387 LY_STMT_MUST,
388 LY_STMT_NAMESPACE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200389 LY_STMT_ORDERED_BY,
390 LY_STMT_ORGANIZATION,
Radek Krejcid6b76452019-09-03 17:03:03 +0200391 LY_STMT_PATH,
392 LY_STMT_PATTERN,
393 LY_STMT_POSITION,
394 LY_STMT_PREFIX,
395 LY_STMT_PRESENCE,
396 LY_STMT_RANGE,
Radek Krejci6b88a462021-02-17 12:39:34 +0100397 LY_STMT_REFERENCE, /**< in ::lysc_ext_substmt.storage stored as a pointer to `const char *` (cardinality < #LY_STMT_CARD_SOME)
398 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200399 LY_STMT_REFINE,
400 LY_STMT_REQUIRE_INSTANCE,
401 LY_STMT_REVISION,
402 LY_STMT_REVISION_DATE,
Radek Krejcieccf6602021-02-05 19:42:54 +0100403 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 +0200404 LY_STMT_SUBMODULE,
Radek Krejcieccf6602021-02-05 19:42:54 +0100405 LY_STMT_TYPE, /**< in ::lysc_ext_substmt.storage stored as a pointer to `struct lysc_type *` (cardinality < #LY_STMT_CARD_SOME)
406 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_type **` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200407 LY_STMT_TYPEDEF,
408 LY_STMT_UNIQUE,
Radek Krejcieccf6602021-02-05 19:42:54 +0100409 LY_STMT_UNITS, /**< in ::lysc_ext_substmt.storage stored as a pointer to `const char *` (cardinality < #LY_STMT_CARD_SOME)
410 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200411 LY_STMT_VALUE,
412 LY_STMT_WHEN,
413 LY_STMT_YANG_VERSION,
Radek Krejci2b0f0f12021-03-02 16:02:35 +0100414 LY_STMT_YIN_ELEMENT,
415
416 /* separated from the list of statements
417 * the following tokens are part of the syntax and parsers have to work
418 * with them, but they are not a standard YANG statements
419 */
420 LY_STMT_SYNTAX_SEMICOLON,
421 LY_STMT_SYNTAX_LEFT_BRACE,
422 LY_STMT_SYNTAX_RIGHT_BRACE,
423
424 /*
425 * YIN-specific tokens, still they are part of the syntax, but not the standard statements
426 */
427 LY_STMT_ARG_TEXT,
428 LY_STMT_ARG_VALUE
Radek Krejcid6b76452019-09-03 17:03:03 +0200429};
430
431/**
Radek Krejcif8ca8192021-03-02 16:50:06 +0100432 * @brief Stringify statement identifier.
433 * @param[in] stmt The statement identifier to stringify.
434 * @return Constant string representation of the given @p stmt.
435 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +0100436LIBYANG_API_DECL const char *ly_stmt2str(enum ly_stmt stmt);
Radek Krejcif8ca8192021-03-02 16:50:06 +0100437
438/**
Radek Krejci39b7fc22021-02-26 23:29:18 +0100439 * @brief Convert nodetype to statement identifier
440 * @param[in] nodetype Nodetype to convert.
441 * @return Statement identifier representing the given @p nodetype.
442 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +0100443LIBYANG_API_DECL enum ly_stmt lys_nodetype2stmt(uint16_t nodetype);
Radek Krejci39b7fc22021-02-26 23:29:18 +0100444
445/**
Radek Krejcib1c11532021-03-29 14:14:19 +0200446 * @brief Possible cardinalities of the YANG statements.
447 *
448 * Used in extensions plugins to define cardinalities of the extension instance substatements.
449 */
450enum ly_stmt_cardinality {
451 LY_STMT_CARD_OPT, /* 0..1 */
452 LY_STMT_CARD_MAND, /* 1 */
453 LY_STMT_CARD_SOME, /* 1..n */
454 LY_STMT_CARD_ANY /* 0..n */
455};
456
457/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200458 * @brief YANG import-stmt
459 */
460struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200461 struct lys_module *module; /**< pointer to the imported module
462 (mandatory, but resolved when the referring module is completely parsed) */
463 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200464 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200465 const char *dsc; /**< description */
466 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200467 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100468 uint16_t flags; /**< LYS_INTERNAL value (@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200469 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
470};
471
472/**
473 * @brief YANG include-stmt
474 */
475struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100476 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200477 (mandatory, but resolved when the referring module is completely parsed) */
478 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200479 const char *dsc; /**< description */
480 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200481 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200482 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
Radek Krejci771928a2021-01-19 13:42:36 +0100483 ly_bool injected; /**< flag to mark includes copied into main module from submodules,
484 only for backward compatibility with YANG 1.0, which does not require the
485 main module to include all submodules. */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200486};
487
488/**
489 * @brief YANG extension-stmt
490 */
491struct lysp_ext {
492 const char *name; /**< extension name */
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100493 const char *argname; /**< argument name, NULL if not specified */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200494 const char *dsc; /**< description statement */
495 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200496 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200497 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */
Michal Vasko5fe75f12020-03-02 13:52:37 +0100498
Radek Krejci720d2612021-03-03 19:44:22 +0100499 struct lysc_ext *compiled; /**< pointer to the compiled extension definition.
500 The extension definition is compiled only if there is compiled extension instance,
501 otherwise this pointer remains NULL. The compiled extension definition is shared
502 among all extension instances. */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200503};
504
505/**
506 * @brief Helper structure for generic storage of the extension instances content.
507 */
508struct lysp_stmt {
509 const char *stmt; /**< identifier of the statement */
510 const char *arg; /**< statement's argument */
Radek Krejci8df109d2021-04-23 12:19:08 +0200511 LY_VALUE_FORMAT format; /**< prefix format of the identifier/argument (::LY_VALUE_XML is YIN format) */
Radek Krejci0b013302021-03-29 15:22:32 +0200512 void *prefix_data; /**< Format-specific data for prefix resolution (see ly_resolve_prefix()) */
Michal Vaskofc2cd072021-02-24 13:17:17 +0100513
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200514 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200515 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
David Sedlákb9d75c42019-08-14 10:49:42 +0200516 uint16_t flags; /**< statement flags, can be set to LYS_YIN_ATTR */
Radek Krejci335332a2019-09-05 13:03:35 +0200517 enum ly_stmt kw; /**< numeric respresentation of the stmt value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200518};
519
David Sedlákae4b4512019-08-14 10:45:56 +0200520#define LYS_YIN 0x1 /**< used to specify input format of extension instance */
521
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200522/**
523 * @brief YANG extension instance
524 */
525struct lysp_ext_instance {
David Sedlákbbd06ca2019-06-27 14:15:38 +0200526 const char *name; /**< extension identifier, including possible prefix */
527 const char *argument; /**< optional value of the extension's argument */
aPiecek60d9d672021-04-27 15:49:57 +0200528 LY_VALUE_FORMAT format; /**< prefix format of the extension name/argument (::LY_VALUE_XML is YIN format) */
529 struct lysp_node *parsed; /**< Simply parsed (unresolved) YANG schema tree serving as a cache.
530 Only lys_compile_extension_instance() can set this. */
Michal Vaskofc2cd072021-02-24 13:17:17 +0100531 void *prefix_data; /**< Format-specific data for prefix resolution
Radek Krejci0b013302021-03-29 15:22:32 +0200532 (see ly_resolve_prefix()) */
Michal Vaskofc2cd072021-02-24 13:17:17 +0100533
Radek Krejci5f9a3672021-03-05 21:35:22 +0100534 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
535
Radek Krejci335332a2019-09-05 13:03:35 +0200536 void *parent; /**< pointer to the parent element holding the extension instance(s), use
Radek Krejciab430862021-03-02 20:13:40 +0100537 ::lysp_ext_instance#parent_stmt to access the schema element */
Radek Krejciab430862021-03-02 20:13:40 +0100538 enum ly_stmt parent_stmt; /**< value identifying placement of the extension instance */
539 LY_ARRAY_COUNT_TYPE parent_stmt_index; /**< in case the instance is in a substatement, this identifies
540 the index of that substatement in its [sized array](@ref sizedarrays) (if any) */
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100541 uint16_t flags; /**< LYS_INTERNAL value (@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200542};
543
544/**
545 * @brief YANG feature-stmt
546 */
547struct lysp_feature {
548 const char *name; /**< feature name (mandatory) */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100549 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
550 struct lysc_iffeature *iffeatures_c; /**< compiled if-features */
551 struct lysp_feature **depfeatures; /**< list of pointers to other features depending on this one
552 ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200553 const char *dsc; /**< description statement */
554 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200555 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100556 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values and
557 LYS_FENABLED are allowed */
558};
559
560/**
561 * @brief Compiled YANG if-feature-stmt
562 */
563struct lysc_iffeature {
564 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
565 struct lysp_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200566};
567
568/**
Michal Vasko7f45cf22020-10-01 12:49:44 +0200569 * @brief Qualified name (optional prefix followed by an identifier).
570 */
571struct lysp_qname {
572 const char *str; /**< qualified name string */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200573 const struct lysp_module *mod; /**< module to resolve any prefixes found in the string, it must be
Michal Vasko7f45cf22020-10-01 12:49:44 +0200574 stored explicitly because of deviations/refines */
575};
576
577/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200578 * @brief YANG identity-stmt
579 */
580struct lysp_ident {
581 const char *name; /**< identity name (mandatory), including possible prefix */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200582 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200583 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200584 const char *dsc; /**< description statement */
585 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200586 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200587 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
588};
589
Michal Vasko71e64ca2018-09-07 16:30:29 +0200590/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200591 * @brief Covers restrictions: range, length, pattern, must
592 */
593struct lysp_restr {
Radek Krejcif13b87b2020-12-01 22:02:17 +0100594#define LYSP_RESTR_PATTERN_ACK 0x06
595#define LYSP_RESTR_PATTERN_NACK 0x15
Michal Vasko7f45cf22020-10-01 12:49:44 +0200596 struct lysp_qname arg; /**< The restriction expression/value (mandatory);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200597 in case of pattern restriction, the first byte has a special meaning:
598 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
599 const char *emsg; /**< error-message */
600 const char *eapptag; /**< error-app-tag value */
601 const char *dsc; /**< description */
602 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200603 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200604};
605
606/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200607 * @brief YANG revision-stmt
608 */
609struct lysp_revision {
Radek Krejcicb3e6472021-01-06 08:19:01 +0100610 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200611 const char *dsc; /**< description statement */
612 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200613 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200614};
615
616/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200617 * @brief Enumeration/Bit value definition
618 */
619struct lysp_type_enum {
620 const char *name; /**< name (mandatory) */
621 const char *dsc; /**< description statement */
622 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200623 int64_t value; /**< enum's value or bit's position */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200624 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200625 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200626 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
627 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200628};
629
630/**
631 * @brief YANG type-stmt
632 *
633 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
634 */
635struct lysp_type {
636 const char *name; /**< name of the type (mandatory) */
637 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
638 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200639 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
640 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
641 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Michal Vasko004d3152020-06-11 19:59:22 +0200642 struct lyxp_expr *path; /**< parsed path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200643 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200644 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
645 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200646
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200647 const struct lysp_module *pmod; /**< (sub)module where the type is defined (needed for deviations) */
Michal Vasko00e8e652022-06-08 10:09:18 +0200648 struct lysc_type *compiled; /**< pointer to the compiled custom type, not used for built-in types */
Radek Krejci2167ee12018-11-02 16:09:07 +0100649
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200650 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
651 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100652 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200653};
654
655/**
656 * @brief YANG typedef-stmt
657 */
658struct lysp_tpdf {
659 const char *name; /**< name of the newly defined type (mandatory) */
660 const char *units; /**< units of the newly defined type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200661 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 +0200662 const char *dsc; /**< description statement */
663 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200664 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200665 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100666 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200667};
668
669/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200670 * @brief YANG when-stmt
671 */
672struct lysp_when {
673 const char *cond; /**< specified condition (mandatory) */
674 const char *dsc; /**< description statement */
675 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200676 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200677};
678
679/**
680 * @brief YANG refine-stmt
681 */
682struct lysp_refine {
683 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
684 const char *dsc; /**< description statement */
685 const char *ref; /**< reference statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200686 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200687 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200688 const char *presence; /**< presence description */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200689 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200690 uint32_t min; /**< min-elements constraint */
691 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200692 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200693 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
694};
695
696/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200697 * @ingroup schematree
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200698 * @defgroup deviatetypes Deviate types
Radek Krejci8678fa42020-08-18 16:07:28 +0200699 *
700 * Type of the deviate operation (used as ::lysp_deviate.mod)
701 *
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200702 * @{
703 */
704#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
705#define LYS_DEV_ADD 2 /**< deviate type add */
706#define LYS_DEV_DELETE 3 /**< deviate type delete */
707#define LYS_DEV_REPLACE 4 /**< deviate type replace */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200708/** @} deviatetypes */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200709
710/**
711 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
712 */
713struct lysp_deviate {
714 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
715 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200716 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200717};
718
719struct lysp_deviate_add {
720 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
721 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200722 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200723 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200724 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200725 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
726 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
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_deviate_del {
733 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
734 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200735 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200736 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200737 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200738 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
739 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200740};
741
742struct lysp_deviate_rpl {
743 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
744 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200745 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200746 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200747 const char *units; /**< units of the values */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200748 struct lysp_qname dflt; /**< default value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200749 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
750 uint32_t min; /**< min-elements constraint */
751 uint32_t max; /**< max-elements constraint, 0 means unbounded */
752};
753
754struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200755 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200756 const char *dsc; /**< description statement */
757 const char *ref; /**< reference statement */
Michal Vasko22df3f02020-08-24 13:29:22 +0200758 struct lysp_deviate *deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200759 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200760};
761
Radek Krejci4f28eda2018-11-12 11:46:16 +0100762/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100763 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200764 * @defgroup spnodeflags Parsed schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100765 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200766 * Various flags for parsed schema nodes (used as ::lysp_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100767 *
768 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
769 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200770 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100771 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
772 * 5 - list 10 - input 15 - typedef 20 - deviate
773 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200774 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
775 * 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
776 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200777 * 1 LYS_CONFIG_W |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200778 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
779 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200780 * 2 LYS_CONFIG_R |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200781 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
782 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
783 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
784 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
785 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
786 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
787 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
788 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
789 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
790 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
791 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
792 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
793 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100794 * LYS_FENABLED | | | | | | | | | | | |x| | | | | | | | | | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200795 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
796 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
797 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
798 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
799 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
800 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
801 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
802 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
803 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
804 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
805 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
806 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
807 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
808 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
809 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
810 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
811 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
812 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
813 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200814 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
David Sedlákae4b4512019-08-14 10:45:56 +0200815 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x|
Michal Vasko5297a432020-08-31 12:27:51 +0200816 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
817 * 12 LYS_YIN_ARGUMENT | | | | | | | | | | | | | | | | | | | | | | |x|
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100818 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
819 * 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 +0200820 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100821 *
822 */
823
824/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100825 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200826 * @defgroup scnodeflags Compiled schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100827 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200828 * Various flags for compiled schema nodes (used as ::lysc_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100829 *
Radek Krejci61e042e2019-09-10 15:53:09 +0200830 * 1 - container 6 - anydata/anyxml 11 - identity
831 * 2 - choice 7 - case 12 - extension
832 * 3 - leaf 8 - notification 13 - bitenum
Michal Vasko03ff5a72019-09-11 13:49:33 +0200833 * 4 - leaflist 9 - rpc/action 14 - when
Michal Vaskoecd62de2019-11-13 12:35:11 +0100834 * 5 - list 10 - feature
Radek Krejci4f28eda2018-11-12 11:46:16 +0100835 *
Michal Vaskoecd62de2019-11-13 12:35:11 +0100836 * 1 1 1 1 1
837 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
838 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskod09b7622021-01-26 09:14:13 +0100839 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100840 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskod09b7622021-01-26 09:14:13 +0100841 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100842 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskof4fa90d2021-11-11 15:05:19 +0100843 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x|x|x|x|x|x|
Michal Vaskoecd62de2019-11-13 12:35:11 +0100844 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskof4fa90d2021-11-11 15:05:19 +0100845 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x|x|x|x|x|x|
Michal Vaskoecd62de2019-11-13 12:35:11 +0100846 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskof4fa90d2021-11-11 15:05:19 +0100847 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x|x|x|x|x|x|
Michal Vaskoecd62de2019-11-13 12:35:11 +0100848 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
849 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
850 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
851 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
852 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | |
853 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
854 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
855 * LYS_PRESENCE |x| | | | | | | | | | | | | |
856 * LYS_UNIQUE | | |x| | | | | | | | | | | |
857 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
858 * 9 LYS_KEY | | |x| | | | | | | | | | | |
Michal Vaskof4fa90d2021-11-11 15:05:19 +0100859 * LYS_DISABLED | | | | | | | | | | | | |x| |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100860 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
861 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
Michal Vaskod1e53b92021-01-28 13:11:06 +0100862 * LYS_IS_ENUM | | | | | | | | | | | | |x| |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100863 * LYS_KEYLESS | | | | |x| | | | | | | | | |
864 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
865 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
866 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
867 * 12 LYS_SET_CONFIG |x|x|x|x|x|x| | | | | | | | |
Michal Vaskod1e53b92021-01-28 13:11:06 +0100868 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
869 * 13 LYS_IS_INPUT |x|x|x|x|x|x|x| | | | | | | |
870 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
871 * 14 LYS_IS_OUTPUT |x|x|x|x|x|x|x| | | | | | | |
872 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
873 * 15 LYS_IS_NOTIF |x|x|x|x|x|x|x| | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100874 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100875 *
876 */
877
878/**
879 * @defgroup snodeflags Schema nodes flags
Radek Krejci8678fa42020-08-18 16:07:28 +0200880 *
881 * Various flags for schema nodes ([parsed](@ref spnodeflags) as well as [compiled](@ref scnodeflags)).
882 *
Radek Krejci4f28eda2018-11-12 11:46:16 +0100883 * @{
884 */
Michal Vaskod1e53b92021-01-28 13:11:06 +0100885#define LYS_CONFIG_W 0x01 /**< config true; */
886#define LYS_CONFIG_R 0x02 /**< config false; */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200887#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100888#define LYS_STATUS_CURR 0x04 /**< status current; */
889#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
890#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
891#define LYS_STATUS_MASK 0x1C /**< mask for status value */
892#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100893 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
894 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
895 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
896 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100897#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
898 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
899 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100900#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Michal Vaskoc118ae22020-08-06 14:51:09 +0200901#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, but it is not only for explicit presence
902 containers, but also for NP containers with some meaning, applicable only to
903 ::lysc_node_container */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100904#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 +0100905#define LYS_KEY 0x0100 /**< flag for leafs being a key of a list, applicable only to ::lysc_node_leaf */
906#define LYS_KEYLESS 0x0200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Michal Vaskof4fa90d2021-11-11 15:05:19 +0100907#define LYS_DISABLED 0x0100 /**< internal flag for a disabled statement, used only for bits/enums */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100908#define LYS_FENABLED 0x20 /**< feature enabled flag, applicable only to ::lysp_feature. */
Michal Vaskoe78faec2021-04-08 17:24:43 +0200909#define LYS_ORDBY_SYSTEM 0x80 /**< ordered-by system configuration lists, applicable only to
910 ::lysc_node_leaflist/::lysp_node_leaflist and ::lysc_node_list/::lysp_node_list */
911#define LYS_ORDBY_USER 0x40 /**< ordered-by user configuration lists, applicable only to
912 ::lysc_node_leaflist/::lysp_node_leaflist and ::lysc_node_list/::lysp_node_list;
913 is always set for state leaf-lists, and key-less lists */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100914#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
915#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
Michal Vaskod1e53b92021-01-28 13:11:06 +0100916#define LYS_YINELEM_FALSE 0x0100 /**< yin-element false for extension's argument */
917#define LYS_YINELEM_MASK 0x0180 /**< mask for yin-element value */
918#define LYS_USED_GRP 0x0400 /**< internal flag for validating not-instantiated groupings
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200919 (resp. do not validate again the instantiated groupings). */
Michal Vaskod1e53b92021-01-28 13:11:06 +0100920#define LYS_SET_VALUE 0x0200 /**< value attribute is set */
921#define LYS_SET_MIN 0x0200 /**< min attribute is set */
922#define LYS_SET_MAX 0x0400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100923
924#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
925#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
926#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
927#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
928#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
929#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
930#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
931#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
932#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
933#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100934#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 +0100935 cases of choice. This information is important for refines, since it is prohibited to make leafs
936 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100937 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
938 between own default or the default values taken from the type. */
939#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 +0100940#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 +0100941
Michal Vaskod1e53b92021-01-28 13:11:06 +0100942#define LYS_SINGLEQUOTED 0x0100 /**< flag for single-quoted argument of an extension instance's substatement, only when the source is YANG */
943#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 +0200944
Michal Vaskod1e53b92021-01-28 13:11:06 +0100945#define LYS_YIN_ATTR 0x0400 /**< flag to identify YIN attribute parsed as extension's substatement, only when the source is YIN */
946#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 +0200947
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100948#define LYS_INTERNAL 0x1000 /**< flag to identify internal parsed statements that should not be printed */
949
Michal Vaskod1e53b92021-01-28 13:11:06 +0100950#define LYS_IS_ENUM 0x0200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
951
952#define LYS_IS_INPUT 0x1000 /**< flag for nodes that are in the subtree of an input statement */
953
954#define LYS_IS_OUTPUT 0x2000 /**< flag for nodes that are in the subtree of an output statement */
955
956#define LYS_IS_NOTIF 0x4000 /**< flag for nodes that are in the subtree of a notification statement */
Radek Krejci693262f2019-04-29 15:23:20 +0200957
Radek Krejcife909632019-02-12 15:34:42 +0100958#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200959/** @} snodeflags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200960
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200961/**
962 * @brief Generic YANG data node
963 */
964struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100965 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejcide7a9c42021-03-10 13:13:06 +0100966 uint16_t nodetype; /**< [type of the node](@ref schemanodetypes) (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200967 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100968 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200969 const char *name; /**< node name (mandatory) */
970 const char *dsc; /**< description statement */
971 const char *ref; /**< reference statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200972 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)),
973 must be qname because of refines */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200974 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200975};
976
977/**
978 * @brief Extension structure of the lysp_node for YANG container
979 */
980struct lysp_node_container {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100981 union {
982 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +0200983
Radek Krejci2a9fc652021-01-22 17:44:34 +0100984 struct {
985 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
986 uint16_t nodetype; /**< LYS_CONTAINER */
987 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
988 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
989 const char *name; /**< node name (mandatory) */
990 const char *dsc; /**< description statement */
991 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100992 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
993 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
994 };
995 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200996
997 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200998 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +0100999 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001000 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001001 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001002 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001003 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001004 struct lysp_node_action *actions;/**< list of actions (linked list) */
1005 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001006};
1007
1008struct lysp_node_leaf {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001009 union {
1010 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001011
Radek Krejci2a9fc652021-01-22 17:44:34 +01001012 struct {
1013 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1014 uint16_t nodetype; /**< LYS_LEAF */
1015 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1016 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1017 const char *name; /**< node name (mandatory) */
1018 const char *dsc; /**< description statement */
1019 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001020 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1021 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1022 };
1023 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001024
1025 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001026 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001027 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001028 struct lysp_type type; /**< type of the leaf node (mandatory) */
1029 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001030 struct lysp_qname dflt; /**< default value, it may or may not be a qualified name */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001031};
1032
1033struct lysp_node_leaflist {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001034 union {
1035 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001036
Radek Krejci2a9fc652021-01-22 17:44:34 +01001037 struct {
1038 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1039 uint16_t nodetype; /**< LYS_LEAFLIST */
1040 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1041 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1042 const char *name; /**< node name (mandatory) */
1043 const char *dsc; /**< description statement */
1044 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001045 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1046 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1047 };
1048 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001049
1050 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001051 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001052 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001053 struct lysp_type type; /**< type of the leaf node (mandatory) */
1054 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001055 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)), they may or
1056 may not be qualified names */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001057 uint32_t min; /**< min-elements constraint */
1058 uint32_t max; /**< max-elements constraint, 0 means unbounded */
1059};
1060
1061struct lysp_node_list {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001062 union {
1063 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001064
Radek Krejci2a9fc652021-01-22 17:44:34 +01001065 struct {
1066 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1067 uint16_t nodetype; /**< LYS_LIST */
1068 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1069 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1070 const char *name; /**< node name (mandatory) */
1071 const char *dsc; /**< description statement */
1072 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001073 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1074 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1075 };
1076 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001077
1078 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001079 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001080 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001081 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001082 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001083 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001084 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001085 struct lysp_node_action *actions;/**< list of actions (linked list) */
1086 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001087 struct lysp_qname *uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001088 uint32_t min; /**< min-elements constraint */
1089 uint32_t max; /**< max-elements constraint, 0 means unbounded */
1090};
1091
1092struct lysp_node_choice {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001093 union {
1094 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001095
Radek Krejci2a9fc652021-01-22 17:44:34 +01001096 struct {
1097 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1098 uint16_t nodetype; /**< LYS_CHOICE */
1099 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1100 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1101 const char *name; /**< node name (mandatory) */
1102 const char *dsc; /**< description statement */
1103 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001104 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1105 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1106 };
1107 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001108
1109 /* choice */
1110 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001111 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001112 struct lysp_qname dflt; /**< default case */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001113};
1114
1115struct lysp_node_case {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001116 union {
1117 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001118
Radek Krejci2a9fc652021-01-22 17:44:34 +01001119 struct {
1120 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1121 uint16_t nodetype; /**< LYS_CASE */
1122 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1123 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1124 const char *name; /**< node name (mandatory) */
1125 const char *dsc; /**< description statement */
1126 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001127 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1128 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1129 };
1130 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001131
1132 /* case */
1133 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001134 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001135};
1136
1137struct lysp_node_anydata {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001138 union {
1139 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001140
Radek Krejci2a9fc652021-01-22 17:44:34 +01001141 struct {
1142 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1143 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1144 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1145 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1146 const char *name; /**< node name (mandatory) */
1147 const char *dsc; /**< description statement */
1148 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001149 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1150 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1151 };
1152 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001153
1154 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001155 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001156 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001157};
1158
1159struct lysp_node_uses {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001160 union {
1161 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001162
Radek Krejci2a9fc652021-01-22 17:44:34 +01001163 struct {
1164 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1165 uint16_t nodetype; /**< LYS_USES */
1166 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1167 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1168 const char *name; /**< grouping name reference (mandatory) */
1169 const char *dsc; /**< description statement */
1170 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001171 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1172 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1173 };
1174 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001175
1176 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001177 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001178 struct lysp_node_augment *augments; /**< list of augments (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001179 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001180};
1181
1182/**
1183 * @brief YANG input-stmt and output-stmt
1184 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001185struct lysp_node_action_inout {
1186 union {
1187 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001188
Radek Krejci2a9fc652021-01-22 17:44:34 +01001189 struct {
1190 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1191 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
1192 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1193 struct lysp_node *next; /**< NULL */
1194 const char *name; /**< empty string */
1195 const char *dsc; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1196 const char *ref; /**< ALWAYS NULL, compatibility member with ::lysp_node */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001197 struct lysp_qname *iffeatures; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1198 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1199 };
1200 }; /**< common part corresponding to ::lysp_node */
1201
1202 /* inout */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001203 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1204 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001205 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci01180ac2021-01-27 08:48:22 +01001206 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001207};
1208
1209/**
1210 * @brief YANG rpc-stmt and action-stmt
1211 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001212struct lysp_node_action {
1213 union {
1214 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001215
Radek Krejci2a9fc652021-01-22 17:44:34 +01001216 struct {
1217 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1218 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
1219 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1220 struct lysp_node_action *next; /**< pointer to the next action (NULL if there is no one) */
1221 const char *name; /**< grouping name reference (mandatory) */
1222 const char *dsc; /**< description statement */
1223 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001224 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1225 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1226 };
1227 }; /**< common part corresponding to ::lysp_node */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001228
1229 /* action */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001230 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1231 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
1232
1233 struct lysp_node_action_inout input; /**< RPC's/Action's input */
1234 struct lysp_node_action_inout output; /**< RPC's/Action's output */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001235};
1236
1237/**
1238 * @brief YANG notification-stmt
1239 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001240struct lysp_node_notif {
1241 union {
1242 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001243
Radek Krejci2a9fc652021-01-22 17:44:34 +01001244 struct {
1245 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1246 uint16_t nodetype; /**< LYS_NOTIF */
1247 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1248 struct lysp_node_notif *next; /**< pointer to the next notification (NULL if there is no one) */
1249 const char *name; /**< grouping name reference (mandatory) */
1250 const char *dsc; /**< description statement */
1251 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001252 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1253 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1254 };
1255 }; /**< common part corresponding to ::lysp_node */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001256
1257 /* notif */
1258 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001259 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1260 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci01180ac2021-01-27 08:48:22 +01001261 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001262};
1263
1264/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001265 * @brief YANG grouping-stmt
1266 */
1267struct lysp_node_grp {
1268 union {
1269 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001270
Radek Krejci2a9fc652021-01-22 17:44:34 +01001271 struct {
1272 struct lysp_node *parent;/**< parent node (NULL if this is a top-level grouping) */
1273 uint16_t nodetype; /**< LYS_GROUPING */
1274 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1275 struct lysp_node_grp *next; /**< pointer to the next grouping (NULL if there is no one) */
1276 const char *name; /**< grouping name (mandatory) */
1277 const char *dsc; /**< description statement */
1278 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001279 struct lysp_qname *iffeatures; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1280 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1281 };
1282 }; /**< common part corresponding to ::lysp_node */
1283
1284 /* grp */
1285 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1286 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci01180ac2021-01-27 08:48:22 +01001287 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001288 struct lysp_node_action *actions; /**< list of actions (linked list) */
1289 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
1290};
1291
1292/**
1293 * @brief YANG uses-augment-stmt and augment-stmt (compatible with struct lysp_node )
1294 */
1295struct lysp_node_augment {
1296 union {
1297 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001298
Radek Krejci2a9fc652021-01-22 17:44:34 +01001299 struct {
1300 struct lysp_node *parent;/**< parent node (NULL if this is a top-level augment) */
1301 uint16_t nodetype; /**< LYS_AUGMENT */
1302 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1303 struct lysp_node_augment *next; /**< pointer to the next augment (NULL if there is no one) */
1304 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
1305 const char *dsc; /**< description statement */
1306 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001307 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1308 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1309 };
1310 }; /**< common part corresponding to ::lysp_node */
1311
1312 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001313 struct lysp_when *when; /**< when statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001314 struct lysp_node_action *actions;/**< list of actions (linked list) */
1315 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
1316};
1317
1318/**
Radek Krejcif0fceb62018-09-05 14:58:45 +02001319 * @brief supported YANG schema version values
1320 */
1321typedef enum LYS_VERSION {
1322 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
Radek Krejci96e48da2020-09-04 13:18:06 +02001323 LYS_VERSION_1_0 = 1, /**< YANG 1 (1.0) */
Radek Krejcif0fceb62018-09-05 14:58:45 +02001324 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
1325} LYS_VERSION;
1326
1327/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001328 * @brief Printable YANG schema tree structure representing YANG module.
1329 *
1330 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
1331 */
1332struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001333 struct lys_module *mod; /**< covering module structure */
1334
Radek Krejcib7db73a2018-10-24 14:18:40 +02001335 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1336 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001337 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1338 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001339 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1340 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1341 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1342 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001343 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001344 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001345 struct lysp_node_augment *augments; /**< list of augments (linked list) */
1346 struct lysp_node_action *rpcs; /**< list of RPCs (linked list) */
1347 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001348 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001349 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001350
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001351 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001352 uint8_t parsing : 1; /**< flag for circular check */
1353 uint8_t is_submod : 1; /**< always 0 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001354};
1355
1356struct lysp_submodule {
Michal Vaskoc3781c32020-10-06 14:04:08 +02001357 struct lys_module *mod; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001358
1359 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1360 in the list is always the last (newest) revision of the module */
1361 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1362 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
1363 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1364 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1365 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1366 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001367 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001368 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001369 struct lysp_node_augment *augments; /**< list of augments (linked list) */
1370 struct lysp_node_action *rpcs; /**< list of RPCs (linked list) */
1371 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001372 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001373 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001374
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001375 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001376 uint8_t parsing : 1; /**< flag for circular check */
1377 uint8_t is_submod : 1; /**< always 1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001378
Michal Vaskoc3781c32020-10-06 14:04:08 +02001379 uint8_t latest_revision : 2; /**< flag to mark the latest available revision:
Radek Krejci086c7132018-10-26 15:29:04 +02001380 1 - the latest revision in searchdirs was not searched yet and this is the
1381 latest revision in the current context
1382 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001383 const char *name; /**< name of the module (mandatory) */
1384 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1385 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
1386 const char *org; /**< party/company responsible for the module */
1387 const char *contact; /**< contact information for the module */
1388 const char *dsc; /**< description of the module */
1389 const char *ref; /**< cross-reference for the module */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001390};
1391
1392/**
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001393 * @brief Get the parsed module or submodule name.
1394 *
1395 * @param[in] PMOD Parsed module or submodule.
1396 * @return Module or submodule name.
1397 */
1398#define LYSP_MODULE_NAME(PMOD) (PMOD->is_submod ? ((struct lysp_submodule *)PMOD)->name : ((struct lysp_module *)PMOD)->mod->name)
1399
1400/**
Radek Krejci8df109d2021-04-23 12:19:08 +02001401 * @brief Compiled prefix data pair mapping of prefixes to modules. In case the format is ::LY_VALUE_SCHEMA_RESOLVED,
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001402 * the expected prefix data is a sized array of these structures.
1403 */
1404struct lysc_prefix {
1405 char *prefix; /**< used prefix */
1406 const struct lys_module *mod; /**< mapping to a module */
1407};
1408
1409/**
Radek Krejci0e59c312019-08-15 15:34:15 +02001410 * @brief Compiled YANG extension-stmt
Radek Krejci9f87b0c2021-03-05 14:45:26 +01001411 *
1412 * Note that the compiled extension definition is created only in case the extension is instantiated. It is not available
1413 * from the compiled schema, but from the parsed extension definition which is being searched when an extension instance
1414 * is being compiled.
Radek Krejci0e59c312019-08-15 15:34:15 +02001415 */
1416struct lysc_ext {
1417 const char *name; /**< extension name */
Radek Krejci9f87b0c2021-03-05 14:45:26 +01001418 const char *argname; /**< argument name, NULL if not specified */
Radek Krejci0e59c312019-08-15 15:34:15 +02001419 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcicc9e30f2021-03-29 12:45:08 +02001420 struct lyplg_ext *plugin; /**< Plugin implementing the specific extension */
Radek Krejci0935f412019-08-20 16:15:18 +02001421 struct lys_module *module; /**< module structure */
Michal Vasko6f4cbb62020-02-28 11:15:47 +01001422 uint32_t refcount; /**< reference counter since extension definition is shared among all its instances */
Radek Krejci0e59c312019-08-15 15:34:15 +02001423 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
1424};
1425
1426/**
Radek Krejcib1c11532021-03-29 14:14:19 +02001427 * @brief Description of the extension instance substatements.
1428 *
1429 * Provided by extensions plugins to libyang to be able to correctly compile the content of extension instances.
1430 * Note that order of the defined records matters - just follow the values of ::ly_stmt and order the records from lower to higher values.
1431 */
1432struct lysc_ext_substmt {
1433 enum ly_stmt stmt; /**< allowed substatement */
1434 enum ly_stmt_cardinality cardinality; /**< cardinality of the substatement */
1435 void *storage; /**< pointer to the storage of the compiled statement according to the specific
1436 lysc_ext_substmt::stmt and lysc_ext_substmt::cardinality */
1437};
1438
1439/**
Radek Krejcice8c1592018-10-29 15:35:51 +01001440 * @brief YANG extension instance
1441 */
1442struct lysc_ext_instance {
Radek Krejciad5963b2019-09-06 16:03:05 +02001443 struct lysc_ext *def; /**< pointer to the extension definition */
Radek Krejcice8c1592018-10-29 15:35:51 +01001444 const char *argument; /**< optional value of the extension's argument */
Radek Krejciab430862021-03-02 20:13:40 +01001445 struct lys_module *module; /**< module where the extension instantiated is defined */
Radek Krejci2a408df2018-10-29 16:32:26 +01001446 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f9a3672021-03-05 21:35:22 +01001447 struct lysc_ext_substmt *substmts; /**< list of allowed substatements with the storage to access the present
1448 substatements ([sized array](@ref sizedarrays)) */
Radek Krejci0e59c312019-08-15 15:34:15 +02001449 void *data; /**< private plugins's data, not used by libyang */
Radek Krejciab430862021-03-02 20:13:40 +01001450
1451 void *parent; /**< pointer to the parent element holding the extension instance(s), use
1452 ::lysc_ext_instance#parent_stmt to access the schema element */
1453 enum ly_stmt parent_stmt; /**< value identifying placement of the extension instance in specific statement */
1454 LY_ARRAY_COUNT_TYPE parent_stmt_index; /**< in case the instance is in a substatement, this identifies
1455 the index of that substatement in its [sized array](@ref sizedarrays) (if any) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001456};
1457
1458/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001459 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001460 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001461struct lysc_when {
1462 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko175012e2019-11-06 15:49:14 +01001463 struct lysc_node *context; /**< context node for evaluating the expression, NULL if the context is root node */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001464 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001465 const char *dsc; /**< description */
1466 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001467 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001468 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Michal Vaskoecd62de2019-11-13 12:35:11 +01001469 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS is allowed */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001470};
1471
1472/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001473 * @brief YANG identity-stmt
1474 */
1475struct lysc_ident {
Michal Vaskoe313c382022-03-14 13:04:47 +01001476 const char *name; /**< identity name (mandatory, no prefix) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001477 const char *dsc; /**< description */
1478 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001479 struct lys_module *module; /**< module structure */
aPiecek6b3d5422021-07-30 15:55:43 +02001480 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays))
1481 It also contains references to identities located in unimplemented modules. */
Radek Krejci2a408df2018-10-29 16:32:26 +01001482 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1483 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1484};
1485
1486/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001487 * @defgroup ifftokens if-feature expression tokens
Radek Krejci8678fa42020-08-18 16:07:28 +02001488 * Tokens of if-feature expression used in ::lysc_iffeature.expr.
Radek Krejci151a5b72018-10-19 14:21:44 +02001489 *
1490 * @{
1491 */
1492#define LYS_IFF_NOT 0x00 /**< operand "not" */
1493#define LYS_IFF_AND 0x01 /**< operand "and" */
1494#define LYS_IFF_OR 0x02 /**< operand "or" */
1495#define LYS_IFF_F 0x03 /**< feature */
Radek Krejci2ff0d572020-05-21 15:27:28 +02001496/** @} ifftokens */
Radek Krejci151a5b72018-10-19 14:21:44 +02001497
1498/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001499 * @brief Compiled YANG revision statement
1500 */
1501struct lysc_revision {
1502 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1503 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1504};
1505
Radek Krejci2167ee12018-11-02 16:09:07 +01001506struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001507 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001508 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001509 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1510 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001511 };
Radek Krejci693262f2019-04-29 15:23:20 +02001512 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001513 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1514 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001515 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001516 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001517 const char *dsc; /**< description */
1518 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001519 const char *emsg; /**< error-message */
1520 const char *eapptag; /**< error-app-tag value */
1521 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1522};
1523
1524struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001525 const char *expr; /**< original, not compiled, regular expression */
1526 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001527 const char *dsc; /**< description */
1528 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001529 const char *emsg; /**< error-message */
1530 const char *eapptag; /**< error-app-tag value */
1531 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0f969882020-08-21 16:56:47 +02001532 uint32_t inverted : 1; /**< invert-match flag */
1533 uint32_t refcount : 31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001534};
1535
1536struct lysc_must {
Radek Krejci2167ee12018-11-02 16:09:07 +01001537 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001538 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001539 const char *dsc; /**< description */
1540 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001541 const char *emsg; /**< error-message */
1542 const char *eapptag; /**< error-app-tag value */
1543 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1544};
1545
1546struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001547 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001548 struct lyplg_type *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 +01001549 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001550 uint32_t refcount; /**< reference counter for type sharing, it may be accessed concurrently when
Michal Vaskobabf0bd2021-08-31 14:55:39 +02001551 creating/freeing data node values that reference it (instance-identifier) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001552};
1553
1554struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001555 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001556 struct lyplg_type *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 +01001557 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001558 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci2167ee12018-11-02 16:09:07 +01001559 struct lysc_range *range; /**< Optional range limitation */
1560};
1561
1562struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001563 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001564 struct lyplg_type *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 +01001565 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001566 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001567 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001568 struct lysc_range *range; /**< Optional range limitation */
1569};
1570
1571struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001572 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001573 struct lyplg_type *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 +01001574 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001575 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci2167ee12018-11-02 16:09:07 +01001576 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001577 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001578};
1579
Radek Krejci693262f2019-04-29 15:23:20 +02001580struct lysc_type_bitenum_item {
1581 const char *name; /**< enumeration identifier */
1582 const char *dsc; /**< description */
1583 const char *ref; /**< reference */
1584 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko26bbb272022-08-02 14:54:33 +02001585
Radek Krejci693262f2019-04-29 15:23:20 +02001586 union {
1587 int32_t value; /**< integer value associated with the enumeration */
1588 uint32_t position; /**< non-negative integer value associated with the bit */
1589 };
Michal Vaskof4fa90d2021-11-11 15:05:19 +01001590 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_IS_ENUM values
1591 are allowed */
Radek Krejci693262f2019-04-29 15:23:20 +02001592};
1593
Radek Krejci2167ee12018-11-02 16:09:07 +01001594struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001595 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001596 struct lyplg_type *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 +01001597 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001598 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001599 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1600};
1601
1602struct lysc_type_bits {
1603 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001604 struct lyplg_type *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 +02001605 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001606 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001607 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1608 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001609};
1610
1611struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001612 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001613 struct lyplg_type *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 +01001614 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001615 uint32_t refcount; /**< reference counter for type sharing */
Michal Vasko004d3152020-06-11 19:59:22 +02001616 struct lyxp_expr *path; /**< parsed target path, compiled path cannot be stored because of type sharing */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001617 struct lysc_prefix *prefixes; /**< resolved prefixes used in the path */
Michal Vaskoed725d72021-06-23 12:03:45 +02001618 const struct lys_module *cur_mod;/**< unused, not needed */
Radek Krejci412ddfa2018-11-23 11:44:11 +01001619 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001620 uint8_t require_instance; /**< require-instance flag */
1621};
1622
1623struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001624 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001625 struct lyplg_type *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 +01001626 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001627 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001628 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001629 mandatory (at least 1 item) */
1630};
1631
1632struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001633 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001634 struct lyplg_type *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 +01001635 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001636 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci2167ee12018-11-02 16:09:07 +01001637 uint8_t require_instance; /**< require-instance flag */
1638};
1639
Radek Krejci2167ee12018-11-02 16:09:07 +01001640struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001641 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001642 struct lyplg_type *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 +01001643 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001644 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci2167ee12018-11-02 16:09:07 +01001645 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1646};
1647
1648struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001649 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001650 struct lyplg_type *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 +01001651 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001652 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci2167ee12018-11-02 16:09:07 +01001653 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001654};
1655
Michal Vasko60ea6352020-06-29 13:39:39 +02001656/**
1657 * @brief Maximum number of hashes stored in a schema node.
1658 */
1659#define LYS_NODE_HASH_COUNT 4
1660
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001661/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001662 * @brief Compiled YANG data node
1663 */
1664struct lysc_node {
Radek Krejcide7a9c42021-03-10 13:13:06 +01001665 uint16_t nodetype; /**< [type of the node](@ref schemanodetypes) (mandatory) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001666 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001667 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001668 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001669 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1670 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1671 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1672 never NULL. If there is no sibling node, pointer points to the node
1673 itself. In case of the first node, this pointer points to the last
1674 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001675 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001676 const char *dsc; /**< description */
1677 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001678 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001679 void *priv; /**< private arbitrary user data, not used by libyang unless ::LY_CTX_SET_PRIV_PARSED is set */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001680};
1681
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001682struct lysc_node_action_inout {
1683 union {
1684 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001685
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001686 struct {
1687 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
1688 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1689 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1690 struct lys_module *module; /**< module structure */
Radek Krejci5960c312021-01-27 20:24:22 +01001691 struct lysc_node *parent;/**< parent node (NULL in case of top level node) */
Michal Vasko544e58a2021-01-28 14:33:41 +01001692 struct lysc_node *next; /**< next sibling node (output node for input, NULL for output) */
1693 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 +01001694 const char *name; /**< "input" or "output" */
1695 const char *dsc; /**< ALWAYS NULL, compatibility member with ::lysc_node */
1696 const char *ref; /**< ALWAYS NULL, compatibility member with ::lysc_node */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001697 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001698 void *priv; /** private arbitrary user data, not used by libyang unless ::LY_CTX_SET_PRIV_PARSED is set */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001699 };
1700 };
1701
Radek Krejci9a3823e2021-01-27 20:26:46 +01001702 struct lysc_node *child; /**< first child node (linked list) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001703 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1704};
1705
1706struct lysc_node_action {
1707 union {
1708 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001709
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001710 struct {
1711 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
1712 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1713 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1714 struct lys_module *module; /**< module structure */
1715 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1716 struct lysc_node_action *next; /**< next sibling node (NULL if there is no one) */
1717 struct lysc_node_action *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1718 never NULL. If there is no sibling node, pointer points to the node
1719 itself. In case of the first node, this pointer points to the last
1720 node in the list. */
1721 const char *name; /**< action/RPC name (mandatory) */
1722 const char *dsc; /**< description */
1723 const char *ref; /**< reference */
1724 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001725 void *priv; /** private arbitrary user data, not used by libyang unless ::LY_CTX_SET_PRIV_PARSED is set */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001726 };
1727 };
1728
Radek Krejci9a3823e2021-01-27 20:26:46 +01001729 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)),
1730 the action/RPC nodes do not contain the when statement on their own, but they can
1731 inherit it from the parent's uses. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001732 struct lysc_node_action_inout input; /**< RPC's/action's input */
1733 struct lysc_node_action_inout output; /**< RPC's/action's output */
1734
1735};
1736
1737struct lysc_node_notif {
1738 union {
1739 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001740
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001741 struct {
1742 uint16_t nodetype; /**< LYS_NOTIF */
1743 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1744 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1745 struct lys_module *module; /**< module structure */
1746 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1747 struct lysc_node_notif *next; /**< next sibling node (NULL if there is no one) */
1748 struct lysc_node_notif *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1749 never NULL. If there is no sibling node, pointer points to the node
1750 itself. In case of the first node, this pointer points to the last
1751 node in the list. */
1752 const char *name; /**< Notification name (mandatory) */
1753 const char *dsc; /**< description */
1754 const char *ref; /**< reference */
1755 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001756 void *priv; /** private arbitrary user data, not used by libyang unless ::LY_CTX_SET_PRIV_PARSED is set */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001757 };
1758 };
1759
Radek Krejci9a3823e2021-01-27 20:26:46 +01001760 struct lysc_node *child; /**< first child node (linked list) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001761 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001762 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)),
1763 the notification nodes do not contain the when statement on their own, but they can
1764 inherit it from the parent's uses. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001765};
1766
1767struct lysc_node_container {
1768 union {
1769 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001770
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001771 struct {
1772 uint16_t nodetype; /**< LYS_CONTAINER */
1773 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1774 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1775 struct lys_module *module; /**< module structure */
1776 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1777 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1778 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1779 never NULL. If there is no sibling node, pointer points to the node
1780 itself. In case of the first node, this pointer points to the last
1781 node in the list. */
1782 const char *name; /**< node name (mandatory) */
1783 const char *dsc; /**< description */
1784 const char *ref; /**< reference */
1785 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001786 void *priv; /**< private arbitrary user data, not used by libyang unless ::LY_CTX_SET_PRIV_PARSED is set */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001787 };
1788 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001789
1790 struct lysc_node *child; /**< first child node (linked list) */
1791 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001792 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001793 struct lysc_node_action *actions;/**< first of actions nodes (linked list) */
1794 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001795};
1796
Radek Krejcia3045382018-11-22 14:30:31 +01001797struct lysc_node_case {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001798 union {
1799 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001800
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001801 struct {
1802 uint16_t nodetype; /**< LYS_CASE */
1803 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1804 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
1805 struct lys_module *module; /**< module structure */
1806 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1807 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1808 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejci056d0a82018-12-06 16:57:25 +01001809 never NULL. If there is no sibling node, pointer points to the node
1810 itself. In case of the first node, this pointer points to the last
1811 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001812 const char *name; /**< name of the case, including the implicit case */
1813 const char *dsc; /**< description */
1814 const char *ref; /**< reference */
1815 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001816 void *priv; /**< private arbitrary user data, not used by libyang unless ::LY_CTX_SET_PRIV_PARSED is set */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001817 };
1818 };
Radek Krejci056d0a82018-12-06 16:57:25 +01001819
Radek Krejcia3045382018-11-22 14:30:31 +01001820 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 +01001821 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001822 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcia3045382018-11-22 14:30:31 +01001823};
1824
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001825struct lysc_node_choice {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001826 union {
1827 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001828
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001829 struct {
1830 uint16_t nodetype; /**< LYS_CHOICE */
1831 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1832 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
1833 struct lys_module *module; /**< module structure */
1834 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1835 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1836 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001837 never NULL. If there is no sibling node, pointer points to the node
1838 itself. In case of the first node, this pointer points to the last
1839 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001840 const char *name; /**< node name (mandatory) */
1841 const char *dsc; /**< description */
1842 const char *ref; /**< reference */
1843 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001844 void *priv; /**< private arbitrary user data, not used by libyang unless ::LY_CTX_SET_PRIV_PARSED is set */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001845 };
1846 };
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001847
Radek Krejcia9026eb2018-12-12 16:04:47 +01001848 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1849 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1850 case is simple. */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001851 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001852 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001853};
1854
1855struct lysc_node_leaf {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001856 union {
1857 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001858
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001859 struct {
1860 uint16_t nodetype; /**< LYS_LEAF */
1861 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1862 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1863 struct lys_module *module; /**< module structure */
1864 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1865 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1866 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001867 never NULL. If there is no sibling node, pointer points to the node
1868 itself. In case of the first node, this pointer points to the last
1869 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001870 const char *name; /**< node name (mandatory) */
1871 const char *dsc; /**< description */
1872 const char *ref; /**< reference */
1873 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001874 void *priv; /**< private arbitrary user data, not used by libyang unless ::LY_CTX_SET_PRIV_PARSED is set */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001875 };
1876 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001877
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 Krejci4f28eda2018-11-12 11:46:16 +01001880 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001881
Radek Krejci4f28eda2018-11-12 11:46:16 +01001882 const char *units; /**< units of the leaf's type */
Michal Vasko33876022021-04-27 16:42:24 +02001883 struct lyd_value *dflt; /**< default value, use ::lyd_value_get_canonical() to get the canonical string */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001884};
1885
1886struct lysc_node_leaflist {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001887 union {
1888 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001889
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001890 struct {
1891 uint16_t nodetype; /**< LYS_LEAFLIST */
1892 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1893 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1894 struct lys_module *module; /**< module structure */
1895 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1896 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1897 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001898 never NULL. If there is no sibling node, pointer points to the node
1899 itself. In case of the first node, this pointer points to the last
1900 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001901 const char *name; /**< node name (mandatory) */
1902 const char *dsc; /**< description */
1903 const char *ref; /**< reference */
1904 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001905 void *priv; /**< private arbitrary user data, not used by libyang unless ::LY_CTX_SET_PRIV_PARSED is set */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001906 };
1907 };
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001908
1909 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001910 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001911 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1912
Radek Krejci0e5d8382018-11-28 16:37:53 +01001913 const char *units; /**< units of the leaf's type */
Michal Vasko33876022021-04-27 16:42:24 +02001914 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values, use
1915 ::lyd_value_get_canonical() to get the canonical strings */
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001916
Radek Krejci0e5d8382018-11-28 16:37:53 +01001917 uint32_t min; /**< min-elements constraint */
1918 uint32_t max; /**< max-elements constraint */
1919
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001920};
1921
1922struct lysc_node_list {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001923 union {
1924 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001925
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001926 struct {
1927 uint16_t nodetype; /**< LYS_LIST */
1928 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1929 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1930 struct lys_module *module; /**< module structure */
1931 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1932 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1933 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001934 never NULL. If there is no sibling node, pointer points to the node
1935 itself. In case of the first node, this pointer points to the last
1936 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001937 const char *name; /**< node name (mandatory) */
1938 const char *dsc; /**< description */
1939 const char *ref; /**< reference */
1940 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001941 void *priv; /**< private arbitrary user data, not used by libyang unless ::LY_CTX_SET_PRIV_PARSED is set */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001942 };
1943 };
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001944
1945 struct lysc_node *child; /**< first child node (linked list) */
1946 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001947 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001948 struct lysc_node_action *actions;/**< first of actions nodes (linked list) */
1949 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001950
Radek Krejci2a9fc652021-01-22 17:44:34 +01001951 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 +01001952 uint32_t min; /**< min-elements constraint */
1953 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001954};
1955
1956struct lysc_node_anydata {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001957 union {
1958 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001959
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001960 struct {
1961 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1962 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1963 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1964 struct lys_module *module; /**< module structure */
1965 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1966 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1967 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001968 never NULL. If there is no sibling node, pointer points to the node
1969 itself. In case of the first node, this pointer points to the last
1970 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001971 const char *name; /**< node name (mandatory) */
1972 const char *dsc; /**< description */
1973 const char *ref; /**< reference */
1974 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001975 void *priv; /**< private arbitrary user data, not used by libyang unless ::LY_CTX_SET_PRIV_PARSED is set */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001976 };
1977 };
Radek Krejci9800fb82018-12-13 14:26:23 +01001978
1979 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001980 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001981};
1982
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001983/**
1984 * @brief Compiled YANG schema tree structure representing YANG module.
1985 *
1986 * Semantically validated YANG schema tree for data tree parsing.
1987 * Contains only the necessary information for the data validation.
1988 */
1989struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001990 struct lys_module *mod; /**< covering module structure */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001991
Radek Krejci2a408df2018-10-29 16:32:26 +01001992 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001993 struct lysc_node_action *rpcs; /**< first of actions nodes (linked list) */
1994 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001995 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001996};
1997
1998/**
Radek Krejci490a5462020-11-05 08:44:42 +01001999 * @brief Examine whether a node is user-ordered list or leaf-list.
2000 *
2001 * @param[in] lysc_node Schema node to examine.
2002 * @return Boolean value whether the @p node is user-ordered or not.
2003 */
2004#define lysc_is_userordered(lysc_node) \
2005 ((!lysc_node || !(lysc_node->nodetype & (LYS_LEAFLIST | LYS_LIST)) || !(lysc_node->flags & LYS_ORDBY_USER)) ? 0 : 1)
2006
2007/**
2008 * @brief Examine whether a node is a list's key.
2009 *
2010 * @param[in] lysc_node Schema node to examine.
2011 * @return Boolean value whether the @p node is a key or not.
2012 */
2013#define lysc_is_key(lysc_node) \
Michal Vaskobce7ee32021-02-04 11:05:25 +01002014 ((!lysc_node || (lysc_node->nodetype != LYS_LEAF) || !(lysc_node->flags & LYS_KEY)) ? 0 : 1)
Radek Krejci490a5462020-11-05 08:44:42 +01002015
2016/**
Michal Vasko5c123b02020-12-04 14:34:04 +01002017 * @brief Examine whether a node is a non-presence container.
2018 *
2019 * @param[in] lysc_node Schema node to examine.
2020 * @return Boolean value whether the @p node is a NP container or not.
2021 */
2022#define lysc_is_np_cont(lysc_node) \
Michal Vaskobce7ee32021-02-04 11:05:25 +01002023 ((!lysc_node || (lysc_node->nodetype != LYS_CONTAINER) || (lysc_node->flags & LYS_PRESENCE)) ? 0 : 1)
2024
2025/**
Michal Vaskoe78faec2021-04-08 17:24:43 +02002026 * @brief Examine whether a node is a key-less list or a non-configuration leaf-list.
Michal Vaskobce7ee32021-02-04 11:05:25 +01002027 *
2028 * @param[in] lysc_node Schema node to examine.
2029 * @return Boolean value whether the @p node is a list with duplicate instances allowed.
2030 */
2031#define lysc_is_dup_inst_list(lysc_node) \
2032 ((lysc_node && (((lysc_node->nodetype == LYS_LIST) && (lysc_node->flags & LYS_KEYLESS)) || \
Michal Vaskoe78faec2021-04-08 17:24:43 +02002033 ((lysc_node->nodetype == LYS_LEAFLIST) && !(lysc_node->flags & LYS_CONFIG_W)))) ? 1 : 0)
Michal Vasko5c123b02020-12-04 14:34:04 +01002034
2035/**
Michal Vaskof8ded142022-02-17 10:48:01 +01002036 * @brief Get nearest @p schema parent (including the node itself) that can be instantiated in data.
2037 *
2038 * @param[in] schema Schema node to get the nearest data node for.
2039 * @return Schema data node, NULL if top-level (in data).
2040 */
2041LIBYANG_API_DECL const struct lysc_node *lysc_data_node(const struct lysc_node *schema);
2042
2043/**
2044 * @brief Same as ::lysc_data_node() but never returns the node itself.
2045 */
2046#define lysc_data_parent(SCHEMA) lysc_data_node((SCHEMA) ? (SCHEMA)->parent : NULL)
2047
2048/**
Michal Vaskod5cfa6e2020-11-23 16:56:08 +01002049 * @brief Check whether the schema node data instance existence depends on any when conditions.
2050 * This node and any direct parent choice and case schema nodes are also examined for when conditions.
2051 *
2052 * Be careful, this function is not recursive and checks only conditions that apply to this node directly.
2053 * Meaning if there are any conditions associated with any data parent instance of @p node, they are not returned.
2054 *
2055 * @param[in] node Schema node to examine.
2056 * @return When condition associated with the node data instance, NULL if there is none.
2057 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002058LIBYANG_API_DECL const struct lysc_when *lysc_has_when(const struct lysc_node *node);
Michal Vaskod5cfa6e2020-11-23 16:56:08 +01002059
2060/**
Michal Vaskoef53c812021-10-13 10:21:03 +02002061 * @brief Get the owner module of the schema node. It is the module of the top-level node. Generally,
2062 * in case of augments it is the target module, recursively, otherwise it is the module where the node is defined.
2063 *
2064 * @param[in] node Schema node to examine.
2065 * @return Module owner of the node.
2066 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002067LIBYANG_API_DECL const struct lys_module *lysc_owner_module(const struct lysc_node *node);
Michal Vaskoef53c812021-10-13 10:21:03 +02002068
2069/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01002070 * @brief Get the groupings linked list of the given (parsed) schema node.
Radek Krejci53ea6152018-12-13 15:21:15 +01002071 * Decides the node's type and in case it has a groupings array, returns it.
2072 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01002073 * @return The node's groupings linked list if any, NULL otherwise.
Radek Krejci53ea6152018-12-13 15:21:15 +01002074 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002075LIBYANG_API_DECL const struct lysp_node_grp *lysp_node_groupings(const struct lysp_node *node);
Radek Krejci53ea6152018-12-13 15:21:15 +01002076
2077/**
Radek Krejci056d0a82018-12-06 16:57:25 +01002078 * @brief Get the typedefs sized array of the given (parsed) schema node.
2079 * Decides the node's type and in case it has a typedefs array, returns it.
2080 * @param[in] node Node to examine.
2081 * @return The node's typedefs sized array if any, NULL otherwise.
2082 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002083LIBYANG_API_DECL const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002084
2085/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01002086 * @brief Get the actions/RPCs linked list of the given (parsed) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01002087 * Decides the node's type and in case it has a actions/RPCs array, returns it.
2088 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01002089 * @return The node's actions/RPCs linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01002090 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002091LIBYANG_API_DECL const struct lysp_node_action *lysp_node_actions(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002092
2093/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01002094 * @brief Get the Notifications linked list of the given (parsed) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01002095 * Decides the node's type and in case it has a Notifications array, returns it.
2096 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01002097 * @return The node's Notifications linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01002098 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002099LIBYANG_API_DECL const struct lysp_node_notif *lysp_node_notifs(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002100
2101/**
2102 * @brief Get the children linked list of the given (parsed) schema node.
2103 * Decides the node's type and in case it has a children list, returns it.
2104 * @param[in] node Node to examine.
2105 * @return The node's children linked list if any, NULL otherwise.
2106 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002107LIBYANG_API_DECL const struct lysp_node *lysp_node_child(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002108
2109/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01002110 * @brief Get the actions/RPCs linked list of the given (compiled) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01002111 * Decides the node's type and in case it has a actions/RPCs array, returns it.
2112 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01002113 * @return The node's actions/RPCs linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01002114 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002115LIBYANG_API_DECL const struct lysc_node_action *lysc_node_actions(const struct lysc_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002116
2117/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01002118 * @brief Get the Notifications linked list of the given (compiled) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01002119 * Decides the node's type and in case it has a Notifications array, returns it.
2120 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01002121 * @return The node's Notifications linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01002122 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002123LIBYANG_API_DECL const struct lysc_node_notif *lysc_node_notifs(const struct lysc_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002124
2125/**
2126 * @brief Get the children linked list of the given (compiled) schema node.
Michal Vasko2a668712020-10-21 11:48:09 +02002127 *
Michal Vasko544e58a2021-01-28 14:33:41 +01002128 * Note that ::LYS_CHOICE has only ::LYS_CASE children.
2129 * Also, ::LYS_RPC and ::LYS_ACTION have the first child ::LYS_INPUT, its sibling is ::LYS_OUTPUT.
2130 *
Michal Vasko2a668712020-10-21 11:48:09 +02002131 * @param[in] node Node to examine.
Michal Vasko2a668712020-10-21 11:48:09 +02002132 * @return Children linked list if any,
2133 * @return NULL otherwise.
2134 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002135LIBYANG_API_DECL const struct lysc_node *lysc_node_child(const struct lysc_node *node);
Michal Vasko2a668712020-10-21 11:48:09 +02002136
2137/**
Radek Krejci9a3823e2021-01-27 20:26:46 +01002138 * @brief Get the must statements list if present in the @p node
2139 *
2140 * @param[in] node Node to examine.
2141 * @return Pointer to the list of must restrictions ([sized array](@ref sizedarrays))
2142 * @return NULL if there is no must statement in the node, no matter if it is not even allowed or just present
2143 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002144LIBYANG_API_DECL struct lysc_must *lysc_node_musts(const struct lysc_node *node);
Radek Krejci9a3823e2021-01-27 20:26:46 +01002145
2146/**
2147 * @brief Get the when statements list if present in the @p node
2148 *
2149 * @param[in] node Node to examine.
2150 * @return Pointer to the list of pointers to when statements ([sized array](@ref sizedarrays))
2151 * @return NULL if there is no when statement in the node, no matter if it is not even allowed or just present
2152 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002153LIBYANG_API_DECL struct lysc_when **lysc_node_when(const struct lysc_node *node);
Radek Krejci9a3823e2021-01-27 20:26:46 +01002154
2155/**
Michal Vaskof1ab44f2020-10-22 08:58:32 +02002156 * @brief Callback to be called for every schema node in a DFS traversal.
2157 *
2158 * @param[in] node Current node.
2159 * @param[in] data Arbitrary user data.
2160 * @param[out] dfs_continue Set to true if the current subtree should be skipped and continue with siblings instead.
2161 * @return LY_SUCCESS on success,
2162 * @return LY_ERR value to terminate DFS and return this value.
2163 */
Michal Vasko8f07dfe2021-03-02 16:10:24 +01002164typedef LY_ERR (*lysc_dfs_clb)(struct lysc_node *node, void *data, ly_bool *dfs_continue);
Michal Vaskof1ab44f2020-10-22 08:58:32 +02002165
2166/**
2167 * @brief DFS traversal of all the schema nodes in a (sub)tree including any actions and nested notifications.
2168 *
2169 * Node with children, actions, and notifications is traversed in this order:
2170 * 1) each child subtree;
2171 * 2) each action subtree;
2172 * 3) each notification subtree.
2173 *
2174 * For algorithm illustration or traversal with actions and notifications skipped, see ::LYSC_TREE_DFS_BEGIN.
2175 *
2176 * @param[in] root Schema root to fully traverse.
2177 * @param[in] dfs_clb Callback to call for each node.
2178 * @param[in] data Arbitrary user data passed to @p dfs_clb.
2179 * @return LY_SUCCESS on success,
2180 * @return LY_ERR value returned by @p dfs_clb.
2181 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002182LIBYANG_API_DECL LY_ERR lysc_tree_dfs_full(const struct lysc_node *root, lysc_dfs_clb dfs_clb, void *data);
Michal Vaskof1ab44f2020-10-22 08:58:32 +02002183
2184/**
2185 * @brief DFS traversal of all the schema nodes in a module including RPCs and notifications.
2186 *
2187 * For more details, see ::lysc_tree_dfs_full().
2188 *
2189 * @param[in] mod Module to fully traverse.
2190 * @param[in] dfs_clb Callback to call for each node.
2191 * @param[in] data Arbitrary user data passed to @p dfs_clb.
2192 * @return LY_SUCCESS on success,
2193 * @return LY_ERR value returned by @p dfs_clb.
2194 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002195LIBYANG_API_DECL LY_ERR lysc_module_dfs_full(const struct lys_module *mod, lysc_dfs_clb dfs_clb, void *data);
Michal Vaskof1ab44f2020-10-22 08:58:32 +02002196
2197/**
Radek Krejci151a5b72018-10-19 14:21:44 +02002198 * @brief Get how the if-feature statement currently evaluates.
2199 *
2200 * @param[in] iff Compiled if-feature statement to evaluate.
Michal Vasko28d78432020-05-26 13:10:53 +02002201 * @return LY_SUCCESS if the statement evaluates to true,
2202 * @return LY_ENOT if it evaluates to false,
2203 * @return LY_ERR on error.
Radek Krejci151a5b72018-10-19 14:21:44 +02002204 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002205LIBYANG_API_DECL LY_ERR lysc_iffeature_value(const struct lysc_iffeature *iff);
Radek Krejci151a5b72018-10-19 14:21:44 +02002206
2207/**
aPiecekf4a0a192021-08-03 15:14:17 +02002208 * @brief Get how the if-feature statement is evaluated for certain identity.
2209 *
2210 * The function can be called even if the identity does not contain
2211 * if-features, in which case ::LY_SUCCESS is returned.
2212 *
2213 * @param[in] ident Compiled identity statement to evaluate.
2214 * @return LY_SUCCESS if the statement evaluates to true,
2215 * @return LY_ENOT if it evaluates to false,
2216 * @return LY_ERR on error.
2217 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002218LIBYANG_API_DECL LY_ERR lys_identity_iffeature_value(const struct lysc_ident *ident);
aPiecekf4a0a192021-08-03 15:14:17 +02002219
2220/**
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002221 * @brief Get the next feature in the module or submodules.
Radek Krejci151a5b72018-10-19 14:21:44 +02002222 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002223 * @param[in] last Last returned feature.
Michal Vasko4ec4bc02021-10-12 10:17:28 +02002224 * @param[in] pmod Parsed module and submodules whose features to iterate over.
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002225 * @param[in,out] idx Submodule index, set to 0 on first call.
2226 * @return Next found feature, NULL if the last has already been returned.
Radek Krejci151a5b72018-10-19 14:21:44 +02002227 */
Michal Vaskoc1a0ff62022-02-28 14:27:16 +01002228LIBYANG_API_DECL struct lysp_feature *lysp_feature_next(const struct lysp_feature *last, const struct lysp_module *pmod,
2229 uint32_t *idx);
Radek Krejci151a5b72018-10-19 14:21:44 +02002230
Radek Krejcibed13942020-10-19 16:06:28 +02002231/**
Radek Krejcidab4f0b2021-03-29 14:07:18 +02002232 * @brief Get pointer to the storage of the specified substatement in the given extension instance.
2233 *
2234 * The function simplifies access into the ::lysc_ext_instance.substmts sized array.
2235 *
2236 * @param[in] ext Compiled extension instance to process.
2237 * @param[in] substmt Extension substatement to search for.
2238 * @param[out] instance_p Pointer where the storage of the @p substmt will be provided. The specific type returned depends
2239 * on the @p substmt and can be found in the documentation of each ::ly_stmt value. Also note that some of the substatements
2240 * (::lysc_node based or flags) can share the storage with other substatements. In case the pointer is NULL, still the return
2241 * code can be used to at least know if the substatement is allowed for the extension.
2242 * @param[out] cardinality_p Pointer to provide allowed cardinality of the substatements in the extension. Note that in some
2243 * cases, the type of the storage depends also on the cardinality of the substatement.
2244 * @return LY_SUCCESS if the @p substmt found.
2245 * @return LY_ENOT in case the @p ext is not able to store (does not allow) the specified @p substmt.
2246 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002247LIBYANG_API_DECL LY_ERR lysc_ext_substmt(const struct lysc_ext_instance *ext, enum ly_stmt substmt,
Radek Krejcidab4f0b2021-03-29 14:07:18 +02002248 void **instance_p, enum ly_stmt_cardinality *cardinality_p);
2249
2250/**
Radek Krejcibed13942020-10-19 16:06:28 +02002251 * @defgroup findxpathoptions Atomize XPath options
2252 * Options to modify behavior of ::lys_find_xpath() and ::lys_find_xpath_atoms() searching for schema nodes in schema tree.
2253 * @{
2254 */
Michal Vasko4ad69e72021-10-26 16:25:55 +02002255#define LYS_FIND_XP_SCHEMA 0x08 /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */
2256#define LYS_FIND_XP_OUTPUT 0x10 /**< Search RPC/action output nodes instead of input ones. */
Michal Vaskoa2fe0812022-05-26 09:24:32 +02002257#define LYS_FIND_NO_MATCH_ERROR 0x40 /**< Return error if a path segment matches no nodes, otherwise only warning
Michal Vasko4ad69e72021-10-26 16:25:55 +02002258 is printed. */
Radek Krejci576f8fa2020-10-26 21:23:58 +01002259/** @} findxpathoptions */
Michal Vasko072de482020-08-05 13:27:21 +02002260
Radek Krejci151a5b72018-10-19 14:21:44 +02002261/**
Michal Vasko40308e72020-10-20 16:38:40 +02002262 * @brief Get all the schema nodes that are required for @p xpath to be evaluated (atoms).
Michal Vasko519fd602020-05-26 12:17:39 +02002263 *
Michal Vasko26512682021-01-11 11:35:40 +01002264 * @param[in] ctx libyang context to use. May be NULL if @p ctx_node is set.
2265 * @param[in] ctx_node XPath schema context node. Use NULL for the root node.
Radek Krejci8df109d2021-04-23 12:19:08 +02002266 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_VALUE_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02002267 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko519fd602020-05-26 12:17:39 +02002268 * @param[out] set Set of found atoms (schema nodes).
2269 * @return LY_SUCCESS on success, @p set is returned.
Michal Vasko40308e72020-10-20 16:38:40 +02002270 * @return LY_ERR value on error.
Michal Vasko519fd602020-05-26 12:17:39 +02002271 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002272LIBYANG_API_DECL LY_ERR lys_find_xpath_atoms(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *xpath,
Michal Vasko26512682021-01-11 11:35:40 +01002273 uint32_t options, struct ly_set **set);
Michal Vasko519fd602020-05-26 12:17:39 +02002274
Michal Vasko072de482020-08-05 13:27:21 +02002275/**
Michal Vasko40308e72020-10-20 16:38:40 +02002276 * @brief Get all the schema nodes that are required for @p expr to be evaluated (atoms).
Michal Vasko072de482020-08-05 13:27:21 +02002277 *
Michal Vasko26512682021-01-11 11:35:40 +01002278 * @param[in] ctx_node XPath schema context node. Use NULL for the root node.
Michal Vasko40308e72020-10-20 16:38:40 +02002279 * @param[in] cur_mod Current module for the expression (where it was "instantiated").
2280 * @param[in] expr Parsed expression to use.
2281 * @param[in] prefixes Sized array of compiled prefixes.
2282 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
2283 * @param[out] set Set of found atoms (schema nodes).
2284 * @return LY_SUCCESS on success, @p set is returned.
2285 * @return LY_ERR value on error.
2286 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002287LIBYANG_API_DECL LY_ERR lys_find_expr_atoms(const struct lysc_node *ctx_node, const struct lys_module *cur_mod,
Michal Vasko40308e72020-10-20 16:38:40 +02002288 const struct lyxp_expr *expr, const struct lysc_prefix *prefixes, uint32_t options, struct ly_set **set);
2289
2290/**
2291 * @brief Evaluate an @p xpath expression on schema nodes.
2292 *
Michal Vasko26512682021-01-11 11:35:40 +01002293 * @param[in] ctx libyang context to use for absolute @p xpath. May be NULL if @p ctx_node is set.
2294 * @param[in] ctx_node XPath schema context node for relative @p xpath. Use NULL for the root node.
Radek Krejci8df109d2021-04-23 12:19:08 +02002295 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_VALUE_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02002296 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko072de482020-08-05 13:27:21 +02002297 * @param[out] set Set of found schema nodes.
2298 * @return LY_SUCCESS on success, @p set is returned.
2299 * @return LY_ERR value if an error occurred.
2300 */
Michal Vaskoc1a0ff62022-02-28 14:27:16 +01002301LIBYANG_API_DECL LY_ERR lys_find_xpath(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *xpath,
2302 uint32_t options, struct ly_set **set);
Michal Vasko519fd602020-05-26 12:17:39 +02002303
2304/**
Radek Krejcibc5644c2020-10-27 14:53:17 +01002305 * @brief Get all the schema nodes that are required for @p path to be evaluated (atoms).
2306 *
2307 * @param[in] path Compiled path to use.
2308 * @param[out] set Set of found atoms (schema nodes).
2309 * @return LY_SUCCESS on success, @p set is returned.
2310 * @return LY_ERR value on error.
2311 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002312LIBYANG_API_DECL LY_ERR lys_find_lypath_atoms(const struct ly_path *path, struct ly_set **set);
Radek Krejcibc5644c2020-10-27 14:53:17 +01002313
2314/**
2315 * @brief Get all the schema nodes that are required for @p path to be evaluated (atoms).
2316 *
Michal Vasko26512682021-01-11 11:35:40 +01002317 * @param[in] ctx libyang context to use for absolute @p path. May be NULL if @p ctx_node is set.
2318 * @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 +01002319 * @param[in] path JSON path to examine.
2320 * @param[in] output Search operation output instead of input.
2321 * @param[out] set Set of found atoms (schema nodes).
2322 * @return LY_ERR value on error.
2323 */
Michal Vaskoc1a0ff62022-02-28 14:27:16 +01002324LIBYANG_API_DECL LY_ERR lys_find_path_atoms(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *path,
2325 ly_bool output, struct ly_set **set);
Radek Krejcibc5644c2020-10-27 14:53:17 +01002326
2327/**
2328 * @brief Get a schema node based on the given data path (JSON format, see @ref howtoXPath).
2329 *
Michal Vasko26512682021-01-11 11:35:40 +01002330 * @param[in] ctx libyang context to use for absolute @p path. May be NULL if @p ctx_node is set.
2331 * @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 +01002332 * @param[in] path JSON path of the node to get.
2333 * @param[in] output Search operation output instead of input.
2334 * @return Found schema node or NULL.
2335 */
Michal Vaskoc1a0ff62022-02-28 14:27:16 +01002336LIBYANG_API_DECL const struct lysc_node *lys_find_path(const struct ly_ctx *ctx, const struct lysc_node *ctx_node,
2337 const char *path, ly_bool output);
Radek Krejcibc5644c2020-10-27 14:53:17 +01002338
2339/**
Michal Vasko03ff5a72019-09-11 13:49:33 +02002340 * @brief Types of the different schema paths.
2341 */
2342typedef enum {
Michal Vasko65de0402020-08-03 16:34:19 +02002343 LYSC_PATH_LOG, /**< Descriptive path format used in log messages */
Michal Vaskobde22b62022-03-22 15:32:56 +01002344 LYSC_PATH_DATA, /**< Similar to ::LYSC_PATH_LOG except that schema-only nodes (choice, case) are skipped */
2345 LYSC_PATH_DATA_PATTERN /**< Similar to ::LYSC_PATH_DATA but there are predicates for all list keys added with
2346 "%s" where their values should be so that they can be printed there */
Michal Vasko03ff5a72019-09-11 13:49:33 +02002347} LYSC_PATH_TYPE;
2348
2349/**
Radek Krejci327de162019-06-14 12:52:07 +02002350 * @brief Generate path of the given node in the requested format.
2351 *
2352 * @param[in] node Schema path of this node will be generated.
2353 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02002354 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
2355 * If NULL, memory for the complete path is allocated.
2356 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02002357 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02002358 * 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 +02002359 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002360LIBYANG_API_DECL char *lysc_path(const struct lysc_node *node, LYSC_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02002361
2362/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002363 * @brief Available YANG schema tree structures representing YANG module.
2364 */
2365struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002366 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
2367 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01002368 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002369 const char *ns; /**< namespace of the module (module - mandatory) */
2370 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
2371 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
2372 const char *org; /**< party/company responsible for the module */
2373 const char *contact; /**< contact information for the module */
2374 const char *dsc; /**< description of the module */
2375 const char *ref; /**< cross-reference for the module */
2376
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002377 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01002378 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
2379 Available only for implemented modules. */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002380
Radek Krejci80d281e2020-09-14 17:42:54 +02002381 struct lysc_ident *identities; /**< List of compiled identities of the module ([sized array](@ref sizedarrays))
aPiecek6b3d5422021-07-30 15:55:43 +02002382 also contains the disabled identities when their if-feature(s) are evaluated to \"false\",
2383 and also the list is filled even if the module is not implemented.
2384 The list is located here because it avoids problems when the module became implemented in
Radek Krejci80d281e2020-09-14 17:42:54 +02002385 future (no matter if implicitly via augment/deviate or explicitly via
2386 ::lys_set_implemented()). Note that if the module is not implemented (compiled), the
2387 identities cannot be instantiated in data (in identityrefs). */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002388
2389 struct lys_module **augmented_by;/**< List of modules that augment this module ([sized array](@ref sizedarrays)) */
2390 struct lys_module **deviated_by; /**< List of modules that deviate this module ([sized array](@ref sizedarrays)) */
2391
Michal Vasko89b5c072020-10-06 13:52:44 +02002392 ly_bool implemented; /**< flag if the module is implemented, not just imported */
Michal Vasko01db7de2021-04-16 12:23:30 +02002393 ly_bool to_compile; /**< flag marking a module that was changed but not (re)compiled, see
2394 ::LY_CTX_EXPLICIT_COMPILE. */
aPiecek8ca21bd2021-07-26 14:31:01 +02002395 uint8_t latest_revision; /**< Flag to mark the latest available revision, see [latest_revision options](@ref latestrevflags). */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002396};
2397
Radek Krejci151a5b72018-10-19 14:21:44 +02002398/**
aPiecek8ca21bd2021-07-26 14:31:01 +02002399 * @defgroup latestrevflags Options for ::lys_module.latest_revision.
2400 *
2401 * Various information bits of ::lys_module.latest_revision.
2402 *
2403 * @{
2404 */
aPiecek94d330b2021-08-04 11:57:31 +02002405#define LYS_MOD_LATEST_REV 0x01 /**< This is the latest revision of the module in the current context. */
2406#define LYS_MOD_LATEST_SEARCHDIRS 0x02 /**< This is the latest revision of the module found in searchdirs. */
Michal Vaskobdac23f2022-01-12 14:02:35 +01002407#define LYS_MOD_IMPORTED_REV 0x04 /**< This is the module revision used when importing the module without
2408 an explicit revision-date. It is used for all such imports regardless of
2409 any changes made in the context. */
2410#define LYS_MOD_LATEST_IMPCLB 0x08 /**< This is the latest revision of the module obtained from import callback. */
aPiecek8ca21bd2021-07-26 14:31:01 +02002411/** @} latestrevflags */
2412
2413/**
Michal Vasko82c31e62020-07-17 15:30:40 +02002414 * @brief Get the current real status of the specified feature in the module.
2415 *
2416 * If the feature is enabled, but some of its if-features are false, the feature is considered
2417 * disabled.
Radek Krejci151a5b72018-10-19 14:21:44 +02002418 *
2419 * @param[in] module Module where the feature is defined.
2420 * @param[in] feature Name of the feature to inspect.
Michal Vasko82c31e62020-07-17 15:30:40 +02002421 * @return LY_SUCCESS if the feature is enabled,
2422 * @return LY_ENOT if the feature is disabled,
2423 * @return LY_ENOTFOUND if the feature was not found.
Radek Krejci151a5b72018-10-19 14:21:44 +02002424 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002425LIBYANG_API_DECL LY_ERR lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02002426
2427/**
Michal Vasko3608d252022-02-28 14:28:12 +01002428 * @brief Get next schema (sibling) node element in the schema order that can be instantiated in a data tree.
2429 * Returned node may be from an augment.
Radek Krejcia3045382018-11-22 14:30:31 +01002430 *
Michal Vasko3608d252022-02-28 14:28:12 +01002431 * ::lys_getnext() is supposed to be called sequentially. In the first call, the @p last parameter is usually NULL
2432 * and function starts returning 1) the first @p parent child (if it is set) or 2) the first top level element of
2433 * @p module. Consequent calls should provide the previously returned node as @p last and the same @p parent and
2434 * @p module parameters.
Radek Krejcia3045382018-11-22 14:30:31 +01002435 *
2436 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
Michal Vasko3608d252022-02-28 14:28:12 +01002437 * data nodes in a data tree. By setting some @p options the behavior can be modified to the extent that
Radek Krejcia3045382018-11-22 14:30:31 +01002438 * all the schema nodes are iteratively returned.
2439 *
2440 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
Michal Vasko3608d252022-02-28 14:28:12 +01002441 * @param[in] parent Parent of the subtree to iterate over. If set, @p module is ignored.
2442 * @param[in] module Module of the top level elements to iterate over. If @p parent is NULL, it must be specified.
Radek Krejcia3045382018-11-22 14:30:31 +01002443 * @param[in] options [ORed options](@ref sgetnextflags).
Michal Vasko3608d252022-02-28 14:28:12 +01002444 * @return Next schema tree node, NULL in case there are no more.
Radek Krejcia3045382018-11-22 14:30:31 +01002445 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002446LIBYANG_API_DECL const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002447 const struct lysc_module *module, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002448
2449/**
Michal Vasko3608d252022-02-28 14:28:12 +01002450 * @brief Get next schema (sibling) node element in the schema order of an extension that can be instantiated in
2451 * a data tree.
Radek Krejci8678fa42020-08-18 16:07:28 +02002452 *
Michal Vasko3608d252022-02-28 14:28:12 +01002453 * It is just ::lys_getnext() for extensions.
Radek Krejci035dacf2021-02-12 18:25:53 +01002454 *
2455 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
Michal Vasko3608d252022-02-28 14:28:12 +01002456 * @param[in] parent Parent of the subtree to iterate over. If set, @p ext is ignored.
2457 * @param[in] ext Extension instance with schema nodes to iterate over. If @p parent is NULL, it must be specified.
Radek Krejci035dacf2021-02-12 18:25:53 +01002458 * @param[in] options [ORed options](@ref sgetnextflags).
Michal Vasko3608d252022-02-28 14:28:12 +01002459 * @return Next schema tree node, NULL in case there are no more.
Radek Krejci035dacf2021-02-12 18:25:53 +01002460 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002461LIBYANG_API_DECL const struct lysc_node *lys_getnext_ext(const struct lysc_node *last, const struct lysc_node *parent,
Radek Krejci035dacf2021-02-12 18:25:53 +01002462 const struct lysc_ext_instance *ext, uint32_t options);
2463
2464/**
2465 * @defgroup sgetnextflags Options for ::lys_getnext() and ::lys_getnext_ext().
2466 *
2467 * Various options setting behavior of ::lys_getnext() and ::lys_getnext_ext().
Radek Krejci8678fa42020-08-18 16:07:28 +02002468 *
Radek Krejcia3045382018-11-22 14:30:31 +01002469 * @{
2470 */
Radek Krejci8678fa42020-08-18 16:07:28 +02002471#define LYS_GETNEXT_WITHCHOICE 0x01 /**< ::lys_getnext() option to allow returning #LYS_CHOICE nodes instead of looking into them */
2472#define LYS_GETNEXT_NOCHOICE 0x02 /**< ::lys_getnext() option to ignore (kind of conditional) nodes within choice node */
2473#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 +01002474#define LYS_GETNEXT_INTONPCONT 0x08 /**< ::lys_getnext() option to look into non-presence container, instead of returning container itself */
2475#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 +01002476 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01002477/** @} sgetnextflags */
2478
2479/**
2480 * @brief Get child node according to the specified criteria.
2481 *
2482 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
2483 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
2484 * @param[in] name Name of the node to find.
2485 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
2486 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
2487 * Used as a bitmask, so multiple nodetypes can be specified.
2488 * @param[in] options [ORed options](@ref sgetnextflags).
2489 * @return Found node if any.
2490 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002491LIBYANG_API_DECL const struct lysc_node *lys_find_child(const struct lysc_node *parent, const struct lys_module *module,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002492 const char *name, size_t name_len, uint16_t nodetype, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002493
2494/**
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002495 * @brief Make the specific module implemented.
2496 *
Michal Vaskoe8988e92021-01-25 11:26:29 +01002497 * If the module is already implemented but with a different set of features, the whole context is recompiled.
2498 *
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002499 * @param[in] mod Module to make implemented. It is not an error
2500 * to provide already implemented module, it just does nothing.
Michal Vaskoe8988e92021-01-25 11:26:29 +01002501 * @param[in] features Optional array specifying the enabled features terminated with NULL overriding any previous
2502 * feature setting. The feature string '*' enables all the features and array of length 1 with only the terminating
2503 * NULL explicitly disables all the features. In case the parameter is NULL, the features are untouched - left disabled
2504 * 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 +01002505 * @return LY_SUCCESS on success.
2506 * @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 +01002507 * @return LY_ERR on other errors during module compilation.
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002508 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002509LIBYANG_API_DECL LY_ERR lys_set_implemented(struct lys_module *mod, const char **features);
Radek Krejcia3045382018-11-22 14:30:31 +01002510
Radek Krejci084289f2019-07-09 17:35:30 +02002511/**
Radek Krejci0935f412019-08-20 16:15:18 +02002512 * @brief Stringify schema nodetype.
Michal Vaskod43d71a2020-08-07 14:54:58 +02002513 *
Radek Krejci0935f412019-08-20 16:15:18 +02002514 * @param[in] nodetype Nodetype to stringify.
2515 * @return Constant string with the name of the node's type.
2516 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002517LIBYANG_API_DECL const char *lys_nodetype2str(uint16_t nodetype);
Radek Krejci0935f412019-08-20 16:15:18 +02002518
Michal Vaskod43d71a2020-08-07 14:54:58 +02002519/**
2520 * @brief Getter for original XPath expression from a parsed expression.
2521 *
2522 * @param[in] path Parsed expression.
2523 * @return Original string expression.
2524 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002525LIBYANG_API_DECL const char *lyxp_get_expr(const struct lyxp_expr *path);
Michal Vaskod43d71a2020-08-07 14:54:58 +02002526
Radek Krejci2ff0d572020-05-21 15:27:28 +02002527/** @} schematree */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002528
Radek Krejci70853c52018-10-15 14:46:16 +02002529#ifdef __cplusplus
2530}
2531#endif
2532
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002533#endif /* LY_TREE_SCHEMA_H_ */