blob: 9e8dc961b394ea50f0f479cdc05710dbeb808296 [file] [log] [blame]
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001/**
2 * @file tree_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief libyang representation of YANG schema trees.
5 *
6 * Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_TREE_SCHEMA_H_
16#define LY_TREE_SCHEMA_H_
17
Radek Krejci54579462019-04-30 12:47:06 +020018#define PCRE2_CODE_UNIT_WIDTH 8
19
20#include <pcre2.h>
Radek Krejci535ea9f2020-05-29 16:01:05 +020021
Radek Krejci5aeea3a2018-09-05 13:29:36 +020022#include <stdint.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020023#include <stdio.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020024
Radek Krejcie7b95092019-05-15 11:03:07 +020025#include "log.h"
26#include "tree.h"
Radek Krejcice8c1592018-10-29 15:35:51 +010027
Radek Krejci70853c52018-10-15 14:46:16 +020028#ifdef __cplusplus
29extern "C" {
30#endif
31
Radek Krejcica376bd2020-06-11 16:04:06 +020032struct ly_ctx;
Radek Krejci47fab892020-11-05 17:02:41 +010033struct ly_path;
Radek Krejcica376bd2020-06-11 16:04:06 +020034struct ly_set;
Radek Krejci47fab892020-11-05 17:02:41 +010035struct lys_module;
36struct lysc_node;
37struct lyxp_expr;
Radek Krejcica376bd2020-06-11 16:04:06 +020038
Radek Krejci5aeea3a2018-09-05 13:29:36 +020039/**
Radek Krejci8678fa42020-08-18 16:07:28 +020040 * @page howtoSchema YANG Modules
41 *
42 * To be able to work with YANG data instances, libyang has to represent YANG data models. All the processed modules are stored
43 * in libyang [context](@ref howtoContext) and loaded using [parser functions](@ref howtoSchemaParsers). It means, that there is
44 * no way to create/change YANG module programmatically. However, all the YANG model definitions are available and can be examined
45 * through the C structures. All the context's modules together form YANG Schema for the data being instantiated.
46 *
47 * Any YANG module is represented as ::lys_module. In fact, the module is represented in two different formats. As ::lys_module.parsed,
48 * there is a parsed schema reflecting the source YANG module. It is exactly what is read from the input. This format is good for
49 * converting from one format to another (YANG to YIN and vice versa), but it is not very useful for validating/manipulating YANG
50 * data. Therefore, there is ::lys_module.compiled storing the compiled YANG module. It is based on the parsed module, but all the
51 * references are resolved. It means that, for example, there are no `grouping`s or `typedef`s since they are supposed to be placed instead of
52 * `uses` or `type` references. This split also means, that the YANG module is fully validated after compilation of the parsed
53 * representation of the module. YANG submodules are available only in the parsed representation. When a submodule is compiled, it
54 * is fully integrated into its main module.
55 *
56 * The context can contain even modules without the compiled representation. Such modules are still useful as imports of other
57 * modules. The grouping or typedef definition can be even compiled into the importing modules. This is actually the main
58 * difference between the imported and implemented modules in the libyang context. The implemented modules are compiled while the
59 * imported modules are only parsed.
60 *
Radek Krejcib100b192020-10-26 08:37:45 +010061 * By default, the module is implemented (and compiled) in case it is explicitly loaded or referenced in another module as
62 * target of leafref, augment or deviation. This behavior can be changed via context options ::LY_CTX_ALL_IMPLEMENTED, when
63 * all the modules in the context are marked as implemented (note the problem with multiple revisions of a single module),
64 * or by ::LY_CTX_REF_IMPLEMENTED option, extending the set of references making the module implemented by when, must and
65 * default statements.
Radek Krejci8678fa42020-08-18 16:07:28 +020066 *
67 * All modules with deviation definition are always marked as implemented. The imported (not implemented) module can be set implemented by ::lys_set_implemented(). But
68 * the implemented module cannot be changed back to just imported module. Note also that only one revision of a specific module
69 * can be implemented in a single context. The imported modules are used only as a
70 * source of definitions for types and groupings for uses statements. The data in such modules are ignored - caller
71 * is not allowed to create the data (including instantiating identities) defined in the model via data parsers,
72 * the default nodes are not added into any data tree and mandatory nodes are not checked in the data trees.
73 *
Michal Vasko14ed9cd2021-01-28 14:16:25 +010074 * The compiled schema tree nodes are able to hold private objects (::lysc_node.priv as a pointer to a structure,
aPiecek9922ea92021-04-12 07:59:20 +020075 * function, variable, ...) used by a caller application unless ::LY_CTX_SET_PRIV_PARSED is set, in that case
76 * the ::lysc_node.priv pointers are used by libyang.
Radek Krejci8678fa42020-08-18 16:07:28 +020077 * Note that the object is not freed by libyang when the context is being destroyed. So the caller is responsible
78 * 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 +020079 * appropriate schema nodes where the object was previously set. Also ::lysc_tree_dfs_full() can be useful to manage
80 * the private data.
Radek Krejci8678fa42020-08-18 16:07:28 +020081 *
82 * Despite all the schema structures and their members are available as part of the libyang API and callers can use
83 * it to navigate through the schema tree structure or to obtain various information, we recommend to use the following
84 * macros for the specific actions.
85 * - ::LYSC_TREE_DFS_BEGIN and ::LYSC_TREE_DFS_END to traverse the schema tree (depth-first).
86 * - ::LY_LIST_FOR and ::LY_ARRAY_FOR as described on @ref howtoStructures page.
87 *
88 * Further information about modules handling can be found on the following pages:
89 * - @subpage howtoSchemaParsers
90 * - @subpage howtoSchemaFeatures
91 * - @subpage howtoPlugins
92 * - @subpage howtoSchemaPrinters
93 *
94 * \note There are many functions to access information from the schema trees. Details are available in
95 * the [Schema Tree module](@ref schematree).
96 *
97 * For information about difference between implemented and imported modules, see the
98 * [context description](@ref howtoContext).
99 *
100 * Functions List (not assigned to above subsections)
101 * --------------------------------------------------
102 * - ::lys_getnext()
103 * - ::lys_nodetype2str()
104 * - ::lys_set_implemented()
Radek Krejci8678fa42020-08-18 16:07:28 +0200105 *
Michal Vaskod5cfa6e2020-11-23 16:56:08 +0100106 * - ::lysc_has_when()
107 *
Michal Vasko544e58a2021-01-28 14:33:41 +0100108 * - ::lysc_node_child()
Radek Krejci8678fa42020-08-18 16:07:28 +0200109 * - ::lysc_node_actions()
110 * - ::lysc_node_notifs()
111 *
Michal Vasko544e58a2021-01-28 14:33:41 +0100112 * - ::lysp_node_child()
Radek Krejci8678fa42020-08-18 16:07:28 +0200113 * - ::lysp_node_actions()
114 * - ::lysp_node_notifs()
115 * - ::lysp_node_groupings()
116 * - ::lysp_node_typedefs()
117 */
118
119/**
120 * @page howtoSchemaFeatures YANG Features
121 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100122 * YANG feature statement is an important part of the language which can significantly affect the meaning of the schemas.
123 * Modifying features may have similar effects as loading/removing schema from the context so it is limited to context
124 * preparation period before working with data. YANG features, respectively their use in if-feature
125 * statements, are evaluated as part of schema compilation so a feature-specific compiled schema tree is generated
126 * as a result.
Radek Krejci8678fa42020-08-18 16:07:28 +0200127 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100128 * To enable any features, they must currently be specified when implementing a new schema with ::lys_parse() or
129 * ::ly_ctx_load_module(). To later examine what the status of a feature is, check its ::LYS_FENABLED flag or
130 * search for it first with ::lys_feature_value(). Lastly, to evaluate compiled if-features, use ::lysc_iffeature_value().
Radek Krejci8678fa42020-08-18 16:07:28 +0200131 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100132 * To iterate over all features of a particular YANG module, use ::lysp_feature_next().
Radek Krejci8678fa42020-08-18 16:07:28 +0200133 *
134 * Note, that the feature's state can affect some of the output formats (e.g. Tree format).
135 *
136 * Functions List
137 * --------------
Radek Krejci8678fa42020-08-18 16:07:28 +0200138 * - ::lys_feature_value()
Radek Krejci8678fa42020-08-18 16:07:28 +0200139 * - ::lysc_iffeature_value()
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100140 * - ::lysp_feature_next()
Radek Krejci8678fa42020-08-18 16:07:28 +0200141 */
142
143/**
Radek Krejci2ff0d572020-05-21 15:27:28 +0200144 * @ingroup trees
Radek Krejci8678fa42020-08-18 16:07:28 +0200145 * @defgroup schematree Schema Tree
Radek Krejci2ff0d572020-05-21 15:27:28 +0200146 * @{
147 *
148 * Data structures and functions to manipulate and access schema tree.
149 */
150
Michal Vasko64246d82020-08-19 12:35:00 +0200151/* *INDENT-OFF* */
152
Radek Krejci2ff0d572020-05-21 15:27:28 +0200153/**
Michal Vasko208a04a2020-10-21 15:17:12 +0200154 * @brief Macro to iterate via all elements in a schema (sub)tree including input and output.
155 * Note that __actions__ and __notifications__ of traversed nodes __are ignored__! To traverse
156 * on all the nodes including those, use ::lysc_tree_dfs_full() instead.
157 *
158 * This is the opening part to the #LYSC_TREE_DFS_END - they always have to be used together.
Radek Krejci0935f412019-08-20 16:15:18 +0200159 *
160 * The function follows deep-first search algorithm:
161 * <pre>
162 * 1
163 * / \
164 * 2 4
165 * / / \
166 * 3 5 6
167 * </pre>
168 *
169 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
Radek Krejci2a9fc652021-01-22 17:44:34 +0100170 * START can be any of the lysc_node* types (including lysc_node_action and lysc_node_notif),
Radek Krejci0935f412019-08-20 16:15:18 +0200171 * ELEM variable must be of the struct lysc_node* type.
172 *
173 * To skip a particular subtree, instead of the continue statement, set LYSC_TREE_DFS_continue
174 * variable to non-zero value.
175 *
176 * Use with opening curly bracket '{' after the macro.
177 *
178 * @param START Pointer to the starting element processed first.
179 * @param ELEM Iterator intended for use in the block.
180 */
181#define LYSC_TREE_DFS_BEGIN(START, ELEM) \
Radek Krejci857189e2020-09-01 13:26:36 +0200182 { ly_bool LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
Michal Vasko14ed9cd2021-01-28 14:16:25 +0100183 for ((ELEM) = (LYSC_TREE_DFS_next) = (struct lysc_node *)(START); \
Radek Krejci0935f412019-08-20 16:15:18 +0200184 (ELEM); \
185 (ELEM) = (LYSC_TREE_DFS_next), LYSC_TREE_DFS_continue = 0)
186
187/**
188 * @brief Macro to iterate via all elements in a (sub)tree. This is the closing part
189 * to the #LYSC_TREE_DFS_BEGIN - they always have to be used together.
190 *
191 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
Radek Krejci2a9fc652021-01-22 17:44:34 +0100192 * START can be a pointer to any of the lysc_node* types (including lysc_node_action and lysc_node_notif),
Radek Krejci0935f412019-08-20 16:15:18 +0200193 * ELEM variable must be pointer to the lysc_node type.
194 *
195 * Use with closing curly bracket '}' after the macro.
196 *
197 * @param START Pointer to the starting element processed first.
198 * @param ELEM Iterator intended for use in the block.
199 */
Radek Krejci0935f412019-08-20 16:15:18 +0200200#define LYSC_TREE_DFS_END(START, ELEM) \
201 /* select element for the next run - children first */ \
202 if (LYSC_TREE_DFS_continue) { \
203 (LYSC_TREE_DFS_next) = NULL; \
204 } else { \
Michal Vasko544e58a2021-01-28 14:33:41 +0100205 (LYSC_TREE_DFS_next) = (struct lysc_node *)lysc_node_child(ELEM); \
Michal Vasko208a04a2020-10-21 15:17:12 +0200206 } \
Radek Krejci0935f412019-08-20 16:15:18 +0200207 if (!(LYSC_TREE_DFS_next)) { \
Michal Vasko208a04a2020-10-21 15:17:12 +0200208 /* no children, try siblings */ \
209 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
Radek Krejci0935f412019-08-20 16:15:18 +0200210 } \
211 while (!(LYSC_TREE_DFS_next)) { \
212 /* parent is already processed, go to its sibling */ \
Radek Krejci7d95fbb2021-01-26 17:33:13 +0100213 (ELEM) = (ELEM)->parent; \
Michal Vasko208a04a2020-10-21 15:17:12 +0200214 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
215 } }
216
217/**
218 * @brief Helper macro for #LYSC_TREE_DFS_END, should not be used directly!
219 */
220#define _LYSC_TREE_DFS_NEXT(START, ELEM, NEXT) \
221 if ((ELEM) == (struct lysc_node *)(START)) { \
222 /* we are done, no next element to process */ \
223 break; \
224 } \
Michal Vasko544e58a2021-01-28 14:33:41 +0100225 (NEXT) = (ELEM)->next;
Radek Krejci0935f412019-08-20 16:15:18 +0200226
Michal Vasko64246d82020-08-19 12:35:00 +0200227/* *INDENT-ON* */
228
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200229#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
230
Radek Krejcide7a9c42021-03-10 13:13:06 +0100231/**
232 * @defgroup schemanodetypes Schema Node Types
233 * Values of the ::lysp_node.nodetype and ::lysc_node.nodetype members.
234 * @{
235 */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200236#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
237#define LYS_CONTAINER 0x0001 /**< container statement node */
238#define LYS_CHOICE 0x0002 /**< choice statement node */
239#define LYS_LEAF 0x0004 /**< leaf statement node */
240#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
241#define LYS_LIST 0x0010 /**< list statement node */
242#define LYS_ANYXML 0x0020 /**< anyxml statement node */
243#define LYS_ANYDATA 0x0060 /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
244#define LYS_CASE 0x0080 /**< case statement node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200245
Michal Vasko7f45cf22020-10-01 12:49:44 +0200246#define LYS_RPC 0x0100 /**< RPC statement node */
247#define LYS_ACTION 0x0200 /**< action statement node */
248#define LYS_NOTIF 0x0400 /**< notification statement node */
Radek Krejcie7b95092019-05-15 11:03:07 +0200249
Michal Vasko7f45cf22020-10-01 12:49:44 +0200250#define LYS_USES 0x0800 /**< uses statement node */
251#define LYS_INPUT 0x1000 /**< RPC/action input node */
252#define LYS_OUTPUT 0x2000 /**< RPC/action output node */
253#define LYS_GROUPING 0x4000
254#define LYS_AUGMENT 0x8000
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100255
Radek Krejcif13b87b2020-12-01 22:02:17 +0100256#define LYS_NODETYPE_MASK 0xffff /**< Mask for nodetypes, the value is limited for 16 bits */
Radek Krejcide7a9c42021-03-10 13:13:06 +0100257/** @} schemanodetypes */
Radek Krejcif13b87b2020-12-01 22:02:17 +0100258
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200259/**
Radek Krejci61837f72021-03-02 19:53:59 +0100260 * @brief Generic test for operation statements.
261 *
262 * This macro matches a subset of schema nodes that maps to common ::lysc_node or ::lysp_node structures. To match all
263 * such nodes, use ::LY_STMT_IS_NODE()
264 *
265 * This macro matches action and RPC.
Radek Krejci6b88a462021-02-17 12:39:34 +0100266 */
267#define LY_STMT_IS_OP(STMT) (((STMT) == LY_STMT_ACTION) || ((STMT) == LY_STMT_RPC))
268
269/**
Radek Krejci61837f72021-03-02 19:53:59 +0100270 * @brief Generic test for schema data nodes.
Radek Krejci6b88a462021-02-17 12:39:34 +0100271 *
Radek Krejci61837f72021-03-02 19:53:59 +0100272 * This macro matches a subset of schema nodes that maps to common ::lysc_node or ::lysp_node structures. To match all
273 * such nodes, use ::LY_STMT_IS_NODE()
Radek Krejci6b88a462021-02-17 12:39:34 +0100274 *
Radek Krejci61837f72021-03-02 19:53:59 +0100275 * This macro matches anydata, anyxml, augment, case, choice, container, grouping, leaf, leaf-list, list and uses. Note
276 * 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 +0100277 */
Radek Krejci61837f72021-03-02 19:53:59 +0100278#define LY_STMT_IS_DATA_NODE(STMT) (((STMT) >= LY_STMT_ANYDATA) && ((STMT) <= LY_STMT_LIST))
279
280/**
281 * @brief Generic test for any schema node that maps to common ::lysc_node or ::lysp_node structures.
282 *
283 * Note that the list of statements that can appear in parsed or compiled schema trees differs (e.g. no uses in compiled tree).
284 *
285 * To check for some of the subsets of this test, try ::LY_STMT_IS_DATA_NODE() or ::LY_STMT_IS_OP().
286 *
287 * This macro matches action, anydata, anyxml, augment, case, choice, container, grouping, input, leaf, leaf-list, list,
288 * notification, output, RPC and uses.
289 */
290#define LY_STMT_IS_NODE(STMT) (((STMT) >= LY_STMT_NOTIFICATION) && ((STMT) <= LY_STMT_LIST))
Radek Krejci6b88a462021-02-17 12:39:34 +0100291
292/**
Radek Krejcid6b76452019-09-03 17:03:03 +0200293 * @brief List of YANG statements
294 */
295enum ly_stmt {
296 LY_STMT_NONE = 0,
Radek Krejci6b88a462021-02-17 12:39:34 +0100297
298 LY_STMT_NOTIFICATION, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node_notif *`.
299 The RPCs/Actions and Notifications are expected in a separated lists than the rest of
300 data definition nodes as it is done in generic structures of libyang. */
Radek Krejci61837f72021-03-02 19:53:59 +0100301 LY_STMT_INPUT,
302 LY_STMT_OUTPUT,
Radek Krejci6b88a462021-02-17 12:39:34 +0100303
304/* LY_STMT_IS_OP */
Radek Krejcieccf6602021-02-05 19:42:54 +0100305 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 +0100306 The RPCs/Actions and Notifications are expected in a separated lists than the rest of
307 data definition nodes as it is done in generic structures of libyang. */
308 LY_STMT_RPC, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node_action *`.
309 The RPCs/Actions and Notifications are expected in a separated lists than the rest of
310 data definition nodes as it is done in generic structures of libyang. */
311
Radek Krejci61837f72021-03-02 19:53:59 +0100312/* LY_STMT_IS_DATA_NODE */
Radek Krejcieccf6602021-02-05 19:42:54 +0100313 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 +0100314 Note that due to ::lysc_node compatibility the anydata is expected to be actually
315 mixed in the linked list with other ::lysc_node based nodes. The RPCs/Actions and
316 Notifications are expected in a separated lists as it is done in generic structures
317 of libyang. */
Radek Krejcieccf6602021-02-05 19:42:54 +0100318 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 +0100319 Note that due to ::lysc_node compatibility the anyxml is expected to be actually
320 mixed in the linked list with other ::lysc_node based nodes. The RPCs/Actions and
321 Notifications are expected in a separated lists as it is done in generic structures
322 of libyang. */
323 LY_STMT_AUGMENT,
324 LY_STMT_CASE, /**< TODO is it possible to compile cases without the parent choice? */
325 LY_STMT_CHOICE, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
326 Note that due to ::lysc_node compatibility the choice is expected to be actually
327 mixed in the linked list with other ::lysc_node based nodes. The RPCs/Actions and
328 Notifications are expected in a separated lists as it is done in generic structures
329 of libyang. */
330 LY_STMT_CONTAINER, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
331 Note that due to ::lysc_node compatibility the container is expected to be actually
332 mixed in the linked list with other ::lysc_node based nodes. The RPCs/Actions and
333 Notifications are expected in a separated lists as it is done in generic structures
334 of libyang. */
335 LY_STMT_GROUPING,
336 LY_STMT_LEAF, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
337 Note that due to ::lysc_node compatibility the leaf is expected to be actually
338 mixed in the linked list with other ::lysc_node based nodes. The RPCs/Actions and
339 Notifications are expected in a separated lists as it is done in generic structures
340 of libyang. */
341 LY_STMT_LEAF_LIST, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
342 Note that due to ::lysc_node compatibility the leaf-list is expected to be actually
343 mixed in the linked list with other ::lysc_node based nodes. The RPCs/Actions and
344 Notifications are expected in a separated lists as it is done in generic structures
345 of libyang. */
346 LY_STMT_LIST, /**< in ::lysc_ext_substmt.storage stored as a pointer to linked list of `struct lysc_node *`.
347 Note that due to ::lysc_node compatibility the list is expected to be actually
348 mixed in the linked list with other ::lysc_node based nodes. The RPCs/Actions and
349 Notifications are expected in a separated lists as it is done in generic structures
350 of libyang. */
351 LY_STMT_USES,
352
353/* rest */
Radek Krejcid6b76452019-09-03 17:03:03 +0200354 LY_STMT_ARGUMENT,
Radek Krejcid6b76452019-09-03 17:03:03 +0200355 LY_STMT_BASE,
356 LY_STMT_BELONGS_TO,
357 LY_STMT_BIT,
Radek Krejcieccf6602021-02-05 19:42:54 +0100358 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 +0200359 LY_STMT_CONTACT,
Radek Krejcieccf6602021-02-05 19:42:54 +0100360 LY_STMT_DEFAULT,
Radek Krejci6b88a462021-02-17 12:39:34 +0100361 LY_STMT_DESCRIPTION, /**< in ::lysc_ext_substmt.storage stored as a pointer to `const char *` (cardinality < #LY_STMT_CARD_SOME)
362 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200363 LY_STMT_DEVIATE,
364 LY_STMT_DEVIATION,
365 LY_STMT_ENUM,
366 LY_STMT_ERROR_APP_TAG,
367 LY_STMT_ERROR_MESSAGE,
368 LY_STMT_EXTENSION,
Radek Krejcieccf6602021-02-05 19:42:54 +0100369 LY_STMT_EXTENSION_INSTANCE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200370 LY_STMT_FEATURE,
371 LY_STMT_FRACTION_DIGITS,
Radek Krejcid6b76452019-09-03 17:03:03 +0200372 LY_STMT_IDENTITY,
Radek Krejci6b88a462021-02-17 12:39:34 +0100373 LY_STMT_IF_FEATURE, /**< if-feature statements are not compiled, they are evaluated and the parent statement is
374 preserved only in case the evaluation of all the if-feature statements is true.
375 Therefore there is no storage expected. */
Radek Krejcid6b76452019-09-03 17:03:03 +0200376 LY_STMT_IMPORT,
377 LY_STMT_INCLUDE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200378 LY_STMT_KEY,
Radek Krejcid6b76452019-09-03 17:03:03 +0200379 LY_STMT_LENGTH,
Radek Krejcieccf6602021-02-05 19:42:54 +0100380 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 +0200381 LY_STMT_MAX_ELEMENTS,
382 LY_STMT_MIN_ELEMENTS,
383 LY_STMT_MODIFIER,
384 LY_STMT_MODULE,
385 LY_STMT_MUST,
386 LY_STMT_NAMESPACE,
Radek Krejcid6b76452019-09-03 17:03:03 +0200387 LY_STMT_ORDERED_BY,
388 LY_STMT_ORGANIZATION,
Radek Krejcid6b76452019-09-03 17:03:03 +0200389 LY_STMT_PATH,
390 LY_STMT_PATTERN,
391 LY_STMT_POSITION,
392 LY_STMT_PREFIX,
393 LY_STMT_PRESENCE,
394 LY_STMT_RANGE,
Radek Krejci6b88a462021-02-17 12:39:34 +0100395 LY_STMT_REFERENCE, /**< in ::lysc_ext_substmt.storage stored as a pointer to `const char *` (cardinality < #LY_STMT_CARD_SOME)
396 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200397 LY_STMT_REFINE,
398 LY_STMT_REQUIRE_INSTANCE,
399 LY_STMT_REVISION,
400 LY_STMT_REVISION_DATE,
Radek Krejcieccf6602021-02-05 19:42:54 +0100401 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 +0200402 LY_STMT_SUBMODULE,
Radek Krejcieccf6602021-02-05 19:42:54 +0100403 LY_STMT_TYPE, /**< in ::lysc_ext_substmt.storage stored as a pointer to `struct lysc_type *` (cardinality < #LY_STMT_CARD_SOME)
404 or as a pointer to a [sized array](@ref sizedarrays) `struct lysc_type **` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200405 LY_STMT_TYPEDEF,
406 LY_STMT_UNIQUE,
Radek Krejcieccf6602021-02-05 19:42:54 +0100407 LY_STMT_UNITS, /**< in ::lysc_ext_substmt.storage stored as a pointer to `const char *` (cardinality < #LY_STMT_CARD_SOME)
408 or as a pointer to a [sized array](@ref sizedarrays) `const char **` */
Radek Krejcid6b76452019-09-03 17:03:03 +0200409 LY_STMT_VALUE,
410 LY_STMT_WHEN,
411 LY_STMT_YANG_VERSION,
Radek Krejci2b0f0f12021-03-02 16:02:35 +0100412 LY_STMT_YIN_ELEMENT,
413
414 /* separated from the list of statements
415 * the following tokens are part of the syntax and parsers have to work
416 * with them, but they are not a standard YANG statements
417 */
418 LY_STMT_SYNTAX_SEMICOLON,
419 LY_STMT_SYNTAX_LEFT_BRACE,
420 LY_STMT_SYNTAX_RIGHT_BRACE,
421
422 /*
423 * YIN-specific tokens, still they are part of the syntax, but not the standard statements
424 */
425 LY_STMT_ARG_TEXT,
426 LY_STMT_ARG_VALUE
Radek Krejcid6b76452019-09-03 17:03:03 +0200427};
428
429/**
Radek Krejcif8ca8192021-03-02 16:50:06 +0100430 * @brief Stringify statement identifier.
431 * @param[in] stmt The statement identifier to stringify.
432 * @return Constant string representation of the given @p stmt.
433 */
434const char *ly_stmt2str(enum ly_stmt stmt);
435
436/**
Radek Krejci39b7fc22021-02-26 23:29:18 +0100437 * @brief Convert nodetype to statement identifier
438 * @param[in] nodetype Nodetype to convert.
439 * @return Statement identifier representing the given @p nodetype.
440 */
441enum ly_stmt lys_nodetype2stmt(uint16_t nodetype);
442
443/**
Radek Krejcib1c11532021-03-29 14:14:19 +0200444 * @brief Possible cardinalities of the YANG statements.
445 *
446 * Used in extensions plugins to define cardinalities of the extension instance substatements.
447 */
448enum ly_stmt_cardinality {
449 LY_STMT_CARD_OPT, /* 0..1 */
450 LY_STMT_CARD_MAND, /* 1 */
451 LY_STMT_CARD_SOME, /* 1..n */
452 LY_STMT_CARD_ANY /* 0..n */
453};
454
455/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200456 * @brief YANG import-stmt
457 */
458struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200459 struct lys_module *module; /**< pointer to the imported module
460 (mandatory, but resolved when the referring module is completely parsed) */
461 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200462 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200463 const char *dsc; /**< description */
464 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200465 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100466 uint16_t flags; /**< LYS_INTERNAL value (@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200467 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
468};
469
470/**
471 * @brief YANG include-stmt
472 */
473struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100474 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200475 (mandatory, but resolved when the referring module is completely parsed) */
476 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200477 const char *dsc; /**< description */
478 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200479 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200480 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
Radek Krejci771928a2021-01-19 13:42:36 +0100481 ly_bool injected; /**< flag to mark includes copied into main module from submodules,
482 only for backward compatibility with YANG 1.0, which does not require the
483 main module to include all submodules. */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200484};
485
486/**
487 * @brief YANG extension-stmt
488 */
489struct lysp_ext {
490 const char *name; /**< extension name */
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100491 const char *argname; /**< argument name, NULL if not specified */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200492 const char *dsc; /**< description statement */
493 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200494 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200495 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */
Michal Vasko5fe75f12020-03-02 13:52:37 +0100496
Radek Krejci720d2612021-03-03 19:44:22 +0100497 struct lysc_ext *compiled; /**< pointer to the compiled extension definition.
498 The extension definition is compiled only if there is compiled extension instance,
499 otherwise this pointer remains NULL. The compiled extension definition is shared
500 among all extension instances. */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200501};
502
503/**
504 * @brief Helper structure for generic storage of the extension instances content.
505 */
506struct lysp_stmt {
507 const char *stmt; /**< identifier of the statement */
508 const char *arg; /**< statement's argument */
Radek Krejci8df109d2021-04-23 12:19:08 +0200509 LY_VALUE_FORMAT format; /**< prefix format of the identifier/argument (::LY_VALUE_XML is YIN format) */
Radek Krejci0b013302021-03-29 15:22:32 +0200510 void *prefix_data; /**< Format-specific data for prefix resolution (see ly_resolve_prefix()) */
Michal Vaskofc2cd072021-02-24 13:17:17 +0100511
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200512 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200513 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
David Sedlákb9d75c42019-08-14 10:49:42 +0200514 uint16_t flags; /**< statement flags, can be set to LYS_YIN_ATTR */
Radek Krejci335332a2019-09-05 13:03:35 +0200515 enum ly_stmt kw; /**< numeric respresentation of the stmt value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200516};
517
David Sedlákae4b4512019-08-14 10:45:56 +0200518#define LYS_YIN 0x1 /**< used to specify input format of extension instance */
519
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200520/**
521 * @brief YANG extension instance
522 */
523struct lysp_ext_instance {
David Sedlákbbd06ca2019-06-27 14:15:38 +0200524 const char *name; /**< extension identifier, including possible prefix */
525 const char *argument; /**< optional value of the extension's argument */
aPiecek60d9d672021-04-27 15:49:57 +0200526 LY_VALUE_FORMAT format; /**< prefix format of the extension name/argument (::LY_VALUE_XML is YIN format) */
527 struct lysp_node *parsed; /**< Simply parsed (unresolved) YANG schema tree serving as a cache.
528 Only lys_compile_extension_instance() can set this. */
Michal Vaskofc2cd072021-02-24 13:17:17 +0100529 void *prefix_data; /**< Format-specific data for prefix resolution
Radek Krejci0b013302021-03-29 15:22:32 +0200530 (see ly_resolve_prefix()) */
Michal Vaskofc2cd072021-02-24 13:17:17 +0100531
Radek Krejci5f9a3672021-03-05 21:35:22 +0100532 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
533
Radek Krejci335332a2019-09-05 13:03:35 +0200534 void *parent; /**< pointer to the parent element holding the extension instance(s), use
Radek Krejciab430862021-03-02 20:13:40 +0100535 ::lysp_ext_instance#parent_stmt to access the schema element */
Radek Krejciab430862021-03-02 20:13:40 +0100536 enum ly_stmt parent_stmt; /**< value identifying placement of the extension instance */
537 LY_ARRAY_COUNT_TYPE parent_stmt_index; /**< in case the instance is in a substatement, this identifies
538 the index of that substatement in its [sized array](@ref sizedarrays) (if any) */
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100539 uint16_t flags; /**< LYS_INTERNAL value (@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200540};
541
542/**
543 * @brief YANG feature-stmt
544 */
545struct lysp_feature {
546 const char *name; /**< feature name (mandatory) */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100547 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
548 struct lysc_iffeature *iffeatures_c; /**< compiled if-features */
549 struct lysp_feature **depfeatures; /**< list of pointers to other features depending on this one
550 ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200551 const char *dsc; /**< description statement */
552 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200553 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100554 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values and
555 LYS_FENABLED are allowed */
556};
557
558/**
559 * @brief Compiled YANG if-feature-stmt
560 */
561struct lysc_iffeature {
562 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
563 struct lysp_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200564};
565
566/**
Michal Vasko7f45cf22020-10-01 12:49:44 +0200567 * @brief Qualified name (optional prefix followed by an identifier).
568 */
569struct lysp_qname {
570 const char *str; /**< qualified name string */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200571 const struct lysp_module *mod; /**< module to resolve any prefixes found in the string, it must be
Michal Vasko7f45cf22020-10-01 12:49:44 +0200572 stored explicitly because of deviations/refines */
573};
574
575/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200576 * @brief YANG identity-stmt
577 */
578struct lysp_ident {
579 const char *name; /**< identity name (mandatory), including possible prefix */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200580 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200581 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200582 const char *dsc; /**< description statement */
583 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200584 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200585 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
586};
587
Michal Vasko71e64ca2018-09-07 16:30:29 +0200588/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200589 * @brief Covers restrictions: range, length, pattern, must
590 */
591struct lysp_restr {
Radek Krejcif13b87b2020-12-01 22:02:17 +0100592#define LYSP_RESTR_PATTERN_ACK 0x06
593#define LYSP_RESTR_PATTERN_NACK 0x15
Michal Vasko7f45cf22020-10-01 12:49:44 +0200594 struct lysp_qname arg; /**< The restriction expression/value (mandatory);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200595 in case of pattern restriction, the first byte has a special meaning:
596 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
597 const char *emsg; /**< error-message */
598 const char *eapptag; /**< error-app-tag value */
599 const char *dsc; /**< description */
600 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200601 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200602};
603
604/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200605 * @brief YANG revision-stmt
606 */
607struct lysp_revision {
Radek Krejcicb3e6472021-01-06 08:19:01 +0100608 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200609 const char *dsc; /**< description statement */
610 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200611 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200612};
613
614/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200615 * @brief Enumeration/Bit value definition
616 */
617struct lysp_type_enum {
618 const char *name; /**< name (mandatory) */
619 const char *dsc; /**< description statement */
620 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200621 int64_t value; /**< enum's value or bit's position */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200622 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200623 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200624 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
625 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200626};
627
628/**
629 * @brief YANG type-stmt
630 *
631 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
632 */
633struct lysp_type {
634 const char *name; /**< name of the type (mandatory) */
635 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
636 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200637 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
638 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
639 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Michal Vasko004d3152020-06-11 19:59:22 +0200640 struct lyxp_expr *path; /**< parsed path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200641 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200642 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
643 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200644
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200645 const struct lysp_module *pmod; /**< (sub)module where the type is defined (needed for deviations) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100646 struct lysc_type *compiled; /**< pointer to the compiled type */
647
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200648 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
649 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100650 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200651};
652
653/**
654 * @brief YANG typedef-stmt
655 */
656struct lysp_tpdf {
657 const char *name; /**< name of the newly defined type (mandatory) */
658 const char *units; /**< units of the newly defined type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200659 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 +0200660 const char *dsc; /**< description statement */
661 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200662 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200663 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100664 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200665};
666
667/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200668 * @brief YANG when-stmt
669 */
670struct lysp_when {
671 const char *cond; /**< specified condition (mandatory) */
672 const char *dsc; /**< description statement */
673 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200674 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200675};
676
677/**
678 * @brief YANG refine-stmt
679 */
680struct lysp_refine {
681 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
682 const char *dsc; /**< description statement */
683 const char *ref; /**< reference statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200684 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200685 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200686 const char *presence; /**< presence description */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200687 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200688 uint32_t min; /**< min-elements constraint */
689 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200690 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200691 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
692};
693
694/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200695 * @ingroup schematree
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200696 * @defgroup deviatetypes Deviate types
Radek Krejci8678fa42020-08-18 16:07:28 +0200697 *
698 * Type of the deviate operation (used as ::lysp_deviate.mod)
699 *
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200700 * @{
701 */
702#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
703#define LYS_DEV_ADD 2 /**< deviate type add */
704#define LYS_DEV_DELETE 3 /**< deviate type delete */
705#define LYS_DEV_REPLACE 4 /**< deviate type replace */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200706/** @} deviatetypes */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200707
708/**
709 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
710 */
711struct lysp_deviate {
712 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
713 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200714 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200715};
716
717struct lysp_deviate_add {
718 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
719 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200720 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200721 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200722 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200723 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
724 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200725 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
726 uint32_t min; /**< min-elements constraint */
727 uint32_t max; /**< max-elements constraint, 0 means unbounded */
728};
729
730struct lysp_deviate_del {
731 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
732 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200733 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200734 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200735 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200736 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
737 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200738};
739
740struct lysp_deviate_rpl {
741 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
742 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200743 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200744 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200745 const char *units; /**< units of the values */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200746 struct lysp_qname dflt; /**< default value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200747 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
748 uint32_t min; /**< min-elements constraint */
749 uint32_t max; /**< max-elements constraint, 0 means unbounded */
750};
751
752struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200753 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200754 const char *dsc; /**< description statement */
755 const char *ref; /**< reference statement */
Michal Vasko22df3f02020-08-24 13:29:22 +0200756 struct lysp_deviate *deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200757 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200758};
759
Radek Krejci4f28eda2018-11-12 11:46:16 +0100760/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100761 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200762 * @defgroup spnodeflags Parsed schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100763 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200764 * Various flags for parsed schema nodes (used as ::lysp_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100765 *
766 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
767 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200768 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100769 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
770 * 5 - list 10 - input 15 - typedef 20 - deviate
771 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200772 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
773 * 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
774 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200775 * 1 LYS_CONFIG_W |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200776 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
777 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vasko5297a432020-08-31 12:27:51 +0200778 * 2 LYS_CONFIG_R |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200779 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
780 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
781 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
782 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
783 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
784 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
785 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
786 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
787 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
788 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
789 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
790 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
791 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100792 * LYS_FENABLED | | | | | | | | | | | |x| | | | | | | | | | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200793 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
794 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
795 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
796 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
797 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
798 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
799 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
800 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
801 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
802 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
803 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
804 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
805 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
806 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
807 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
808 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
809 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
810 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
811 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200812 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
David Sedlákae4b4512019-08-14 10:45:56 +0200813 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x|
Michal Vasko5297a432020-08-31 12:27:51 +0200814 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
815 * 12 LYS_YIN_ARGUMENT | | | | | | | | | | | | | | | | | | | | | | |x|
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100816 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
817 * 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 +0200818 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100819 *
820 */
821
822/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100823 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200824 * @defgroup scnodeflags Compiled schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100825 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200826 * Various flags for compiled schema nodes (used as ::lysc_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100827 *
Radek Krejci61e042e2019-09-10 15:53:09 +0200828 * 1 - container 6 - anydata/anyxml 11 - identity
829 * 2 - choice 7 - case 12 - extension
830 * 3 - leaf 8 - notification 13 - bitenum
Michal Vasko03ff5a72019-09-11 13:49:33 +0200831 * 4 - leaflist 9 - rpc/action 14 - when
Michal Vaskoecd62de2019-11-13 12:35:11 +0100832 * 5 - list 10 - feature
Radek Krejci4f28eda2018-11-12 11:46:16 +0100833 *
Michal Vaskoecd62de2019-11-13 12:35:11 +0100834 * 1 1 1 1 1
835 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
836 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskod09b7622021-01-26 09:14:13 +0100837 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100838 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskod09b7622021-01-26 09:14:13 +0100839 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100840 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
841 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x|x|x|x| |x|
842 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
843 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x|x|x|x| |x|
844 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
845 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x|x|x|x| |x|
846 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
847 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
848 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
849 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
850 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | |
851 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
852 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
853 * LYS_PRESENCE |x| | | | | | | | | | | | | |
854 * LYS_UNIQUE | | |x| | | | | | | | | | | |
855 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
856 * 9 LYS_KEY | | |x| | | | | | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100857 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
858 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
Michal Vaskod1e53b92021-01-28 13:11:06 +0100859 * LYS_IS_ENUM | | | | | | | | | | | | |x| |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100860 * LYS_KEYLESS | | | | |x| | | | | | | | | |
861 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
862 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
863 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
864 * 12 LYS_SET_CONFIG |x|x|x|x|x|x| | | | | | | | |
Michal Vaskod1e53b92021-01-28 13:11:06 +0100865 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
866 * 13 LYS_IS_INPUT |x|x|x|x|x|x|x| | | | | | | |
867 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
868 * 14 LYS_IS_OUTPUT |x|x|x|x|x|x|x| | | | | | | |
869 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
870 * 15 LYS_IS_NOTIF |x|x|x|x|x|x|x| | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100871 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100872 *
873 */
874
875/**
876 * @defgroup snodeflags Schema nodes flags
Radek Krejci8678fa42020-08-18 16:07:28 +0200877 *
878 * Various flags for schema nodes ([parsed](@ref spnodeflags) as well as [compiled](@ref scnodeflags)).
879 *
Radek Krejci4f28eda2018-11-12 11:46:16 +0100880 * @{
881 */
Michal Vaskod1e53b92021-01-28 13:11:06 +0100882#define LYS_CONFIG_W 0x01 /**< config true; */
883#define LYS_CONFIG_R 0x02 /**< config false; */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200884#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100885#define LYS_STATUS_CURR 0x04 /**< status current; */
886#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
887#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
888#define LYS_STATUS_MASK 0x1C /**< mask for status value */
889#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100890 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
891 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
892 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
893 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100894#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
895 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
896 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100897#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Michal Vaskoc118ae22020-08-06 14:51:09 +0200898#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, but it is not only for explicit presence
899 containers, but also for NP containers with some meaning, applicable only to
900 ::lysc_node_container */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100901#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 +0100902#define LYS_KEY 0x0100 /**< flag for leafs being a key of a list, applicable only to ::lysc_node_leaf */
903#define LYS_KEYLESS 0x0200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100904#define LYS_FENABLED 0x20 /**< feature enabled flag, applicable only to ::lysp_feature. */
Michal Vaskoe78faec2021-04-08 17:24:43 +0200905#define LYS_ORDBY_SYSTEM 0x80 /**< ordered-by system configuration lists, applicable only to
906 ::lysc_node_leaflist/::lysp_node_leaflist and ::lysc_node_list/::lysp_node_list */
907#define LYS_ORDBY_USER 0x40 /**< ordered-by user configuration lists, applicable only to
908 ::lysc_node_leaflist/::lysp_node_leaflist and ::lysc_node_list/::lysp_node_list;
909 is always set for state leaf-lists, and key-less lists */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100910#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
911#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
Michal Vaskod1e53b92021-01-28 13:11:06 +0100912#define LYS_YINELEM_FALSE 0x0100 /**< yin-element false for extension's argument */
913#define LYS_YINELEM_MASK 0x0180 /**< mask for yin-element value */
914#define LYS_USED_GRP 0x0400 /**< internal flag for validating not-instantiated groupings
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200915 (resp. do not validate again the instantiated groupings). */
Michal Vaskod1e53b92021-01-28 13:11:06 +0100916#define LYS_SET_VALUE 0x0200 /**< value attribute is set */
917#define LYS_SET_MIN 0x0200 /**< min attribute is set */
918#define LYS_SET_MAX 0x0400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100919
920#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
921#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
922#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
923#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
924#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
925#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
926#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
927#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
928#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
929#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100930#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 +0100931 cases of choice. This information is important for refines, since it is prohibited to make leafs
932 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100933 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
934 between own default or the default values taken from the type. */
935#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 +0100936#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 +0100937
Michal Vaskod1e53b92021-01-28 13:11:06 +0100938#define LYS_SINGLEQUOTED 0x0100 /**< flag for single-quoted argument of an extension instance's substatement, only when the source is YANG */
939#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 +0200940
Michal Vaskod1e53b92021-01-28 13:11:06 +0100941#define LYS_YIN_ATTR 0x0400 /**< flag to identify YIN attribute parsed as extension's substatement, only when the source is YIN */
942#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 +0200943
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100944#define LYS_INTERNAL 0x1000 /**< flag to identify internal parsed statements that should not be printed */
945
Michal Vaskod1e53b92021-01-28 13:11:06 +0100946#define LYS_IS_ENUM 0x0200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
947
948#define LYS_IS_INPUT 0x1000 /**< flag for nodes that are in the subtree of an input statement */
949
950#define LYS_IS_OUTPUT 0x2000 /**< flag for nodes that are in the subtree of an output statement */
951
952#define LYS_IS_NOTIF 0x4000 /**< flag for nodes that are in the subtree of a notification statement */
Radek Krejci693262f2019-04-29 15:23:20 +0200953
Radek Krejcife909632019-02-12 15:34:42 +0100954#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200955/** @} snodeflags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200956
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200957/**
958 * @brief Generic YANG data node
959 */
960struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100961 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejcide7a9c42021-03-10 13:13:06 +0100962 uint16_t nodetype; /**< [type of the node](@ref schemanodetypes) (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200963 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100964 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200965 const char *name; /**< node name (mandatory) */
966 const char *dsc; /**< description statement */
967 const char *ref; /**< reference statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200968 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)),
969 must be qname because of refines */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200970 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200971};
972
973/**
974 * @brief Extension structure of the lysp_node for YANG container
975 */
976struct lysp_node_container {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100977 union {
978 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
979 struct {
980 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
981 uint16_t nodetype; /**< LYS_CONTAINER */
982 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
983 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
984 const char *name; /**< node name (mandatory) */
985 const char *dsc; /**< description statement */
986 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100987 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
988 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
989 };
990 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200991
992 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200993 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +0100994 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200995 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200996 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100997 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200998 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100999 struct lysp_node_action *actions;/**< list of actions (linked list) */
1000 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001001};
1002
1003struct lysp_node_leaf {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001004 union {
1005 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1006 struct {
1007 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1008 uint16_t nodetype; /**< LYS_LEAF */
1009 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1010 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1011 const char *name; /**< node name (mandatory) */
1012 const char *dsc; /**< description statement */
1013 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001014 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1015 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1016 };
1017 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001018
1019 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001020 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001021 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001022 struct lysp_type type; /**< type of the leaf node (mandatory) */
1023 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001024 struct lysp_qname dflt; /**< default value, it may or may not be a qualified name */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001025};
1026
1027struct lysp_node_leaflist {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001028 union {
1029 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1030 struct {
1031 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1032 uint16_t nodetype; /**< LYS_LEAFLIST */
1033 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1034 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1035 const char *name; /**< node name (mandatory) */
1036 const char *dsc; /**< description statement */
1037 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001038 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1039 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1040 };
1041 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001042
1043 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001044 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001045 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001046 struct lysp_type type; /**< type of the leaf node (mandatory) */
1047 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001048 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)), they may or
1049 may not be qualified names */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001050 uint32_t min; /**< min-elements constraint */
1051 uint32_t max; /**< max-elements constraint, 0 means unbounded */
1052};
1053
1054struct lysp_node_list {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001055 union {
1056 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1057 struct {
1058 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1059 uint16_t nodetype; /**< LYS_LIST */
1060 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1061 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1062 const char *name; /**< node name (mandatory) */
1063 const char *dsc; /**< description statement */
1064 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001065 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1066 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1067 };
1068 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001069
1070 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001071 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001072 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001073 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001074 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001075 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001076 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001077 struct lysp_node_action *actions;/**< list of actions (linked list) */
1078 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001079 struct lysp_qname *uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001080 uint32_t min; /**< min-elements constraint */
1081 uint32_t max; /**< max-elements constraint, 0 means unbounded */
1082};
1083
1084struct lysp_node_choice {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001085 union {
1086 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1087 struct {
1088 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1089 uint16_t nodetype; /**< LYS_CHOICE */
1090 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1091 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1092 const char *name; /**< node name (mandatory) */
1093 const char *dsc; /**< description statement */
1094 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001095 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1096 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1097 };
1098 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001099
1100 /* choice */
1101 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001102 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001103 struct lysp_qname dflt; /**< default case */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001104};
1105
1106struct lysp_node_case {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001107 union {
1108 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1109 struct {
1110 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1111 uint16_t nodetype; /**< LYS_CASE */
1112 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1113 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1114 const char *name; /**< node name (mandatory) */
1115 const char *dsc; /**< description statement */
1116 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001117 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1118 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1119 };
1120 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001121
1122 /* case */
1123 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001124 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001125};
1126
1127struct lysp_node_anydata {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001128 union {
1129 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1130 struct {
1131 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1132 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1133 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1134 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1135 const char *name; /**< node name (mandatory) */
1136 const char *dsc; /**< description statement */
1137 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001138 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1139 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1140 };
1141 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001142
1143 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001144 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001145 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001146};
1147
1148struct lysp_node_uses {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001149 union {
1150 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1151 struct {
1152 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1153 uint16_t nodetype; /**< LYS_USES */
1154 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1155 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
1156 const char *name; /**< grouping name reference (mandatory) */
1157 const char *dsc; /**< description statement */
1158 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001159 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1160 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1161 };
1162 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001163
1164 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001165 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001166 struct lysp_node_augment *augments; /**< list of augments (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001167 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001168};
1169
1170/**
1171 * @brief YANG input-stmt and output-stmt
1172 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001173struct lysp_node_action_inout {
1174 union {
1175 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1176 struct {
1177 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1178 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
1179 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1180 struct lysp_node *next; /**< NULL */
1181 const char *name; /**< empty string */
1182 const char *dsc; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1183 const char *ref; /**< ALWAYS NULL, compatibility member with ::lysp_node */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001184 struct lysp_qname *iffeatures; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1185 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1186 };
1187 }; /**< common part corresponding to ::lysp_node */
1188
1189 /* inout */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001190 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1191 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001192 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci01180ac2021-01-27 08:48:22 +01001193 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001194};
1195
1196/**
1197 * @brief YANG rpc-stmt and action-stmt
1198 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001199struct lysp_node_action {
1200 union {
1201 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1202 struct {
1203 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1204 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
1205 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1206 struct lysp_node_action *next; /**< pointer to the next action (NULL if there is no one) */
1207 const char *name; /**< grouping name reference (mandatory) */
1208 const char *dsc; /**< description statement */
1209 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001210 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1211 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1212 };
1213 }; /**< common part corresponding to ::lysp_node */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001214
1215 /* action */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001216 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1217 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
1218
1219 struct lysp_node_action_inout input; /**< RPC's/Action's input */
1220 struct lysp_node_action_inout output; /**< RPC's/Action's output */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001221};
1222
1223/**
1224 * @brief YANG notification-stmt
1225 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001226struct lysp_node_notif {
1227 union {
1228 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1229 struct {
1230 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1231 uint16_t nodetype; /**< LYS_NOTIF */
1232 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1233 struct lysp_node_notif *next; /**< pointer to the next notification (NULL if there is no one) */
1234 const char *name; /**< grouping name reference (mandatory) */
1235 const char *dsc; /**< description statement */
1236 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001237 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1238 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1239 };
1240 }; /**< common part corresponding to ::lysp_node */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001241
1242 /* notif */
1243 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001244 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1245 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci01180ac2021-01-27 08:48:22 +01001246 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001247};
1248
1249/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001250 * @brief YANG grouping-stmt
1251 */
1252struct lysp_node_grp {
1253 union {
1254 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1255 struct {
1256 struct lysp_node *parent;/**< parent node (NULL if this is a top-level grouping) */
1257 uint16_t nodetype; /**< LYS_GROUPING */
1258 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1259 struct lysp_node_grp *next; /**< pointer to the next grouping (NULL if there is no one) */
1260 const char *name; /**< grouping name (mandatory) */
1261 const char *dsc; /**< description statement */
1262 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001263 struct lysp_qname *iffeatures; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1264 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1265 };
1266 }; /**< common part corresponding to ::lysp_node */
1267
1268 /* grp */
1269 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1270 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci01180ac2021-01-27 08:48:22 +01001271 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001272 struct lysp_node_action *actions; /**< list of actions (linked list) */
1273 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
1274};
1275
1276/**
1277 * @brief YANG uses-augment-stmt and augment-stmt (compatible with struct lysp_node )
1278 */
1279struct lysp_node_augment {
1280 union {
1281 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
1282 struct {
1283 struct lysp_node *parent;/**< parent node (NULL if this is a top-level augment) */
1284 uint16_t nodetype; /**< LYS_AUGMENT */
1285 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1286 struct lysp_node_augment *next; /**< pointer to the next augment (NULL if there is no one) */
1287 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
1288 const char *dsc; /**< description statement */
1289 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001290 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1291 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1292 };
1293 }; /**< common part corresponding to ::lysp_node */
1294
1295 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001296 struct lysp_when *when; /**< when statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001297 struct lysp_node_action *actions;/**< list of actions (linked list) */
1298 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
1299};
1300
1301/**
Radek Krejcif0fceb62018-09-05 14:58:45 +02001302 * @brief supported YANG schema version values
1303 */
1304typedef enum LYS_VERSION {
1305 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
Radek Krejci96e48da2020-09-04 13:18:06 +02001306 LYS_VERSION_1_0 = 1, /**< YANG 1 (1.0) */
Radek Krejcif0fceb62018-09-05 14:58:45 +02001307 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
1308} LYS_VERSION;
1309
1310/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001311 * @brief Printable YANG schema tree structure representing YANG module.
1312 *
1313 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
1314 */
1315struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001316 struct lys_module *mod; /**< covering module structure */
1317
Radek Krejcib7db73a2018-10-24 14:18:40 +02001318 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1319 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001320 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1321 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001322 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1323 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1324 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1325 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001326 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001327 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001328 struct lysp_node_augment *augments; /**< list of augments (linked list) */
1329 struct lysp_node_action *rpcs; /**< list of RPCs (linked list) */
1330 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001331 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001332 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001333
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001334 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001335 uint8_t parsing : 1; /**< flag for circular check */
1336 uint8_t is_submod : 1; /**< always 0 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001337};
1338
1339struct lysp_submodule {
Michal Vaskoc3781c32020-10-06 14:04:08 +02001340 struct lys_module *mod; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001341
1342 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1343 in the list is always the last (newest) revision of the module */
1344 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1345 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
1346 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1347 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1348 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1349 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001350 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001351 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001352 struct lysp_node_augment *augments; /**< list of augments (linked list) */
1353 struct lysp_node_action *rpcs; /**< list of RPCs (linked list) */
1354 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001355 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001356 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001357
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001358 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001359 uint8_t parsing : 1; /**< flag for circular check */
1360 uint8_t is_submod : 1; /**< always 1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001361
Michal Vaskoc3781c32020-10-06 14:04:08 +02001362 uint8_t latest_revision : 2; /**< flag to mark the latest available revision:
Radek Krejci086c7132018-10-26 15:29:04 +02001363 1 - the latest revision in searchdirs was not searched yet and this is the
1364 latest revision in the current context
1365 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001366 const char *name; /**< name of the module (mandatory) */
1367 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1368 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
1369 const char *org; /**< party/company responsible for the module */
1370 const char *contact; /**< contact information for the module */
1371 const char *dsc; /**< description of the module */
1372 const char *ref; /**< cross-reference for the module */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001373};
1374
1375/**
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001376 * @brief Get the parsed module or submodule name.
1377 *
1378 * @param[in] PMOD Parsed module or submodule.
1379 * @return Module or submodule name.
1380 */
1381#define LYSP_MODULE_NAME(PMOD) (PMOD->is_submod ? ((struct lysp_submodule *)PMOD)->name : ((struct lysp_module *)PMOD)->mod->name)
1382
1383/**
Radek Krejci8df109d2021-04-23 12:19:08 +02001384 * @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 +02001385 * the expected prefix data is a sized array of these structures.
1386 */
1387struct lysc_prefix {
1388 char *prefix; /**< used prefix */
1389 const struct lys_module *mod; /**< mapping to a module */
1390};
1391
1392/**
Radek Krejci0e59c312019-08-15 15:34:15 +02001393 * @brief Compiled YANG extension-stmt
Radek Krejci9f87b0c2021-03-05 14:45:26 +01001394 *
1395 * Note that the compiled extension definition is created only in case the extension is instantiated. It is not available
1396 * from the compiled schema, but from the parsed extension definition which is being searched when an extension instance
1397 * is being compiled.
Radek Krejci0e59c312019-08-15 15:34:15 +02001398 */
1399struct lysc_ext {
1400 const char *name; /**< extension name */
Radek Krejci9f87b0c2021-03-05 14:45:26 +01001401 const char *argname; /**< argument name, NULL if not specified */
Radek Krejci0e59c312019-08-15 15:34:15 +02001402 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcicc9e30f2021-03-29 12:45:08 +02001403 struct lyplg_ext *plugin; /**< Plugin implementing the specific extension */
Radek Krejci0935f412019-08-20 16:15:18 +02001404 struct lys_module *module; /**< module structure */
Michal Vasko6f4cbb62020-02-28 11:15:47 +01001405 uint32_t refcount; /**< reference counter since extension definition is shared among all its instances */
Radek Krejci0e59c312019-08-15 15:34:15 +02001406 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
1407};
1408
1409/**
Radek Krejcib1c11532021-03-29 14:14:19 +02001410 * @brief Description of the extension instance substatements.
1411 *
1412 * Provided by extensions plugins to libyang to be able to correctly compile the content of extension instances.
1413 * Note that order of the defined records matters - just follow the values of ::ly_stmt and order the records from lower to higher values.
1414 */
1415struct lysc_ext_substmt {
1416 enum ly_stmt stmt; /**< allowed substatement */
1417 enum ly_stmt_cardinality cardinality; /**< cardinality of the substatement */
1418 void *storage; /**< pointer to the storage of the compiled statement according to the specific
1419 lysc_ext_substmt::stmt and lysc_ext_substmt::cardinality */
1420};
1421
1422/**
Radek Krejcice8c1592018-10-29 15:35:51 +01001423 * @brief YANG extension instance
1424 */
1425struct lysc_ext_instance {
Radek Krejciad5963b2019-09-06 16:03:05 +02001426 struct lysc_ext *def; /**< pointer to the extension definition */
Radek Krejcice8c1592018-10-29 15:35:51 +01001427 const char *argument; /**< optional value of the extension's argument */
Radek Krejciab430862021-03-02 20:13:40 +01001428 struct lys_module *module; /**< module where the extension instantiated is defined */
Radek Krejci2a408df2018-10-29 16:32:26 +01001429 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f9a3672021-03-05 21:35:22 +01001430 struct lysc_ext_substmt *substmts; /**< list of allowed substatements with the storage to access the present
1431 substatements ([sized array](@ref sizedarrays)) */
Radek Krejci0e59c312019-08-15 15:34:15 +02001432 void *data; /**< private plugins's data, not used by libyang */
Radek Krejciab430862021-03-02 20:13:40 +01001433
1434 void *parent; /**< pointer to the parent element holding the extension instance(s), use
1435 ::lysc_ext_instance#parent_stmt to access the schema element */
1436 enum ly_stmt parent_stmt; /**< value identifying placement of the extension instance in specific statement */
1437 LY_ARRAY_COUNT_TYPE parent_stmt_index; /**< in case the instance is in a substatement, this identifies
1438 the index of that substatement in its [sized array](@ref sizedarrays) (if any) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001439};
1440
1441/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001442 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001443 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001444struct lysc_when {
1445 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko175012e2019-11-06 15:49:14 +01001446 struct lysc_node *context; /**< context node for evaluating the expression, NULL if the context is root node */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001447 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001448 const char *dsc; /**< description */
1449 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001450 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001451 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Michal Vaskoecd62de2019-11-13 12:35:11 +01001452 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS is allowed */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001453};
1454
1455/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001456 * @brief YANG identity-stmt
1457 */
1458struct lysc_ident {
1459 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +01001460 const char *dsc; /**< description */
1461 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001462 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001463 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
1464 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1465 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1466};
1467
1468/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001469 * @defgroup ifftokens if-feature expression tokens
Radek Krejci8678fa42020-08-18 16:07:28 +02001470 * Tokens of if-feature expression used in ::lysc_iffeature.expr.
Radek Krejci151a5b72018-10-19 14:21:44 +02001471 *
1472 * @{
1473 */
1474#define LYS_IFF_NOT 0x00 /**< operand "not" */
1475#define LYS_IFF_AND 0x01 /**< operand "and" */
1476#define LYS_IFF_OR 0x02 /**< operand "or" */
1477#define LYS_IFF_F 0x03 /**< feature */
Radek Krejci2ff0d572020-05-21 15:27:28 +02001478/** @} ifftokens */
Radek Krejci151a5b72018-10-19 14:21:44 +02001479
1480/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001481 * @brief Compiled YANG revision statement
1482 */
1483struct lysc_revision {
1484 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1485 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1486};
1487
Radek Krejci2167ee12018-11-02 16:09:07 +01001488struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001489 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001490 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001491 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1492 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001493 };
Radek Krejci693262f2019-04-29 15:23:20 +02001494 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001495 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1496 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001497 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001498 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001499 const char *dsc; /**< description */
1500 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001501 const char *emsg; /**< error-message */
1502 const char *eapptag; /**< error-app-tag value */
1503 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1504};
1505
1506struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001507 const char *expr; /**< original, not compiled, regular expression */
1508 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001509 const char *dsc; /**< description */
1510 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001511 const char *emsg; /**< error-message */
1512 const char *eapptag; /**< error-app-tag value */
1513 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0f969882020-08-21 16:56:47 +02001514 uint32_t inverted : 1; /**< invert-match flag */
1515 uint32_t refcount : 31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001516};
1517
1518struct lysc_must {
Radek Krejci2167ee12018-11-02 16:09:07 +01001519 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001520 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001521 const char *dsc; /**< description */
1522 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001523 const char *emsg; /**< error-message */
1524 const char *eapptag; /**< error-app-tag value */
1525 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1526};
1527
1528struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001529 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001530 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 +01001531 LY_DATA_TYPE basetype; /**< Base type of the type */
1532 uint32_t refcount; /**< reference counter for type sharing */
1533};
1534
1535struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001536 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001537 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 +01001538 LY_DATA_TYPE basetype; /**< Base type of the type */
1539 uint32_t refcount; /**< reference counter for type sharing */
1540 struct lysc_range *range; /**< Optional range limitation */
1541};
1542
1543struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001544 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001545 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 +01001546 LY_DATA_TYPE basetype; /**< Base type of the type */
1547 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001548 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001549 struct lysc_range *range; /**< Optional range limitation */
1550};
1551
1552struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001553 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001554 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 +01001555 LY_DATA_TYPE basetype; /**< Base type of the type */
1556 uint32_t refcount; /**< reference counter for type sharing */
1557 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001558 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001559};
1560
Radek Krejci693262f2019-04-29 15:23:20 +02001561struct lysc_type_bitenum_item {
1562 const char *name; /**< enumeration identifier */
1563 const char *dsc; /**< description */
1564 const char *ref; /**< reference */
1565 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci693262f2019-04-29 15:23:20 +02001566 union {
1567 int32_t value; /**< integer value associated with the enumeration */
1568 uint32_t position; /**< non-negative integer value associated with the bit */
1569 };
1570 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1571 values are allowed */
1572};
1573
Radek Krejci2167ee12018-11-02 16:09:07 +01001574struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001575 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001576 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 +01001577 LY_DATA_TYPE basetype; /**< Base type of the type */
1578 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001579 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1580};
1581
1582struct lysc_type_bits {
1583 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001584 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 +02001585 LY_DATA_TYPE basetype; /**< Base type of the type */
1586 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001587 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1588 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001589};
1590
1591struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001592 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001593 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 +01001594 LY_DATA_TYPE basetype; /**< Base type of the type */
1595 uint32_t refcount; /**< reference counter for type sharing */
Michal Vasko004d3152020-06-11 19:59:22 +02001596 struct lyxp_expr *path; /**< parsed target path, compiled path cannot be stored because of type sharing */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001597 struct lysc_prefix *prefixes; /**< resolved prefixes used in the path */
Michal Vaskoc0792ca2020-12-01 12:03:21 +01001598 const struct lys_module *cur_mod;/**< current module for the leafref (path) */
Radek Krejci412ddfa2018-11-23 11:44:11 +01001599 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001600 uint8_t require_instance; /**< require-instance flag */
1601};
1602
1603struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001604 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001605 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 +01001606 LY_DATA_TYPE basetype; /**< Base type of the type */
1607 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001608 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001609 mandatory (at least 1 item) */
1610};
1611
1612struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001613 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001614 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 +01001615 LY_DATA_TYPE basetype; /**< Base type of the type */
1616 uint32_t refcount; /**< reference counter for type sharing */
1617 uint8_t require_instance; /**< require-instance flag */
1618};
1619
Radek Krejci2167ee12018-11-02 16:09:07 +01001620struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001621 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001622 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 +01001623 LY_DATA_TYPE basetype; /**< Base type of the type */
1624 uint32_t refcount; /**< reference counter for type sharing */
1625 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1626};
1627
1628struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001629 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001630 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 +01001631 LY_DATA_TYPE basetype; /**< Base type of the type */
1632 uint32_t refcount; /**< reference counter for type sharing */
1633 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001634};
1635
Michal Vasko60ea6352020-06-29 13:39:39 +02001636/**
1637 * @brief Maximum number of hashes stored in a schema node.
1638 */
1639#define LYS_NODE_HASH_COUNT 4
1640
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001641/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001642 * @brief Compiled YANG data node
1643 */
1644struct lysc_node {
Radek Krejcide7a9c42021-03-10 13:13:06 +01001645 uint16_t nodetype; /**< [type of the node](@ref schemanodetypes) (mandatory) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001646 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001647 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001648 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001649 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1650 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1651 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1652 never NULL. If there is no sibling node, pointer points to the node
1653 itself. In case of the first node, this pointer points to the last
1654 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001655 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001656 const char *dsc; /**< description */
1657 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001658 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001659 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 +02001660};
1661
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001662struct lysc_node_action_inout {
1663 union {
1664 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1665 struct {
1666 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
1667 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1668 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1669 struct lys_module *module; /**< module structure */
Radek Krejci5960c312021-01-27 20:24:22 +01001670 struct lysc_node *parent;/**< parent node (NULL in case of top level node) */
Michal Vasko544e58a2021-01-28 14:33:41 +01001671 struct lysc_node *next; /**< next sibling node (output node for input, NULL for output) */
1672 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 +01001673 const char *name; /**< "input" or "output" */
1674 const char *dsc; /**< ALWAYS NULL, compatibility member with ::lysc_node */
1675 const char *ref; /**< ALWAYS NULL, compatibility member with ::lysc_node */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001676 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001677 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 +01001678 };
1679 };
1680
Radek Krejci9a3823e2021-01-27 20:26:46 +01001681 struct lysc_node *child; /**< first child node (linked list) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001682 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1683};
1684
1685struct lysc_node_action {
1686 union {
1687 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1688 struct {
1689 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
1690 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1691 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1692 struct lys_module *module; /**< module structure */
1693 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1694 struct lysc_node_action *next; /**< next sibling node (NULL if there is no one) */
1695 struct lysc_node_action *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1696 never NULL. If there is no sibling node, pointer points to the node
1697 itself. In case of the first node, this pointer points to the last
1698 node in the list. */
1699 const char *name; /**< action/RPC name (mandatory) */
1700 const char *dsc; /**< description */
1701 const char *ref; /**< reference */
1702 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001703 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 +01001704 };
1705 };
1706
Radek Krejci9a3823e2021-01-27 20:26:46 +01001707 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)),
1708 the action/RPC nodes do not contain the when statement on their own, but they can
1709 inherit it from the parent's uses. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001710 struct lysc_node_action_inout input; /**< RPC's/action's input */
1711 struct lysc_node_action_inout output; /**< RPC's/action's output */
1712
1713};
1714
1715struct lysc_node_notif {
1716 union {
1717 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1718 struct {
1719 uint16_t nodetype; /**< LYS_NOTIF */
1720 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1721 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1722 struct lys_module *module; /**< module structure */
1723 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1724 struct lysc_node_notif *next; /**< next sibling node (NULL if there is no one) */
1725 struct lysc_node_notif *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1726 never NULL. If there is no sibling node, pointer points to the node
1727 itself. In case of the first node, this pointer points to the last
1728 node in the list. */
1729 const char *name; /**< Notification name (mandatory) */
1730 const char *dsc; /**< description */
1731 const char *ref; /**< reference */
1732 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001733 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 +01001734 };
1735 };
1736
Radek Krejci9a3823e2021-01-27 20:26:46 +01001737 struct lysc_node *child; /**< first child node (linked list) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001738 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001739 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)),
1740 the notification nodes do not contain the when statement on their own, but they can
1741 inherit it from the parent's uses. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001742};
1743
1744struct lysc_node_container {
1745 union {
1746 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1747 struct {
1748 uint16_t nodetype; /**< LYS_CONTAINER */
1749 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1750 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1751 struct lys_module *module; /**< module structure */
1752 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1753 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1754 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1755 never NULL. If there is no sibling node, pointer points to the node
1756 itself. In case of the first node, this pointer points to the last
1757 node in the list. */
1758 const char *name; /**< node name (mandatory) */
1759 const char *dsc; /**< description */
1760 const char *ref; /**< reference */
1761 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001762 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 +01001763 };
1764 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001765
1766 struct lysc_node *child; /**< first child node (linked list) */
1767 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001768 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001769 struct lysc_node_action *actions;/**< first of actions nodes (linked list) */
1770 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001771};
1772
Radek Krejcia3045382018-11-22 14:30:31 +01001773struct lysc_node_case {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001774 union {
1775 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1776 struct {
1777 uint16_t nodetype; /**< LYS_CASE */
1778 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1779 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
1780 struct lys_module *module; /**< module structure */
1781 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1782 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1783 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejci056d0a82018-12-06 16:57:25 +01001784 never NULL. If there is no sibling node, pointer points to the node
1785 itself. In case of the first node, this pointer points to the last
1786 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001787 const char *name; /**< name of the case, including the implicit case */
1788 const char *dsc; /**< description */
1789 const char *ref; /**< reference */
1790 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001791 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 +01001792 };
1793 };
Radek Krejci056d0a82018-12-06 16:57:25 +01001794
Radek Krejcia3045382018-11-22 14:30:31 +01001795 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 +01001796 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001797 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcia3045382018-11-22 14:30:31 +01001798};
1799
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001800struct lysc_node_choice {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001801 union {
1802 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1803 struct {
1804 uint16_t nodetype; /**< LYS_CHOICE */
1805 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1806 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
1807 struct lys_module *module; /**< module structure */
1808 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1809 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1810 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001811 never NULL. If there is no sibling node, pointer points to the node
1812 itself. In case of the first node, this pointer points to the last
1813 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001814 const char *name; /**< node name (mandatory) */
1815 const char *dsc; /**< description */
1816 const char *ref; /**< reference */
1817 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001818 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 +01001819 };
1820 };
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001821
Radek Krejcia9026eb2018-12-12 16:04:47 +01001822 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1823 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1824 case is simple. */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001825 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001826 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001827};
1828
1829struct lysc_node_leaf {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001830 union {
1831 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1832 struct {
1833 uint16_t nodetype; /**< LYS_LEAF */
1834 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1835 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1836 struct lys_module *module; /**< module structure */
1837 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1838 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1839 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001840 never NULL. If there is no sibling node, pointer points to the node
1841 itself. In case of the first node, this pointer points to the last
1842 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001843 const char *name; /**< node name (mandatory) */
1844 const char *dsc; /**< description */
1845 const char *ref; /**< reference */
1846 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001847 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 +01001848 };
1849 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001850
1851 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001852 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001853 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001854
Radek Krejci4f28eda2018-11-12 11:46:16 +01001855 const char *units; /**< units of the leaf's type */
Michal Vasko33876022021-04-27 16:42:24 +02001856 struct lyd_value *dflt; /**< default value, use ::lyd_value_get_canonical() to get the canonical string */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001857};
1858
1859struct lysc_node_leaflist {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001860 union {
1861 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1862 struct {
1863 uint16_t nodetype; /**< LYS_LEAFLIST */
1864 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1865 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1866 struct lys_module *module; /**< module structure */
1867 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1868 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1869 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001870 never NULL. If there is no sibling node, pointer points to the node
1871 itself. In case of the first node, this pointer points to the last
1872 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001873 const char *name; /**< node name (mandatory) */
1874 const char *dsc; /**< description */
1875 const char *ref; /**< reference */
1876 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001877 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 +01001878 };
1879 };
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001880
1881 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001882 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001883 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1884
Radek Krejci0e5d8382018-11-28 16:37:53 +01001885 const char *units; /**< units of the leaf's type */
Michal Vasko33876022021-04-27 16:42:24 +02001886 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values, use
1887 ::lyd_value_get_canonical() to get the canonical strings */
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001888
Radek Krejci0e5d8382018-11-28 16:37:53 +01001889 uint32_t min; /**< min-elements constraint */
1890 uint32_t max; /**< max-elements constraint */
1891
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001892};
1893
1894struct lysc_node_list {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001895 union {
1896 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1897 struct {
1898 uint16_t nodetype; /**< LYS_LIST */
1899 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1900 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1901 struct lys_module *module; /**< module structure */
1902 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1903 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1904 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001905 never NULL. If there is no sibling node, pointer points to the node
1906 itself. In case of the first node, this pointer points to the last
1907 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001908 const char *name; /**< node name (mandatory) */
1909 const char *dsc; /**< description */
1910 const char *ref; /**< reference */
1911 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001912 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 +01001913 };
1914 };
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001915
1916 struct lysc_node *child; /**< first child node (linked list) */
1917 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001918 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001919 struct lysc_node_action *actions;/**< first of actions nodes (linked list) */
1920 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001921
Radek Krejci2a9fc652021-01-22 17:44:34 +01001922 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 +01001923 uint32_t min; /**< min-elements constraint */
1924 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001925};
1926
1927struct lysc_node_anydata {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001928 union {
1929 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
1930 struct {
1931 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1932 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1933 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1934 struct lys_module *module; /**< module structure */
1935 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1936 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1937 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001938 never NULL. If there is no sibling node, pointer points to the node
1939 itself. In case of the first node, this pointer points to the last
1940 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001941 const char *name; /**< node name (mandatory) */
1942 const char *dsc; /**< description */
1943 const char *ref; /**< reference */
1944 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001945 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 +01001946 };
1947 };
Radek Krejci9800fb82018-12-13 14:26:23 +01001948
1949 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001950 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001951};
1952
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001953/**
1954 * @brief Compiled YANG schema tree structure representing YANG module.
1955 *
1956 * Semantically validated YANG schema tree for data tree parsing.
1957 * Contains only the necessary information for the data validation.
1958 */
1959struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001960 struct lys_module *mod; /**< covering module structure */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001961
Radek Krejci2a408df2018-10-29 16:32:26 +01001962 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001963 struct lysc_node_action *rpcs; /**< first of actions nodes (linked list) */
1964 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001965 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001966};
1967
1968/**
Radek Krejci490a5462020-11-05 08:44:42 +01001969 * @brief Examine whether a node is user-ordered list or leaf-list.
1970 *
1971 * @param[in] lysc_node Schema node to examine.
1972 * @return Boolean value whether the @p node is user-ordered or not.
1973 */
1974#define lysc_is_userordered(lysc_node) \
1975 ((!lysc_node || !(lysc_node->nodetype & (LYS_LEAFLIST | LYS_LIST)) || !(lysc_node->flags & LYS_ORDBY_USER)) ? 0 : 1)
1976
1977/**
1978 * @brief Examine whether a node is a list's key.
1979 *
1980 * @param[in] lysc_node Schema node to examine.
1981 * @return Boolean value whether the @p node is a key or not.
1982 */
1983#define lysc_is_key(lysc_node) \
Michal Vaskobce7ee32021-02-04 11:05:25 +01001984 ((!lysc_node || (lysc_node->nodetype != LYS_LEAF) || !(lysc_node->flags & LYS_KEY)) ? 0 : 1)
Radek Krejci490a5462020-11-05 08:44:42 +01001985
1986/**
Michal Vasko5c123b02020-12-04 14:34:04 +01001987 * @brief Examine whether a node is a non-presence container.
1988 *
1989 * @param[in] lysc_node Schema node to examine.
1990 * @return Boolean value whether the @p node is a NP container or not.
1991 */
1992#define lysc_is_np_cont(lysc_node) \
Michal Vaskobce7ee32021-02-04 11:05:25 +01001993 ((!lysc_node || (lysc_node->nodetype != LYS_CONTAINER) || (lysc_node->flags & LYS_PRESENCE)) ? 0 : 1)
1994
1995/**
Michal Vaskoe78faec2021-04-08 17:24:43 +02001996 * @brief Examine whether a node is a key-less list or a non-configuration leaf-list.
Michal Vaskobce7ee32021-02-04 11:05:25 +01001997 *
1998 * @param[in] lysc_node Schema node to examine.
1999 * @return Boolean value whether the @p node is a list with duplicate instances allowed.
2000 */
2001#define lysc_is_dup_inst_list(lysc_node) \
2002 ((lysc_node && (((lysc_node->nodetype == LYS_LIST) && (lysc_node->flags & LYS_KEYLESS)) || \
Michal Vaskoe78faec2021-04-08 17:24:43 +02002003 ((lysc_node->nodetype == LYS_LEAFLIST) && !(lysc_node->flags & LYS_CONFIG_W)))) ? 1 : 0)
Michal Vasko5c123b02020-12-04 14:34:04 +01002004
2005/**
Michal Vaskod5cfa6e2020-11-23 16:56:08 +01002006 * @brief Check whether the schema node data instance existence depends on any when conditions.
2007 * This node and any direct parent choice and case schema nodes are also examined for when conditions.
2008 *
2009 * Be careful, this function is not recursive and checks only conditions that apply to this node directly.
2010 * Meaning if there are any conditions associated with any data parent instance of @p node, they are not returned.
2011 *
2012 * @param[in] node Schema node to examine.
2013 * @return When condition associated with the node data instance, NULL if there is none.
2014 */
2015const struct lysc_when *lysc_has_when(const struct lysc_node *node);
2016
2017/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01002018 * @brief Get the groupings linked list of the given (parsed) schema node.
Radek Krejci53ea6152018-12-13 15:21:15 +01002019 * Decides the node's type and in case it has a groupings array, returns it.
2020 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01002021 * @return The node's groupings linked list if any, NULL otherwise.
Radek Krejci53ea6152018-12-13 15:21:15 +01002022 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01002023const struct lysp_node_grp *lysp_node_groupings(const struct lysp_node *node);
Radek Krejci53ea6152018-12-13 15:21:15 +01002024
2025/**
Radek Krejci056d0a82018-12-06 16:57:25 +01002026 * @brief Get the typedefs sized array of the given (parsed) schema node.
2027 * Decides the node's type and in case it has a typedefs array, returns it.
2028 * @param[in] node Node to examine.
2029 * @return The node's typedefs sized array if any, NULL otherwise.
2030 */
2031const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
2032
2033/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01002034 * @brief Get the actions/RPCs linked list of the given (parsed) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01002035 * Decides the node's type and in case it has a actions/RPCs array, returns it.
2036 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01002037 * @return The node's actions/RPCs linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01002038 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01002039const struct lysp_node_action *lysp_node_actions(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002040
2041/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01002042 * @brief Get the Notifications linked list of the given (parsed) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01002043 * Decides the node's type and in case it has a Notifications array, returns it.
2044 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01002045 * @return The node's Notifications linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01002046 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01002047const struct lysp_node_notif *lysp_node_notifs(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002048
2049/**
2050 * @brief Get the children linked list of the given (parsed) schema node.
2051 * Decides the node's type and in case it has a children list, returns it.
2052 * @param[in] node Node to examine.
2053 * @return The node's children linked list if any, NULL otherwise.
2054 */
Michal Vasko544e58a2021-01-28 14:33:41 +01002055const struct lysp_node *lysp_node_child(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002056
2057/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01002058 * @brief Get the actions/RPCs linked list of the given (compiled) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01002059 * Decides the node's type and in case it has a actions/RPCs array, returns it.
2060 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01002061 * @return The node's actions/RPCs linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01002062 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01002063const struct lysc_node_action *lysc_node_actions(const struct lysc_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002064
2065/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01002066 * @brief Get the Notifications linked list of the given (compiled) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01002067 * Decides the node's type and in case it has a Notifications array, returns it.
2068 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01002069 * @return The node's Notifications linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01002070 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01002071const struct lysc_node_notif *lysc_node_notifs(const struct lysc_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01002072
2073/**
2074 * @brief Get the children linked list of the given (compiled) schema node.
Michal Vasko2a668712020-10-21 11:48:09 +02002075 *
Michal Vasko544e58a2021-01-28 14:33:41 +01002076 * Note that ::LYS_CHOICE has only ::LYS_CASE children.
2077 * Also, ::LYS_RPC and ::LYS_ACTION have the first child ::LYS_INPUT, its sibling is ::LYS_OUTPUT.
2078 *
Michal Vasko2a668712020-10-21 11:48:09 +02002079 * @param[in] node Node to examine.
Michal Vasko2a668712020-10-21 11:48:09 +02002080 * @return Children linked list if any,
2081 * @return NULL otherwise.
2082 */
Michal Vasko544e58a2021-01-28 14:33:41 +01002083const struct lysc_node *lysc_node_child(const struct lysc_node *node);
Michal Vasko2a668712020-10-21 11:48:09 +02002084
2085/**
Radek Krejci9a3823e2021-01-27 20:26:46 +01002086 * @brief Get the must statements list if present in the @p node
2087 *
2088 * @param[in] node Node to examine.
2089 * @return Pointer to the list of must restrictions ([sized array](@ref sizedarrays))
2090 * @return NULL if there is no must statement in the node, no matter if it is not even allowed or just present
2091 */
2092struct lysc_must *lysc_node_musts(const struct lysc_node *node);
2093
2094/**
2095 * @brief Get the when statements list if present in the @p node
2096 *
2097 * @param[in] node Node to examine.
2098 * @return Pointer to the list of pointers to when statements ([sized array](@ref sizedarrays))
2099 * @return NULL if there is no when statement in the node, no matter if it is not even allowed or just present
2100 */
2101struct lysc_when **lysc_node_when(const struct lysc_node *node);
2102
2103/**
Michal Vaskof1ab44f2020-10-22 08:58:32 +02002104 * @brief Callback to be called for every schema node in a DFS traversal.
2105 *
2106 * @param[in] node Current node.
2107 * @param[in] data Arbitrary user data.
2108 * @param[out] dfs_continue Set to true if the current subtree should be skipped and continue with siblings instead.
2109 * @return LY_SUCCESS on success,
2110 * @return LY_ERR value to terminate DFS and return this value.
2111 */
Michal Vasko8f07dfe2021-03-02 16:10:24 +01002112typedef LY_ERR (*lysc_dfs_clb)(struct lysc_node *node, void *data, ly_bool *dfs_continue);
Michal Vaskof1ab44f2020-10-22 08:58:32 +02002113
2114/**
2115 * @brief DFS traversal of all the schema nodes in a (sub)tree including any actions and nested notifications.
2116 *
2117 * Node with children, actions, and notifications is traversed in this order:
2118 * 1) each child subtree;
2119 * 2) each action subtree;
2120 * 3) each notification subtree.
2121 *
2122 * For algorithm illustration or traversal with actions and notifications skipped, see ::LYSC_TREE_DFS_BEGIN.
2123 *
2124 * @param[in] root Schema root to fully traverse.
2125 * @param[in] dfs_clb Callback to call for each node.
2126 * @param[in] data Arbitrary user data passed to @p dfs_clb.
2127 * @return LY_SUCCESS on success,
2128 * @return LY_ERR value returned by @p dfs_clb.
2129 */
2130LY_ERR lysc_tree_dfs_full(const struct lysc_node *root, lysc_dfs_clb dfs_clb, void *data);
2131
2132/**
2133 * @brief DFS traversal of all the schema nodes in a module including RPCs and notifications.
2134 *
2135 * For more details, see ::lysc_tree_dfs_full().
2136 *
2137 * @param[in] mod Module to fully traverse.
2138 * @param[in] dfs_clb Callback to call for each node.
2139 * @param[in] data Arbitrary user data passed to @p dfs_clb.
2140 * @return LY_SUCCESS on success,
2141 * @return LY_ERR value returned by @p dfs_clb.
2142 */
2143LY_ERR lysc_module_dfs_full(const struct lys_module *mod, lysc_dfs_clb dfs_clb, void *data);
2144
2145/**
Radek Krejci151a5b72018-10-19 14:21:44 +02002146 * @brief Get how the if-feature statement currently evaluates.
2147 *
2148 * @param[in] iff Compiled if-feature statement to evaluate.
Michal Vasko28d78432020-05-26 13:10:53 +02002149 * @return LY_SUCCESS if the statement evaluates to true,
2150 * @return LY_ENOT if it evaluates to false,
2151 * @return LY_ERR on error.
Radek Krejci151a5b72018-10-19 14:21:44 +02002152 */
Michal Vasko28d78432020-05-26 13:10:53 +02002153LY_ERR lysc_iffeature_value(const struct lysc_iffeature *iff);
Radek Krejci151a5b72018-10-19 14:21:44 +02002154
2155/**
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002156 * @brief Get the next feature in the module or submodules.
Radek Krejci151a5b72018-10-19 14:21:44 +02002157 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002158 * @param[in] last Last returned feature.
2159 * @param[in] pmod Parsed module and submodoules whose features to iterate over.
2160 * @param[in,out] idx Submodule index, set to 0 on first call.
2161 * @return Next found feature, NULL if the last has already been returned.
Radek Krejci151a5b72018-10-19 14:21:44 +02002162 */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002163struct lysp_feature *lysp_feature_next(const struct lysp_feature *last, const struct lysp_module *pmod, uint32_t *idx);
Radek Krejci151a5b72018-10-19 14:21:44 +02002164
Radek Krejcibed13942020-10-19 16:06:28 +02002165/**
Radek Krejcidab4f0b2021-03-29 14:07:18 +02002166 * @brief Get pointer to the storage of the specified substatement in the given extension instance.
2167 *
2168 * The function simplifies access into the ::lysc_ext_instance.substmts sized array.
2169 *
2170 * @param[in] ext Compiled extension instance to process.
2171 * @param[in] substmt Extension substatement to search for.
2172 * @param[out] instance_p Pointer where the storage of the @p substmt will be provided. The specific type returned depends
2173 * on the @p substmt and can be found in the documentation of each ::ly_stmt value. Also note that some of the substatements
2174 * (::lysc_node based or flags) can share the storage with other substatements. In case the pointer is NULL, still the return
2175 * code can be used to at least know if the substatement is allowed for the extension.
2176 * @param[out] cardinality_p Pointer to provide allowed cardinality of the substatements in the extension. Note that in some
2177 * cases, the type of the storage depends also on the cardinality of the substatement.
2178 * @return LY_SUCCESS if the @p substmt found.
2179 * @return LY_ENOT in case the @p ext is not able to store (does not allow) the specified @p substmt.
2180 */
2181LY_ERR lysc_ext_substmt(const struct lysc_ext_instance *ext, enum ly_stmt substmt,
2182 void **instance_p, enum ly_stmt_cardinality *cardinality_p);
2183
2184/**
Radek Krejcibed13942020-10-19 16:06:28 +02002185 * @defgroup findxpathoptions Atomize XPath options
2186 * Options to modify behavior of ::lys_find_xpath() and ::lys_find_xpath_atoms() searching for schema nodes in schema tree.
2187 * @{
2188 */
Michal Vaskocdad7122020-11-09 21:04:44 +01002189#define LYS_FIND_XP_SCHEMA 0x08 /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */
2190#define LYS_FIND_XP_OUTPUT 0x10 /**< Search RPC/action output nodes instead of input ones. */
Radek Krejci576f8fa2020-10-26 21:23:58 +01002191/** @} findxpathoptions */
Michal Vasko072de482020-08-05 13:27:21 +02002192
Radek Krejci151a5b72018-10-19 14:21:44 +02002193/**
Michal Vasko40308e72020-10-20 16:38:40 +02002194 * @brief Get all the schema nodes that are required for @p xpath to be evaluated (atoms).
Michal Vasko519fd602020-05-26 12:17:39 +02002195 *
Michal Vasko26512682021-01-11 11:35:40 +01002196 * @param[in] ctx libyang context to use. May be NULL if @p ctx_node is set.
2197 * @param[in] ctx_node XPath schema context node. Use NULL for the root node.
Radek Krejci8df109d2021-04-23 12:19:08 +02002198 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_VALUE_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02002199 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko519fd602020-05-26 12:17:39 +02002200 * @param[out] set Set of found atoms (schema nodes).
2201 * @return LY_SUCCESS on success, @p set is returned.
Michal Vasko40308e72020-10-20 16:38:40 +02002202 * @return LY_ERR value on error.
Michal Vasko519fd602020-05-26 12:17:39 +02002203 */
Michal Vasko26512682021-01-11 11:35:40 +01002204LY_ERR lys_find_xpath_atoms(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *xpath,
2205 uint32_t options, struct ly_set **set);
Michal Vasko519fd602020-05-26 12:17:39 +02002206
Michal Vasko072de482020-08-05 13:27:21 +02002207/**
Michal Vasko40308e72020-10-20 16:38:40 +02002208 * @brief Get all the schema nodes that are required for @p expr to be evaluated (atoms).
Michal Vasko072de482020-08-05 13:27:21 +02002209 *
Michal Vasko26512682021-01-11 11:35:40 +01002210 * @param[in] ctx_node XPath schema context node. Use NULL for the root node.
Michal Vasko40308e72020-10-20 16:38:40 +02002211 * @param[in] cur_mod Current module for the expression (where it was "instantiated").
2212 * @param[in] expr Parsed expression to use.
2213 * @param[in] prefixes Sized array of compiled prefixes.
2214 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
2215 * @param[out] set Set of found atoms (schema nodes).
2216 * @return LY_SUCCESS on success, @p set is returned.
2217 * @return LY_ERR value on error.
2218 */
2219LY_ERR lys_find_expr_atoms(const struct lysc_node *ctx_node, const struct lys_module *cur_mod,
2220 const struct lyxp_expr *expr, const struct lysc_prefix *prefixes, uint32_t options, struct ly_set **set);
2221
2222/**
2223 * @brief Evaluate an @p xpath expression on schema nodes.
2224 *
Michal Vasko26512682021-01-11 11:35:40 +01002225 * @param[in] ctx libyang context to use for absolute @p xpath. May be NULL if @p ctx_node is set.
2226 * @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 +02002227 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_VALUE_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02002228 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko072de482020-08-05 13:27:21 +02002229 * @param[out] set Set of found schema nodes.
2230 * @return LY_SUCCESS on success, @p set is returned.
2231 * @return LY_ERR value if an error occurred.
2232 */
Michal Vasko26512682021-01-11 11:35:40 +01002233LY_ERR lys_find_xpath(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *xpath, uint32_t options,
2234 struct ly_set **set);
Michal Vasko519fd602020-05-26 12:17:39 +02002235
2236/**
Radek Krejcibc5644c2020-10-27 14:53:17 +01002237 * @brief Get all the schema nodes that are required for @p path to be evaluated (atoms).
2238 *
2239 * @param[in] path Compiled path to use.
2240 * @param[out] set Set of found atoms (schema nodes).
2241 * @return LY_SUCCESS on success, @p set is returned.
2242 * @return LY_ERR value on error.
2243 */
2244LY_ERR lys_find_lypath_atoms(const struct ly_path *path, struct ly_set **set);
2245
2246/**
2247 * @brief Get all the schema nodes that are required for @p path to be evaluated (atoms).
2248 *
Michal Vasko26512682021-01-11 11:35:40 +01002249 * @param[in] ctx libyang context to use for absolute @p path. May be NULL if @p ctx_node is set.
2250 * @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 +01002251 * @param[in] path JSON path to examine.
2252 * @param[in] output Search operation output instead of input.
2253 * @param[out] set Set of found atoms (schema nodes).
2254 * @return LY_ERR value on error.
2255 */
2256LY_ERR lys_find_path_atoms(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *path, ly_bool output,
2257 struct ly_set **set);
2258
2259/**
2260 * @brief Get a schema node based on the given data path (JSON format, see @ref howtoXPath).
2261 *
Michal Vasko26512682021-01-11 11:35:40 +01002262 * @param[in] ctx libyang context to use for absolute @p path. May be NULL if @p ctx_node is set.
2263 * @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 +01002264 * @param[in] path JSON path of the node to get.
2265 * @param[in] output Search operation output instead of input.
2266 * @return Found schema node or NULL.
2267 */
2268const struct lysc_node *lys_find_path(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *path,
2269 ly_bool output);
2270
2271/**
Michal Vasko03ff5a72019-09-11 13:49:33 +02002272 * @brief Types of the different schema paths.
2273 */
2274typedef enum {
Michal Vasko65de0402020-08-03 16:34:19 +02002275 LYSC_PATH_LOG, /**< Descriptive path format used in log messages */
2276 LYSC_PATH_DATA /**< Similar to ::LYSC_PATH_LOG except that schema-only nodes (choice, case) are skipped */
Michal Vasko03ff5a72019-09-11 13:49:33 +02002277} LYSC_PATH_TYPE;
2278
2279/**
Radek Krejci327de162019-06-14 12:52:07 +02002280 * @brief Generate path of the given node in the requested format.
2281 *
2282 * @param[in] node Schema path of this node will be generated.
2283 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02002284 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
2285 * If NULL, memory for the complete path is allocated.
2286 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02002287 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02002288 * 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 +02002289 */
Michal Vasko03ff5a72019-09-11 13:49:33 +02002290char *lysc_path(const struct lysc_node *node, LYSC_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02002291
2292/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002293 * @brief Available YANG schema tree structures representing YANG module.
2294 */
2295struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002296 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
2297 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01002298 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002299 const char *ns; /**< namespace of the module (module - mandatory) */
2300 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
2301 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
2302 const char *org; /**< party/company responsible for the module */
2303 const char *contact; /**< contact information for the module */
2304 const char *dsc; /**< description of the module */
2305 const char *ref; /**< cross-reference for the module */
2306
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002307 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01002308 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
2309 Available only for implemented modules. */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002310
Radek Krejci80d281e2020-09-14 17:42:54 +02002311 struct lysc_ident *identities; /**< List of compiled identities of the module ([sized array](@ref sizedarrays))
2312 Identities are outside the compiled tree to allow their linkage to the identities from
2313 the implemented modules. This avoids problems when the module became implemented in
2314 future (no matter if implicitly via augment/deviate or explicitly via
2315 ::lys_set_implemented()). Note that if the module is not implemented (compiled), the
2316 identities cannot be instantiated in data (in identityrefs). */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002317
2318 struct lys_module **augmented_by;/**< List of modules that augment this module ([sized array](@ref sizedarrays)) */
2319 struct lys_module **deviated_by; /**< List of modules that deviate this module ([sized array](@ref sizedarrays)) */
2320
Michal Vasko89b5c072020-10-06 13:52:44 +02002321 ly_bool implemented; /**< flag if the module is implemented, not just imported */
Michal Vasko01db7de2021-04-16 12:23:30 +02002322 ly_bool to_compile; /**< flag marking a module that was changed but not (re)compiled, see
2323 ::LY_CTX_EXPLICIT_COMPILE. */
Radek Krejci95710c92019-02-11 15:49:55 +01002324 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002325 1 - the latest revision in searchdirs was not searched yet and this is the
2326 latest revision in the current context
2327 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002328};
2329
Radek Krejci151a5b72018-10-19 14:21:44 +02002330/**
Michal Vasko82c31e62020-07-17 15:30:40 +02002331 * @brief Get the current real status of the specified feature in the module.
2332 *
2333 * If the feature is enabled, but some of its if-features are false, the feature is considered
2334 * disabled.
Radek Krejci151a5b72018-10-19 14:21:44 +02002335 *
2336 * @param[in] module Module where the feature is defined.
2337 * @param[in] feature Name of the feature to inspect.
Michal Vasko82c31e62020-07-17 15:30:40 +02002338 * @return LY_SUCCESS if the feature is enabled,
2339 * @return LY_ENOT if the feature is disabled,
2340 * @return LY_ENOTFOUND if the feature was not found.
Radek Krejci151a5b72018-10-19 14:21:44 +02002341 */
Michal Vasko82c31e62020-07-17 15:30:40 +02002342LY_ERR lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02002343
2344/**
Radek Krejcia3045382018-11-22 14:30:31 +01002345 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
2346 * be from an augment.
2347 *
Radek Krejci8678fa42020-08-18 16:07:28 +02002348 * ::lys_getnext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
Radek Krejcia3045382018-11-22 14:30:31 +01002349 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
2350 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
2351 * \p parent and \p module parameters.
2352 *
2353 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
2354 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
2355 * all the schema nodes are iteratively returned.
2356 *
2357 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
2358 * @param[in] parent Parent of the subtree where the function starts processing.
2359 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
2360 * module must be specified.
2361 * @param[in] options [ORed options](@ref sgetnextflags).
2362 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
2363 */
2364const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002365 const struct lysc_module *module, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002366
2367/**
Radek Krejci035dacf2021-02-12 18:25:53 +01002368 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree.
Radek Krejci8678fa42020-08-18 16:07:28 +02002369 *
Radek Krejci035dacf2021-02-12 18:25:53 +01002370 * In contrast to ::lys_getnext(), ::lys_getnext_ext() is limited by the given @p ext instance as a schema tree root.
2371 * If the extension does not contain any schema node, NULL is returned. If the @p parent is provided, the functionality
2372 * is completely the same as ::lys_getnext().
2373 *
2374 * ::lys_getnext_ext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
2375 * and function starts returning i) the first \p parent's child or ii) the first top level element of the given @p ext
2376 * instance. Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
2377 * \p parent and \p ext parameters.
2378 *
2379 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
2380 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
2381 * all the schema nodes are iteratively returned.
2382 *
2383 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
2384 * @param[in] parent Parent of the subtree where the function starts processing.
2385 * @param[in] ext The extension instance to provide a separate schema tree. To consider the top level elements in the tree,
2386 * the \p parent must be NULL. anyway, at least one of @p parent and @p ext parameters must be specified.
2387 * @param[in] options [ORed options](@ref sgetnextflags).
2388 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
2389 */
2390const struct lysc_node *lys_getnext_ext(const struct lysc_node *last, const struct lysc_node *parent,
2391 const struct lysc_ext_instance *ext, uint32_t options);
2392
2393/**
2394 * @defgroup sgetnextflags Options for ::lys_getnext() and ::lys_getnext_ext().
2395 *
2396 * Various options setting behavior of ::lys_getnext() and ::lys_getnext_ext().
Radek Krejci8678fa42020-08-18 16:07:28 +02002397 *
Radek Krejcia3045382018-11-22 14:30:31 +01002398 * @{
2399 */
Radek Krejci8678fa42020-08-18 16:07:28 +02002400#define LYS_GETNEXT_WITHCHOICE 0x01 /**< ::lys_getnext() option to allow returning #LYS_CHOICE nodes instead of looking into them */
2401#define LYS_GETNEXT_NOCHOICE 0x02 /**< ::lys_getnext() option to ignore (kind of conditional) nodes within choice node */
2402#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 +01002403#define LYS_GETNEXT_INTONPCONT 0x08 /**< ::lys_getnext() option to look into non-presence container, instead of returning container itself */
2404#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 +01002405 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01002406/** @} sgetnextflags */
2407
2408/**
2409 * @brief Get child node according to the specified criteria.
2410 *
2411 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
2412 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
2413 * @param[in] name Name of the node to find.
2414 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
2415 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
2416 * Used as a bitmask, so multiple nodetypes can be specified.
2417 * @param[in] options [ORed options](@ref sgetnextflags).
2418 * @return Found node if any.
2419 */
Michal Vaskoe444f752020-02-10 12:20:06 +01002420const struct lysc_node *lys_find_child(const struct lysc_node *parent, const struct lys_module *module,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002421 const char *name, size_t name_len, uint16_t nodetype, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002422
2423/**
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002424 * @brief Make the specific module implemented.
2425 *
Michal Vaskoe8988e92021-01-25 11:26:29 +01002426 * If the module is already implemented but with a different set of features, the whole context is recompiled.
2427 *
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002428 * @param[in] mod Module to make implemented. It is not an error
2429 * to provide already implemented module, it just does nothing.
Michal Vaskoe8988e92021-01-25 11:26:29 +01002430 * @param[in] features Optional array specifying the enabled features terminated with NULL overriding any previous
2431 * feature setting. The feature string '*' enables all the features and array of length 1 with only the terminating
2432 * NULL explicitly disables all the features. In case the parameter is NULL, the features are untouched - left disabled
2433 * 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 +01002434 * @return LY_SUCCESS on success.
2435 * @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 +01002436 * @return LY_ERR on other errors during module compilation.
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002437 */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01002438LY_ERR lys_set_implemented(struct lys_module *mod, const char **features);
Radek Krejcia3045382018-11-22 14:30:31 +01002439
Radek Krejci084289f2019-07-09 17:35:30 +02002440/**
Radek Krejci0935f412019-08-20 16:15:18 +02002441 * @brief Stringify schema nodetype.
Michal Vaskod43d71a2020-08-07 14:54:58 +02002442 *
Radek Krejci0935f412019-08-20 16:15:18 +02002443 * @param[in] nodetype Nodetype to stringify.
2444 * @return Constant string with the name of the node's type.
2445 */
2446const char *lys_nodetype2str(uint16_t nodetype);
2447
Michal Vaskod43d71a2020-08-07 14:54:58 +02002448/**
2449 * @brief Getter for original XPath expression from a parsed expression.
2450 *
2451 * @param[in] path Parsed expression.
2452 * @return Original string expression.
2453 */
2454const char *lyxp_get_expr(const struct lyxp_expr *path);
2455
Radek Krejci2ff0d572020-05-21 15:27:28 +02002456/** @} schematree */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002457
Radek Krejci70853c52018-10-15 14:46:16 +02002458#ifdef __cplusplus
2459}
2460#endif
2461
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002462#endif /* LY_TREE_SCHEMA_H_ */