blob: 8a6b2a3648159b4faff984012e4b89c724c9b247 [file] [log] [blame]
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001/**
2 * @file tree_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
Michal Vaskoedb0fa52022-10-04 10:36:00 +02004 * @author Michal Vasko <mvasko@cesnet.cz>
Radek Krejci5aeea3a2018-09-05 13:29:36 +02005 * @brief libyang representation of YANG schema trees.
6 *
Michal Vaskoedb0fa52022-10-04 10:36:00 +02007 * Copyright (c) 2015 - 2022 CESNET, z.s.p.o.
Radek Krejci5aeea3a2018-09-05 13:29:36 +02008 *
9 * This source code is licensed under BSD 3-Clause License (the "License").
10 * You may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * https://opensource.org/licenses/BSD-3-Clause
14 */
15
16#ifndef LY_TREE_SCHEMA_H_
17#define LY_TREE_SCHEMA_H_
18
Radek Krejci54579462019-04-30 12:47:06 +020019#define PCRE2_CODE_UNIT_WIDTH 8
20
21#include <pcre2.h>
Radek Krejci535ea9f2020-05-29 16:01:05 +020022
Radek Krejci5aeea3a2018-09-05 13:29:36 +020023#include <stdint.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020024#include <stdio.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020025
Michal Vaskobabf0bd2021-08-31 14:55:39 +020026#include "config.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020027#include "log.h"
28#include "tree.h"
Radek Krejcice8c1592018-10-29 15:35:51 +010029
Radek Krejci70853c52018-10-15 14:46:16 +020030#ifdef __cplusplus
31extern "C" {
32#endif
33
Radek Krejcica376bd2020-06-11 16:04:06 +020034struct ly_ctx;
Radek Krejci47fab892020-11-05 17:02:41 +010035struct ly_path;
Radek Krejcica376bd2020-06-11 16:04:06 +020036struct ly_set;
Radek Krejci47fab892020-11-05 17:02:41 +010037struct lys_module;
38struct lysc_node;
39struct lyxp_expr;
Radek Krejcica376bd2020-06-11 16:04:06 +020040
Radek Krejci5aeea3a2018-09-05 13:29:36 +020041/**
Radek Krejci8678fa42020-08-18 16:07:28 +020042 * @page howtoSchema YANG Modules
43 *
44 * To be able to work with YANG data instances, libyang has to represent YANG data models. All the processed modules are stored
45 * in libyang [context](@ref howtoContext) and loaded using [parser functions](@ref howtoSchemaParsers). It means, that there is
46 * no way to create/change YANG module programmatically. However, all the YANG model definitions are available and can be examined
47 * through the C structures. All the context's modules together form YANG Schema for the data being instantiated.
48 *
49 * Any YANG module is represented as ::lys_module. In fact, the module is represented in two different formats. As ::lys_module.parsed,
50 * there is a parsed schema reflecting the source YANG module. It is exactly what is read from the input. This format is good for
51 * converting from one format to another (YANG to YIN and vice versa), but it is not very useful for validating/manipulating YANG
52 * data. Therefore, there is ::lys_module.compiled storing the compiled YANG module. It is based on the parsed module, but all the
53 * 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
54 * `uses` or `type` references. This split also means, that the YANG module is fully validated after compilation of the parsed
55 * representation of the module. YANG submodules are available only in the parsed representation. When a submodule is compiled, it
56 * is fully integrated into its main module.
57 *
58 * The context can contain even modules without the compiled representation. Such modules are still useful as imports of other
59 * modules. The grouping or typedef definition can be even compiled into the importing modules. This is actually the main
60 * difference between the imported and implemented modules in the libyang context. The implemented modules are compiled while the
61 * imported modules are only parsed.
62 *
Radek Krejcib100b192020-10-26 08:37:45 +010063 * By default, the module is implemented (and compiled) in case it is explicitly loaded or referenced in another module as
64 * target of leafref, augment or deviation. This behavior can be changed via context options ::LY_CTX_ALL_IMPLEMENTED, when
65 * all the modules in the context are marked as implemented (note the problem with multiple revisions of a single module),
66 * or by ::LY_CTX_REF_IMPLEMENTED option, extending the set of references making the module implemented by when, must and
67 * default statements.
Radek Krejci8678fa42020-08-18 16:07:28 +020068 *
69 * All modules with deviation definition are always marked as implemented. The imported (not implemented) module can be set implemented by ::lys_set_implemented(). But
70 * the implemented module cannot be changed back to just imported module. Note also that only one revision of a specific module
71 * can be implemented in a single context. The imported modules are used only as a
72 * source of definitions for types and groupings for uses statements. The data in such modules are ignored - caller
73 * is not allowed to create the data (including instantiating identities) defined in the model via data parsers,
74 * the default nodes are not added into any data tree and mandatory nodes are not checked in the data trees.
75 *
Michal Vasko14ed9cd2021-01-28 14:16:25 +010076 * 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 +020077 * function, variable, ...) used by a caller application unless ::LY_CTX_SET_PRIV_PARSED is set, in that case
78 * the ::lysc_node.priv pointers are used by libyang.
Radek Krejci8678fa42020-08-18 16:07:28 +020079 * Note that the object is not freed by libyang when the context is being destroyed. So the caller is responsible
80 * 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 +020081 * appropriate schema nodes where the object was previously set. Also ::lysc_tree_dfs_full() can be useful to manage
82 * the private data.
Radek Krejci8678fa42020-08-18 16:07:28 +020083 *
84 * Despite all the schema structures and their members are available as part of the libyang API and callers can use
85 * it to navigate through the schema tree structure or to obtain various information, we recommend to use the following
86 * macros for the specific actions.
87 * - ::LYSC_TREE_DFS_BEGIN and ::LYSC_TREE_DFS_END to traverse the schema tree (depth-first).
88 * - ::LY_LIST_FOR and ::LY_ARRAY_FOR as described on @ref howtoStructures page.
89 *
90 * Further information about modules handling can be found on the following pages:
91 * - @subpage howtoSchemaParsers
92 * - @subpage howtoSchemaFeatures
93 * - @subpage howtoPlugins
94 * - @subpage howtoSchemaPrinters
95 *
96 * \note There are many functions to access information from the schema trees. Details are available in
97 * the [Schema Tree module](@ref schematree).
98 *
99 * For information about difference between implemented and imported modules, see the
100 * [context description](@ref howtoContext).
101 *
102 * Functions List (not assigned to above subsections)
103 * --------------------------------------------------
104 * - ::lys_getnext()
105 * - ::lys_nodetype2str()
106 * - ::lys_set_implemented()
Radek Krejci8678fa42020-08-18 16:07:28 +0200107 *
Michal Vaskod5cfa6e2020-11-23 16:56:08 +0100108 * - ::lysc_has_when()
Michal Vaskoef53c812021-10-13 10:21:03 +0200109 * - ::lysc_owner_module()
Michal Vaskod5cfa6e2020-11-23 16:56:08 +0100110 *
Michal Vasko544e58a2021-01-28 14:33:41 +0100111 * - ::lysc_node_child()
Radek Krejci8678fa42020-08-18 16:07:28 +0200112 * - ::lysc_node_actions()
113 * - ::lysc_node_notifs()
114 *
Michal Vasko544e58a2021-01-28 14:33:41 +0100115 * - ::lysp_node_child()
Radek Krejci8678fa42020-08-18 16:07:28 +0200116 * - ::lysp_node_actions()
117 * - ::lysp_node_notifs()
118 * - ::lysp_node_groupings()
119 * - ::lysp_node_typedefs()
120 */
121
122/**
123 * @page howtoSchemaFeatures YANG Features
124 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100125 * YANG feature statement is an important part of the language which can significantly affect the meaning of the schemas.
126 * Modifying features may have similar effects as loading/removing schema from the context so it is limited to context
127 * preparation period before working with data. YANG features, respectively their use in if-feature
128 * statements, are evaluated as part of schema compilation so a feature-specific compiled schema tree is generated
129 * as a result.
Radek Krejci8678fa42020-08-18 16:07:28 +0200130 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100131 * To enable any features, they must currently be specified when implementing a new schema with ::lys_parse() or
132 * ::ly_ctx_load_module(). To later examine what the status of a feature is, check its ::LYS_FENABLED flag or
133 * 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 +0200134 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100135 * To iterate over all features of a particular YANG module, use ::lysp_feature_next().
Radek Krejci8678fa42020-08-18 16:07:28 +0200136 *
137 * Note, that the feature's state can affect some of the output formats (e.g. Tree format).
138 *
139 * Functions List
140 * --------------
Radek Krejci8678fa42020-08-18 16:07:28 +0200141 * - ::lys_feature_value()
Radek Krejci8678fa42020-08-18 16:07:28 +0200142 * - ::lysc_iffeature_value()
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100143 * - ::lysp_feature_next()
Radek Krejci8678fa42020-08-18 16:07:28 +0200144 */
145
146/**
Radek Krejci2ff0d572020-05-21 15:27:28 +0200147 * @ingroup trees
Radek Krejci8678fa42020-08-18 16:07:28 +0200148 * @defgroup schematree Schema Tree
Radek Krejci2ff0d572020-05-21 15:27:28 +0200149 * @{
150 *
151 * Data structures and functions to manipulate and access schema tree.
152 */
153
Michal Vasko64246d82020-08-19 12:35:00 +0200154/* *INDENT-OFF* */
155
Radek Krejci2ff0d572020-05-21 15:27:28 +0200156/**
Michal Vasko208a04a2020-10-21 15:17:12 +0200157 * @brief Macro to iterate via all elements in a schema (sub)tree including input and output.
158 * Note that __actions__ and __notifications__ of traversed nodes __are ignored__! To traverse
159 * on all the nodes including those, use ::lysc_tree_dfs_full() instead.
160 *
161 * 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 +0200162 *
163 * The function follows deep-first search algorithm:
164 * <pre>
165 * 1
166 * / \
167 * 2 4
168 * / / \
169 * 3 5 6
170 * </pre>
171 *
172 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
Radek Krejci2a9fc652021-01-22 17:44:34 +0100173 * START can be any of the lysc_node* types (including lysc_node_action and lysc_node_notif),
Radek Krejci0935f412019-08-20 16:15:18 +0200174 * ELEM variable must be of the struct lysc_node* type.
175 *
176 * To skip a particular subtree, instead of the continue statement, set LYSC_TREE_DFS_continue
177 * variable to non-zero value.
178 *
179 * Use with opening curly bracket '{' after the macro.
180 *
181 * @param START Pointer to the starting element processed first.
182 * @param ELEM Iterator intended for use in the block.
183 */
184#define LYSC_TREE_DFS_BEGIN(START, ELEM) \
Radek Krejci857189e2020-09-01 13:26:36 +0200185 { ly_bool LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
Michal Vasko14ed9cd2021-01-28 14:16:25 +0100186 for ((ELEM) = (LYSC_TREE_DFS_next) = (struct lysc_node *)(START); \
Radek Krejci0935f412019-08-20 16:15:18 +0200187 (ELEM); \
188 (ELEM) = (LYSC_TREE_DFS_next), LYSC_TREE_DFS_continue = 0)
189
190/**
191 * @brief Macro to iterate via all elements in a (sub)tree. This is the closing part
192 * to the #LYSC_TREE_DFS_BEGIN - they always have to be used together.
193 *
194 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
Radek Krejci2a9fc652021-01-22 17:44:34 +0100195 * 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 +0200196 * ELEM variable must be pointer to the lysc_node type.
197 *
198 * Use with closing curly bracket '}' after the macro.
199 *
200 * @param START Pointer to the starting element processed first.
201 * @param ELEM Iterator intended for use in the block.
202 */
Radek Krejci0935f412019-08-20 16:15:18 +0200203#define LYSC_TREE_DFS_END(START, ELEM) \
204 /* select element for the next run - children first */ \
205 if (LYSC_TREE_DFS_continue) { \
206 (LYSC_TREE_DFS_next) = NULL; \
207 } else { \
Michal Vasko544e58a2021-01-28 14:33:41 +0100208 (LYSC_TREE_DFS_next) = (struct lysc_node *)lysc_node_child(ELEM); \
Michal Vasko208a04a2020-10-21 15:17:12 +0200209 } \
Radek Krejci0935f412019-08-20 16:15:18 +0200210 if (!(LYSC_TREE_DFS_next)) { \
Michal Vasko208a04a2020-10-21 15:17:12 +0200211 /* no children, try siblings */ \
212 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
Radek Krejci0935f412019-08-20 16:15:18 +0200213 } \
214 while (!(LYSC_TREE_DFS_next)) { \
215 /* parent is already processed, go to its sibling */ \
Radek Krejci7d95fbb2021-01-26 17:33:13 +0100216 (ELEM) = (ELEM)->parent; \
Michal Vasko208a04a2020-10-21 15:17:12 +0200217 _LYSC_TREE_DFS_NEXT(START, ELEM, LYSC_TREE_DFS_next); \
218 } }
219
220/**
221 * @brief Helper macro for #LYSC_TREE_DFS_END, should not be used directly!
222 */
223#define _LYSC_TREE_DFS_NEXT(START, ELEM, NEXT) \
224 if ((ELEM) == (struct lysc_node *)(START)) { \
225 /* we are done, no next element to process */ \
226 break; \
227 } \
Michal Vasko544e58a2021-01-28 14:33:41 +0100228 (NEXT) = (ELEM)->next;
Radek Krejci0935f412019-08-20 16:15:18 +0200229
Michal Vasko64246d82020-08-19 12:35:00 +0200230/* *INDENT-ON* */
231
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200232#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
233
Radek Krejcide7a9c42021-03-10 13:13:06 +0100234/**
235 * @defgroup schemanodetypes Schema Node Types
236 * Values of the ::lysp_node.nodetype and ::lysc_node.nodetype members.
237 * @{
238 */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200239#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
240#define LYS_CONTAINER 0x0001 /**< container statement node */
241#define LYS_CHOICE 0x0002 /**< choice statement node */
242#define LYS_LEAF 0x0004 /**< leaf statement node */
243#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
244#define LYS_LIST 0x0010 /**< list statement node */
245#define LYS_ANYXML 0x0020 /**< anyxml statement node */
246#define LYS_ANYDATA 0x0060 /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
247#define LYS_CASE 0x0080 /**< case statement node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200248
Michal Vasko7f45cf22020-10-01 12:49:44 +0200249#define LYS_RPC 0x0100 /**< RPC statement node */
250#define LYS_ACTION 0x0200 /**< action statement node */
251#define LYS_NOTIF 0x0400 /**< notification statement node */
Radek Krejcie7b95092019-05-15 11:03:07 +0200252
Michal Vasko7f45cf22020-10-01 12:49:44 +0200253#define LYS_USES 0x0800 /**< uses statement node */
254#define LYS_INPUT 0x1000 /**< RPC/action input node */
255#define LYS_OUTPUT 0x2000 /**< RPC/action output node */
256#define LYS_GROUPING 0x4000
257#define LYS_AUGMENT 0x8000
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100258
Radek Krejcif13b87b2020-12-01 22:02:17 +0100259#define LYS_NODETYPE_MASK 0xffff /**< Mask for nodetypes, the value is limited for 16 bits */
Radek Krejcide7a9c42021-03-10 13:13:06 +0100260/** @} schemanodetypes */
Radek Krejcif13b87b2020-12-01 22:02:17 +0100261
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200262/**
263 * @brief YANG import-stmt
264 */
265struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200266 struct lys_module *module; /**< pointer to the imported module
267 (mandatory, but resolved when the referring module is completely parsed) */
268 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200269 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200270 const char *dsc; /**< description */
271 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200272 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100273 uint16_t flags; /**< LYS_INTERNAL value (@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200274 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
275};
276
277/**
278 * @brief YANG include-stmt
279 */
280struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100281 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200282 (mandatory, but resolved when the referring module is completely parsed) */
283 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200284 const char *dsc; /**< description */
285 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200286 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200287 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
Radek Krejci771928a2021-01-19 13:42:36 +0100288 ly_bool injected; /**< flag to mark includes copied into main module from submodules,
289 only for backward compatibility with YANG 1.0, which does not require the
290 main module to include all submodules. */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200291};
292
293/**
294 * @brief YANG extension-stmt
295 */
296struct lysp_ext {
297 const char *name; /**< extension name */
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100298 const char *argname; /**< argument name, NULL if not specified */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200299 const char *dsc; /**< description statement */
300 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200301 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcif56e2a42019-09-09 14:15:25 +0200302 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */
Michal Vasko5fe75f12020-03-02 13:52:37 +0100303
Radek Krejci720d2612021-03-03 19:44:22 +0100304 struct lysc_ext *compiled; /**< pointer to the compiled extension definition.
305 The extension definition is compiled only if there is compiled extension instance,
306 otherwise this pointer remains NULL. The compiled extension definition is shared
307 among all extension instances. */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200308};
309
310/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200311 * @brief YANG feature-stmt
312 */
313struct lysp_feature {
314 const char *name; /**< feature name (mandatory) */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100315 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
316 struct lysc_iffeature *iffeatures_c; /**< compiled if-features */
317 struct lysp_feature **depfeatures; /**< list of pointers to other features depending on this one
318 ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200319 const char *dsc; /**< description statement */
320 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200321 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100322 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values and
323 LYS_FENABLED are allowed */
324};
325
326/**
327 * @brief Compiled YANG if-feature-stmt
328 */
329struct lysc_iffeature {
330 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
331 struct lysp_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200332};
333
334/**
Michal Vasko7f45cf22020-10-01 12:49:44 +0200335 * @brief Qualified name (optional prefix followed by an identifier).
336 */
337struct lysp_qname {
338 const char *str; /**< qualified name string */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200339 const struct lysp_module *mod; /**< module to resolve any prefixes found in the string, it must be
Michal Vasko7f45cf22020-10-01 12:49:44 +0200340 stored explicitly because of deviations/refines */
341};
342
343/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200344 * @brief YANG identity-stmt
345 */
346struct lysp_ident {
347 const char *name; /**< identity name (mandatory), including possible prefix */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200348 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200349 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200350 const char *dsc; /**< description statement */
351 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200352 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200353 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
354};
355
Michal Vasko71e64ca2018-09-07 16:30:29 +0200356/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200357 * @brief Covers restrictions: range, length, pattern, must
358 */
359struct lysp_restr {
Radek Krejcif13b87b2020-12-01 22:02:17 +0100360#define LYSP_RESTR_PATTERN_ACK 0x06
361#define LYSP_RESTR_PATTERN_NACK 0x15
Michal Vasko7f45cf22020-10-01 12:49:44 +0200362 struct lysp_qname arg; /**< The restriction expression/value (mandatory);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200363 in case of pattern restriction, the first byte has a special meaning:
364 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
365 const char *emsg; /**< error-message */
366 const char *eapptag; /**< error-app-tag value */
367 const char *dsc; /**< description */
368 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200369 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200370};
371
372/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200373 * @brief YANG revision-stmt
374 */
375struct lysp_revision {
Radek Krejcicb3e6472021-01-06 08:19:01 +0100376 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200377 const char *dsc; /**< description statement */
378 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200379 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200380};
381
382/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200383 * @brief Enumeration/Bit value definition
384 */
385struct lysp_type_enum {
386 const char *name; /**< name (mandatory) */
387 const char *dsc; /**< description statement */
388 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200389 int64_t value; /**< enum's value or bit's position */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200390 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200391 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200392 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
393 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200394};
395
396/**
397 * @brief YANG type-stmt
398 *
399 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
400 */
401struct lysp_type {
402 const char *name; /**< name of the type (mandatory) */
403 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
404 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200405 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
406 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
407 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Michal Vasko004d3152020-06-11 19:59:22 +0200408 struct lyxp_expr *path; /**< parsed path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200409 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200410 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
411 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200412
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200413 const struct lysp_module *pmod; /**< (sub)module where the type is defined (needed for deviations) */
Michal Vasko00e8e652022-06-08 10:09:18 +0200414 struct lysc_type *compiled; /**< pointer to the compiled custom type, not used for built-in types */
Radek Krejci2167ee12018-11-02 16:09:07 +0100415
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200416 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
417 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100418 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200419};
420
421/**
422 * @brief YANG typedef-stmt
423 */
424struct lysp_tpdf {
425 const char *name; /**< name of the newly defined type (mandatory) */
426 const char *units; /**< units of the newly defined type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200427 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 +0200428 const char *dsc; /**< description statement */
429 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200430 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200431 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100432 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200433};
434
435/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200436 * @brief YANG when-stmt
437 */
438struct lysp_when {
439 const char *cond; /**< specified condition (mandatory) */
440 const char *dsc; /**< description statement */
441 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200442 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200443};
444
445/**
446 * @brief YANG refine-stmt
447 */
448struct lysp_refine {
449 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
450 const char *dsc; /**< description statement */
451 const char *ref; /**< reference statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200452 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200453 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200454 const char *presence; /**< presence description */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200455 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200456 uint32_t min; /**< min-elements constraint */
457 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200458 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200459 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
460};
461
462/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200463 * @ingroup schematree
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200464 * @defgroup deviatetypes Deviate types
Radek Krejci8678fa42020-08-18 16:07:28 +0200465 *
466 * Type of the deviate operation (used as ::lysp_deviate.mod)
467 *
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200468 * @{
469 */
470#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
471#define LYS_DEV_ADD 2 /**< deviate type add */
472#define LYS_DEV_DELETE 3 /**< deviate type delete */
473#define LYS_DEV_REPLACE 4 /**< deviate type replace */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200474/** @} deviatetypes */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200475
476/**
477 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
478 */
479struct lysp_deviate {
480 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
481 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200482 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200483};
484
485struct lysp_deviate_add {
486 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
487 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200488 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200489 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200490 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200491 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
492 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200493 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
494 uint32_t min; /**< min-elements constraint */
495 uint32_t max; /**< max-elements constraint, 0 means unbounded */
496};
497
498struct lysp_deviate_del {
499 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
500 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200501 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200502 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200503 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200504 struct lysp_qname *uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
505 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200506};
507
508struct lysp_deviate_rpl {
509 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
510 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200511 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200512 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200513 const char *units; /**< units of the values */
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200514 struct lysp_qname dflt; /**< default value */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200515 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
516 uint32_t min; /**< min-elements constraint */
517 uint32_t max; /**< max-elements constraint, 0 means unbounded */
518};
519
520struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200521 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200522 const char *dsc; /**< description statement */
523 const char *ref; /**< reference statement */
Michal Vasko22df3f02020-08-24 13:29:22 +0200524 struct lysp_deviate *deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200525 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200526};
527
Radek Krejci4f28eda2018-11-12 11:46:16 +0100528/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100529 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200530 * @defgroup spnodeflags Parsed schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100531 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200532 * Various flags for parsed schema nodes (used as ::lysp_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100533 *
534 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
535 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200536 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Michal Vasko0b50f6b2022-10-05 15:07:55 +0200537 * 4 - leaflist 9 - rpc 14 - extension 19 - augment 24 - extension instance
Radek Krejci4f28eda2018-11-12 11:46:16 +0100538 * 5 - list 10 - input 15 - typedef 20 - deviate
539 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200540 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
541 * 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
Michal Vasko0b50f6b2022-10-05 15:07:55 +0200542 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
543 * 1 LYS_CONFIG_W |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | | |
544 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| | |
545 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
546 * 2 LYS_CONFIG_R |x|x|x|x|x|x| | | | | | | | | | | |x| |x| | | | |
547 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| | |
548 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
549 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | | |
550 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| | |
551 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
552 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | | |
553 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| | |
554 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
555 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | | |
556 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| | |
557 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
558 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | | |
559 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| | |
560 * LYS_FENABLED | | | | | | | | | | | |x| | | | | | | | | | | | |
561 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
562 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | | |
563 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | | |
564 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| | |
565 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
566 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | | |
567 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | | |
568 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| | |
569 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
570 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | | |
571 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| | |
572 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x| |
573 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
574 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | | |
575 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| | |
576 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | | |
577 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x| |
578 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
579 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | | |
580 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | | |
581 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x| |
582 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
583 * 12 LYS_YIN_ARGUMENT | | | | | | | | | | | | | | | | | | | | | | |x| |
584 * LYS_EXT_PARSED_AUGMENT | | | | | | | | | | | | | | | | | | | | | | | |x|
585 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
586 * 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|x|
587 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100588 *
589 */
590
591/**
Radek Krejci4f28eda2018-11-12 11:46:16 +0100592 * @ingroup snodeflags
Radek Krejci8678fa42020-08-18 16:07:28 +0200593 * @defgroup scnodeflags Compiled schema nodes flags
Radek Krejci4f28eda2018-11-12 11:46:16 +0100594 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200595 * Various flags for compiled schema nodes (used as ::lysc_node.flags).
Radek Krejci4f28eda2018-11-12 11:46:16 +0100596 *
Radek Krejci61e042e2019-09-10 15:53:09 +0200597 * 1 - container 6 - anydata/anyxml 11 - identity
598 * 2 - choice 7 - case 12 - extension
599 * 3 - leaf 8 - notification 13 - bitenum
Michal Vasko03ff5a72019-09-11 13:49:33 +0200600 * 4 - leaflist 9 - rpc/action 14 - when
Michal Vaskoecd62de2019-11-13 12:35:11 +0100601 * 5 - list 10 - feature
Radek Krejci4f28eda2018-11-12 11:46:16 +0100602 *
Michal Vaskoecd62de2019-11-13 12:35:11 +0100603 * 1 1 1 1 1
604 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
605 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskod09b7622021-01-26 09:14:13 +0100606 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100607 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskod09b7622021-01-26 09:14:13 +0100608 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100609 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskof4fa90d2021-11-11 15:05:19 +0100610 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x|x|x|x|x|x|
Michal Vaskoecd62de2019-11-13 12:35:11 +0100611 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskof4fa90d2021-11-11 15:05:19 +0100612 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x|x|x|x|x|x|
Michal Vaskoecd62de2019-11-13 12:35:11 +0100613 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Michal Vaskof4fa90d2021-11-11 15:05:19 +0100614 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x|x|x|x|x|x|
Michal Vaskoecd62de2019-11-13 12:35:11 +0100615 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
616 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
617 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
618 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
619 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | |
620 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
621 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
622 * LYS_PRESENCE |x| | | | | | | | | | | | | |
623 * LYS_UNIQUE | | |x| | | | | | | | | | | |
624 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
625 * 9 LYS_KEY | | |x| | | | | | | | | | | |
Michal Vaskof4fa90d2021-11-11 15:05:19 +0100626 * LYS_DISABLED | | | | | | | | | | | | |x| |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100627 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
628 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
Michal Vaskod1e53b92021-01-28 13:11:06 +0100629 * LYS_IS_ENUM | | | | | | | | | | | | |x| |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100630 * LYS_KEYLESS | | | | |x| | | | | | | | | |
631 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
632 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
633 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
634 * 12 LYS_SET_CONFIG |x|x|x|x|x|x| | | | | | | | |
Michal Vaskod1e53b92021-01-28 13:11:06 +0100635 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
636 * 13 LYS_IS_INPUT |x|x|x|x|x|x|x| | | | | | | |
637 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
638 * 14 LYS_IS_OUTPUT |x|x|x|x|x|x|x| | | | | | | |
639 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
640 * 15 LYS_IS_NOTIF |x|x|x|x|x|x|x| | | | | | | |
Michal Vaskoecd62de2019-11-13 12:35:11 +0100641 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100642 *
643 */
644
645/**
646 * @defgroup snodeflags Schema nodes flags
Radek Krejci8678fa42020-08-18 16:07:28 +0200647 *
648 * Various flags for schema nodes ([parsed](@ref spnodeflags) as well as [compiled](@ref scnodeflags)).
649 *
Radek Krejci4f28eda2018-11-12 11:46:16 +0100650 * @{
651 */
Michal Vaskod1e53b92021-01-28 13:11:06 +0100652#define LYS_CONFIG_W 0x01 /**< config true; */
653#define LYS_CONFIG_R 0x02 /**< config false; */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200654#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100655#define LYS_STATUS_CURR 0x04 /**< status current; */
656#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
657#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
658#define LYS_STATUS_MASK 0x1C /**< mask for status value */
659#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100660 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
661 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
662 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
663 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100664#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
665 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
666 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100667#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Michal Vaskoc118ae22020-08-06 14:51:09 +0200668#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, but it is not only for explicit presence
669 containers, but also for NP containers with some meaning, applicable only to
670 ::lysc_node_container */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100671#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 +0100672#define LYS_KEY 0x0100 /**< flag for leafs being a key of a list, applicable only to ::lysc_node_leaf */
673#define LYS_KEYLESS 0x0200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Michal Vaskof4fa90d2021-11-11 15:05:19 +0100674#define LYS_DISABLED 0x0100 /**< internal flag for a disabled statement, used only for bits/enums */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100675#define LYS_FENABLED 0x20 /**< feature enabled flag, applicable only to ::lysp_feature. */
Michal Vaskoe78faec2021-04-08 17:24:43 +0200676#define LYS_ORDBY_SYSTEM 0x80 /**< ordered-by system configuration lists, applicable only to
677 ::lysc_node_leaflist/::lysp_node_leaflist and ::lysc_node_list/::lysp_node_list */
678#define LYS_ORDBY_USER 0x40 /**< ordered-by user configuration lists, applicable only to
679 ::lysc_node_leaflist/::lysp_node_leaflist and ::lysc_node_list/::lysp_node_list;
680 is always set for state leaf-lists, and key-less lists */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100681#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
682#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
Michal Vaskod1e53b92021-01-28 13:11:06 +0100683#define LYS_YINELEM_FALSE 0x0100 /**< yin-element false for extension's argument */
684#define LYS_YINELEM_MASK 0x0180 /**< mask for yin-element value */
685#define LYS_USED_GRP 0x0400 /**< internal flag for validating not-instantiated groupings
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200686 (resp. do not validate again the instantiated groupings). */
Michal Vaskod1e53b92021-01-28 13:11:06 +0100687#define LYS_SET_VALUE 0x0200 /**< value attribute is set */
688#define LYS_SET_MIN 0x0200 /**< min attribute is set */
689#define LYS_SET_MAX 0x0400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100690
691#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
692#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
693#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
694#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
695#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
696#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
697#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
698#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
699#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
700#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100701#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 +0100702 cases of choice. This information is important for refines, since it is prohibited to make leafs
703 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100704 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
705 between own default or the default values taken from the type. */
706#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 +0100707#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 +0100708
Michal Vaskod1e53b92021-01-28 13:11:06 +0100709#define LYS_SINGLEQUOTED 0x0100 /**< flag for single-quoted argument of an extension instance's substatement, only when the source is YANG */
710#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 +0200711
Michal Vaskod1e53b92021-01-28 13:11:06 +0100712#define LYS_YIN_ATTR 0x0400 /**< flag to identify YIN attribute parsed as extension's substatement, only when the source is YIN */
713#define LYS_YIN_ARGUMENT 0x0800 /**< flag to identify statement representing extension's argument, only when the source is YIN */
Michal Vasko0b50f6b2022-10-05 15:07:55 +0200714#define LYS_EXT_PARSED_AUGMENT 0x0800 /**< flag to mark an extension instance whose parsed nodes are augment nodes */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200715
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100716#define LYS_INTERNAL 0x1000 /**< flag to identify internal parsed statements that should not be printed */
717
Michal Vaskod1e53b92021-01-28 13:11:06 +0100718#define LYS_IS_ENUM 0x0200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
719
720#define LYS_IS_INPUT 0x1000 /**< flag for nodes that are in the subtree of an input statement */
721
722#define LYS_IS_OUTPUT 0x2000 /**< flag for nodes that are in the subtree of an output statement */
723
724#define LYS_IS_NOTIF 0x4000 /**< flag for nodes that are in the subtree of a notification statement */
Radek Krejci693262f2019-04-29 15:23:20 +0200725
Radek Krejcife909632019-02-12 15:34:42 +0100726#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci2ff0d572020-05-21 15:27:28 +0200727/** @} snodeflags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200728
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200729/**
730 * @brief Generic YANG data node
731 */
732struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100733 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejcide7a9c42021-03-10 13:13:06 +0100734 uint16_t nodetype; /**< [type of the node](@ref schemanodetypes) (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200735 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100736 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200737 const char *name; /**< node name (mandatory) */
738 const char *dsc; /**< description statement */
739 const char *ref; /**< reference statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200740 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)),
741 must be qname because of refines */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200742 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200743};
744
745/**
746 * @brief Extension structure of the lysp_node for YANG container
747 */
748struct lysp_node_container {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100749 union {
750 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +0200751
Radek Krejci2a9fc652021-01-22 17:44:34 +0100752 struct {
753 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
754 uint16_t nodetype; /**< LYS_CONTAINER */
755 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
756 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
757 const char *name; /**< node name (mandatory) */
758 const char *dsc; /**< description statement */
759 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100760 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
761 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
762 };
763 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200764
765 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200766 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +0100767 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200768 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200769 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100770 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200771 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100772 struct lysp_node_action *actions;/**< list of actions (linked list) */
773 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200774};
775
776struct lysp_node_leaf {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100777 union {
778 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +0200779
Radek Krejci2a9fc652021-01-22 17:44:34 +0100780 struct {
781 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
782 uint16_t nodetype; /**< LYS_LEAF */
783 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
784 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
785 const char *name; /**< node name (mandatory) */
786 const char *dsc; /**< description statement */
787 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100788 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
789 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
790 };
791 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200792
793 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200794 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +0100795 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200796 struct lysp_type type; /**< type of the leaf node (mandatory) */
797 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200798 struct lysp_qname dflt; /**< default value, it may or may not be a qualified name */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200799};
800
801struct lysp_node_leaflist {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100802 union {
803 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +0200804
Radek Krejci2a9fc652021-01-22 17:44:34 +0100805 struct {
806 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
807 uint16_t nodetype; /**< LYS_LEAFLIST */
808 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
809 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
810 const char *name; /**< node name (mandatory) */
811 const char *dsc; /**< description statement */
812 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100813 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
814 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
815 };
816 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200817
818 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200819 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +0100820 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200821 struct lysp_type type; /**< type of the leaf node (mandatory) */
822 const char *units; /**< units of the leaf's type */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200823 struct lysp_qname *dflts; /**< list of default values ([sized array](@ref sizedarrays)), they may or
824 may not be qualified names */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200825 uint32_t min; /**< min-elements constraint */
826 uint32_t max; /**< max-elements constraint, 0 means unbounded */
827};
828
829struct lysp_node_list {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100830 union {
831 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +0200832
Radek Krejci2a9fc652021-01-22 17:44:34 +0100833 struct {
834 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
835 uint16_t nodetype; /**< LYS_LIST */
836 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
837 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
838 const char *name; /**< node name (mandatory) */
839 const char *dsc; /**< description statement */
840 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100841 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
842 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
843 };
844 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200845
846 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200847 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +0100848 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200849 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200850 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100851 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200852 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100853 struct lysp_node_action *actions;/**< list of actions (linked list) */
854 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200855 struct lysp_qname *uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200856 uint32_t min; /**< min-elements constraint */
857 uint32_t max; /**< max-elements constraint, 0 means unbounded */
858};
859
860struct lysp_node_choice {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100861 union {
862 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +0200863
Radek Krejci2a9fc652021-01-22 17:44:34 +0100864 struct {
865 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
866 uint16_t nodetype; /**< LYS_CHOICE */
867 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
868 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
869 const char *name; /**< node name (mandatory) */
870 const char *dsc; /**< description statement */
871 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100872 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
873 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
874 };
875 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200876
877 /* choice */
878 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +0100879 struct lysp_when *when; /**< when statement */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200880 struct lysp_qname dflt; /**< default case */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200881};
882
883struct lysp_node_case {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100884 union {
885 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +0200886
Radek Krejci2a9fc652021-01-22 17:44:34 +0100887 struct {
888 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
889 uint16_t nodetype; /**< LYS_CASE */
890 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
891 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
892 const char *name; /**< node name (mandatory) */
893 const char *dsc; /**< description statement */
894 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100895 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
896 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
897 };
898 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200899
900 /* case */
901 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +0100902 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200903};
904
905struct lysp_node_anydata {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100906 union {
907 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +0200908
Radek Krejci2a9fc652021-01-22 17:44:34 +0100909 struct {
910 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
911 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
912 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
913 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
914 const char *name; /**< node name (mandatory) */
915 const char *dsc; /**< description statement */
916 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100917 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
918 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
919 };
920 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200921
922 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200923 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +0100924 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200925};
926
927struct lysp_node_uses {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100928 union {
929 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +0200930
Radek Krejci2a9fc652021-01-22 17:44:34 +0100931 struct {
932 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
933 uint16_t nodetype; /**< LYS_USES */
934 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
935 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
936 const char *name; /**< grouping name reference (mandatory) */
937 const char *dsc; /**< description statement */
938 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100939 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
940 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
941 };
942 }; /**< common part corresponding to ::lysp_node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200943
944 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200945 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100946 struct lysp_node_augment *augments; /**< list of augments (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +0100947 struct lysp_when *when; /**< when statement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200948};
949
950/**
951 * @brief YANG input-stmt and output-stmt
952 */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100953struct lysp_node_action_inout {
954 union {
955 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +0200956
Radek Krejci2a9fc652021-01-22 17:44:34 +0100957 struct {
958 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
959 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
960 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
961 struct lysp_node *next; /**< NULL */
962 const char *name; /**< empty string */
963 const char *dsc; /**< ALWAYS NULL, compatibility member with ::lysp_node */
964 const char *ref; /**< ALWAYS NULL, compatibility member with ::lysp_node */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100965 struct lysp_qname *iffeatures; /**< ALWAYS NULL, compatibility member with ::lysp_node */
966 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
967 };
968 }; /**< common part corresponding to ::lysp_node */
969
970 /* inout */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200971 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
972 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100973 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci01180ac2021-01-27 08:48:22 +0100974 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200975};
976
977/**
978 * @brief YANG rpc-stmt and action-stmt
979 */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100980struct lysp_node_action {
981 union {
982 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +0200983
Radek Krejci2a9fc652021-01-22 17:44:34 +0100984 struct {
985 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
986 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
987 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
988 struct lysp_node_action *next; /**< pointer to the next action (NULL if there is no one) */
989 const char *name; /**< grouping name reference (mandatory) */
990 const char *dsc; /**< description statement */
991 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100992 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
993 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
994 };
995 }; /**< common part corresponding to ::lysp_node */
Michal Vasko7f45cf22020-10-01 12:49:44 +0200996
997 /* action */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100998 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
999 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
1000
1001 struct lysp_node_action_inout input; /**< RPC's/Action's input */
1002 struct lysp_node_action_inout output; /**< RPC's/Action's output */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001003};
1004
1005/**
1006 * @brief YANG notification-stmt
1007 */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001008struct lysp_node_notif {
1009 union {
1010 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001011
Radek Krejci2a9fc652021-01-22 17:44:34 +01001012 struct {
1013 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
1014 uint16_t nodetype; /**< LYS_NOTIF */
1015 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1016 struct lysp_node_notif *next; /**< pointer to the next notification (NULL if there is no one) */
1017 const char *name; /**< grouping name reference (mandatory) */
1018 const char *dsc; /**< description statement */
1019 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001020 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1021 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1022 };
1023 }; /**< common part corresponding to ::lysp_node */
Michal Vasko7f45cf22020-10-01 12:49:44 +02001024
1025 /* notif */
1026 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001027 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1028 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci01180ac2021-01-27 08:48:22 +01001029 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001030};
1031
1032/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001033 * @brief YANG grouping-stmt
1034 */
1035struct lysp_node_grp {
1036 union {
1037 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001038
Radek Krejci2a9fc652021-01-22 17:44:34 +01001039 struct {
1040 struct lysp_node *parent;/**< parent node (NULL if this is a top-level grouping) */
1041 uint16_t nodetype; /**< LYS_GROUPING */
1042 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1043 struct lysp_node_grp *next; /**< pointer to the next grouping (NULL if there is no one) */
1044 const char *name; /**< grouping name (mandatory) */
1045 const char *dsc; /**< description statement */
1046 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001047 struct lysp_qname *iffeatures; /**< ALWAYS NULL, compatibility member with ::lysp_node */
1048 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1049 };
1050 }; /**< common part corresponding to ::lysp_node */
1051
1052 /* grp */
1053 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
1054 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci01180ac2021-01-27 08:48:22 +01001055 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001056 struct lysp_node_action *actions; /**< list of actions (linked list) */
1057 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
1058};
1059
1060/**
1061 * @brief YANG uses-augment-stmt and augment-stmt (compatible with struct lysp_node )
1062 */
1063struct lysp_node_augment {
1064 union {
1065 struct lysp_node node; /**< implicit cast for the members compatible with ::lysp_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001066
Radek Krejci2a9fc652021-01-22 17:44:34 +01001067 struct {
1068 struct lysp_node *parent;/**< parent node (NULL if this is a top-level augment) */
1069 uint16_t nodetype; /**< LYS_AUGMENT */
1070 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
1071 struct lysp_node_augment *next; /**< pointer to the next augment (NULL if there is no one) */
1072 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
1073 const char *dsc; /**< description statement */
1074 const char *ref; /**< reference statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001075 struct lysp_qname *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1076 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1077 };
1078 }; /**< common part corresponding to ::lysp_node */
1079
1080 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001081 struct lysp_when *when; /**< when statement */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001082 struct lysp_node_action *actions;/**< list of actions (linked list) */
1083 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
1084};
1085
1086/**
Radek Krejcif0fceb62018-09-05 14:58:45 +02001087 * @brief supported YANG schema version values
1088 */
1089typedef enum LYS_VERSION {
1090 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
Radek Krejci96e48da2020-09-04 13:18:06 +02001091 LYS_VERSION_1_0 = 1, /**< YANG 1 (1.0) */
Radek Krejcif0fceb62018-09-05 14:58:45 +02001092 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
1093} LYS_VERSION;
1094
1095/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001096 * @brief Printable YANG schema tree structure representing YANG module.
1097 *
1098 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
1099 */
1100struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001101 struct lys_module *mod; /**< covering module structure */
1102
Radek Krejcib7db73a2018-10-24 14:18:40 +02001103 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1104 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001105 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1106 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001107 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1108 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1109 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1110 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001111 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001112 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001113 struct lysp_node_augment *augments; /**< list of augments (linked list) */
1114 struct lysp_node_action *rpcs; /**< list of RPCs (linked list) */
1115 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001116 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001117 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001118
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001119 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001120 uint8_t parsing : 1; /**< flag for circular check */
1121 uint8_t is_submod : 1; /**< always 0 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001122};
1123
1124struct lysp_submodule {
Michal Vaskoc3781c32020-10-06 14:04:08 +02001125 struct lys_module *mod; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001126
1127 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
1128 in the list is always the last (newest) revision of the module */
1129 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
1130 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
1131 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
1132 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
1133 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1134 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001135 struct lysp_node_grp *groupings; /**< list of groupings (linked list) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001136 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001137 struct lysp_node_augment *augments; /**< list of augments (linked list) */
1138 struct lysp_node_action *rpcs; /**< list of RPCs (linked list) */
1139 struct lysp_node_notif *notifs; /**< list of notifications (linked list) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001140 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001141 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001142
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001143 uint8_t version; /**< yang-version (LYS_VERSION values) */
Michal Vaskoc3781c32020-10-06 14:04:08 +02001144 uint8_t parsing : 1; /**< flag for circular check */
1145 uint8_t is_submod : 1; /**< always 1 */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001146
Michal Vaskoc3781c32020-10-06 14:04:08 +02001147 uint8_t latest_revision : 2; /**< flag to mark the latest available revision:
Radek Krejci086c7132018-10-26 15:29:04 +02001148 1 - the latest revision in searchdirs was not searched yet and this is the
1149 latest revision in the current context
1150 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001151 const char *name; /**< name of the module (mandatory) */
1152 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1153 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
1154 const char *org; /**< party/company responsible for the module */
1155 const char *contact; /**< contact information for the module */
1156 const char *dsc; /**< description of the module */
1157 const char *ref; /**< cross-reference for the module */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001158};
1159
1160/**
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001161 * @brief Get the parsed module or submodule name.
1162 *
1163 * @param[in] PMOD Parsed module or submodule.
1164 * @return Module or submodule name.
1165 */
1166#define LYSP_MODULE_NAME(PMOD) (PMOD->is_submod ? ((struct lysp_submodule *)PMOD)->name : ((struct lysp_module *)PMOD)->mod->name)
1167
1168/**
Radek Krejci8df109d2021-04-23 12:19:08 +02001169 * @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 +02001170 * the expected prefix data is a sized array of these structures.
1171 */
1172struct lysc_prefix {
1173 char *prefix; /**< used prefix */
1174 const struct lys_module *mod; /**< mapping to a module */
1175};
1176
1177/**
Radek Krejci0e59c312019-08-15 15:34:15 +02001178 * @brief Compiled YANG extension-stmt
Radek Krejci9f87b0c2021-03-05 14:45:26 +01001179 *
1180 * Note that the compiled extension definition is created only in case the extension is instantiated. It is not available
1181 * from the compiled schema, but from the parsed extension definition which is being searched when an extension instance
1182 * is being compiled.
Radek Krejci0e59c312019-08-15 15:34:15 +02001183 */
1184struct lysc_ext {
1185 const char *name; /**< extension name */
Radek Krejci9f87b0c2021-03-05 14:45:26 +01001186 const char *argname; /**< argument name, NULL if not specified */
Radek Krejci0e59c312019-08-15 15:34:15 +02001187 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcicc9e30f2021-03-29 12:45:08 +02001188 struct lyplg_ext *plugin; /**< Plugin implementing the specific extension */
Radek Krejci0935f412019-08-20 16:15:18 +02001189 struct lys_module *module; /**< module structure */
Michal Vaskoc636ea42022-09-16 10:20:31 +02001190 uint32_t refcount; /**< unused, always 1 */
Radek Krejci0e59c312019-08-15 15:34:15 +02001191 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
1192};
1193
1194/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001195 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001196 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001197struct lysc_when {
1198 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko175012e2019-11-06 15:49:14 +01001199 struct lysc_node *context; /**< context node for evaluating the expression, NULL if the context is root node */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001200 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001201 const char *dsc; /**< description */
1202 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001203 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001204 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Michal Vaskoecd62de2019-11-13 12:35:11 +01001205 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS is allowed */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001206};
1207
1208/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001209 * @brief YANG identity-stmt
1210 */
1211struct lysc_ident {
Michal Vaskoe313c382022-03-14 13:04:47 +01001212 const char *name; /**< identity name (mandatory, no prefix) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001213 const char *dsc; /**< description */
1214 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001215 struct lys_module *module; /**< module structure */
aPiecek6b3d5422021-07-30 15:55:43 +02001216 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays))
1217 It also contains references to identities located in unimplemented modules. */
Radek Krejci2a408df2018-10-29 16:32:26 +01001218 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1219 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1220};
1221
1222/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001223 * @defgroup ifftokens if-feature expression tokens
Radek Krejci8678fa42020-08-18 16:07:28 +02001224 * Tokens of if-feature expression used in ::lysc_iffeature.expr.
Radek Krejci151a5b72018-10-19 14:21:44 +02001225 *
1226 * @{
1227 */
1228#define LYS_IFF_NOT 0x00 /**< operand "not" */
1229#define LYS_IFF_AND 0x01 /**< operand "and" */
1230#define LYS_IFF_OR 0x02 /**< operand "or" */
1231#define LYS_IFF_F 0x03 /**< feature */
Radek Krejci2ff0d572020-05-21 15:27:28 +02001232/** @} ifftokens */
Radek Krejci151a5b72018-10-19 14:21:44 +02001233
1234/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001235 * @brief Compiled YANG revision statement
1236 */
1237struct lysc_revision {
1238 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1239 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1240};
1241
Radek Krejci2167ee12018-11-02 16:09:07 +01001242struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001243 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001244 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001245 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1246 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001247 };
Radek Krejci693262f2019-04-29 15:23:20 +02001248 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001249 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1250 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001251 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001252 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001253 const char *dsc; /**< description */
1254 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001255 const char *emsg; /**< error-message */
1256 const char *eapptag; /**< error-app-tag value */
1257 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1258};
1259
1260struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001261 const char *expr; /**< original, not compiled, regular expression */
1262 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001263 const char *dsc; /**< description */
1264 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001265 const char *emsg; /**< error-message */
1266 const char *eapptag; /**< error-app-tag value */
1267 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0f969882020-08-21 16:56:47 +02001268 uint32_t inverted : 1; /**< invert-match flag */
1269 uint32_t refcount : 31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001270};
1271
1272struct lysc_must {
Radek Krejci2167ee12018-11-02 16:09:07 +01001273 struct lyxp_expr *cond; /**< XPath when condition */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001274 struct lysc_prefix *prefixes; /**< compiled used prefixes in the condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001275 const char *dsc; /**< description */
1276 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001277 const char *emsg; /**< error-message */
1278 const char *eapptag; /**< error-app-tag value */
1279 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1280};
1281
1282struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001283 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001284 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 +01001285 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001286 uint32_t refcount; /**< reference counter for type sharing, it may be accessed concurrently when
Michal Vaskobabf0bd2021-08-31 14:55:39 +02001287 creating/freeing data node values that reference it (instance-identifier) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001288};
1289
1290struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001291 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001292 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 +01001293 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001294 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci2167ee12018-11-02 16:09:07 +01001295 struct lysc_range *range; /**< Optional range limitation */
1296};
1297
1298struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001299 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001300 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 +01001301 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001302 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001303 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001304 struct lysc_range *range; /**< Optional range limitation */
1305};
1306
1307struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001308 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001309 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 +01001310 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001311 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci2167ee12018-11-02 16:09:07 +01001312 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001313 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001314};
1315
Radek Krejci693262f2019-04-29 15:23:20 +02001316struct lysc_type_bitenum_item {
1317 const char *name; /**< enumeration identifier */
1318 const char *dsc; /**< description */
1319 const char *ref; /**< reference */
1320 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko26bbb272022-08-02 14:54:33 +02001321
Radek Krejci693262f2019-04-29 15:23:20 +02001322 union {
1323 int32_t value; /**< integer value associated with the enumeration */
1324 uint32_t position; /**< non-negative integer value associated with the bit */
1325 };
Michal Vaskof4fa90d2021-11-11 15:05:19 +01001326 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_IS_ENUM values
1327 are allowed */
Radek Krejci693262f2019-04-29 15:23:20 +02001328};
1329
Radek Krejci2167ee12018-11-02 16:09:07 +01001330struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001331 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001332 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 +01001333 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001334 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001335 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1336};
1337
1338struct lysc_type_bits {
1339 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001340 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 +02001341 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001342 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001343 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1344 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001345};
1346
1347struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001348 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001349 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 +01001350 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001351 uint32_t refcount; /**< reference counter for type sharing */
Michal Vasko004d3152020-06-11 19:59:22 +02001352 struct lyxp_expr *path; /**< parsed target path, compiled path cannot be stored because of type sharing */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001353 struct lysc_prefix *prefixes; /**< resolved prefixes used in the path */
Michal Vaskoed725d72021-06-23 12:03:45 +02001354 const struct lys_module *cur_mod;/**< unused, not needed */
Radek Krejci412ddfa2018-11-23 11:44:11 +01001355 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001356 uint8_t require_instance; /**< require-instance flag */
1357};
1358
1359struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001360 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001361 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 +01001362 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001363 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001364 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001365 mandatory (at least 1 item) */
1366};
1367
1368struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001369 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001370 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 +01001371 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001372 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci2167ee12018-11-02 16:09:07 +01001373 uint8_t require_instance; /**< require-instance flag */
1374};
1375
Radek Krejci2167ee12018-11-02 16:09:07 +01001376struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001377 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001378 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 +01001379 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001380 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci2167ee12018-11-02 16:09:07 +01001381 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1382};
1383
1384struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001385 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5f351892021-03-22 16:13:05 +01001386 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 +01001387 LY_DATA_TYPE basetype; /**< Base type of the type */
Michal Vasko080064b2021-08-31 15:20:44 +02001388 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci2167ee12018-11-02 16:09:07 +01001389 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001390};
1391
Michal Vasko60ea6352020-06-29 13:39:39 +02001392/**
1393 * @brief Maximum number of hashes stored in a schema node.
1394 */
1395#define LYS_NODE_HASH_COUNT 4
1396
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001397/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001398 * @brief Compiled YANG data node
1399 */
1400struct lysc_node {
Radek Krejcide7a9c42021-03-10 13:13:06 +01001401 uint16_t nodetype; /**< [type of the node](@ref schemanodetypes) (mandatory) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001402 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Michal Vasko60ea6352020-06-29 13:39:39 +02001403 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001404 struct lys_module *module; /**< module structure */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001405 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1406 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1407 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1408 never NULL. If there is no sibling node, pointer points to the node
1409 itself. In case of the first node, this pointer points to the last
1410 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001411 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001412 const char *dsc; /**< description */
1413 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001414 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001415 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 +02001416};
1417
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001418struct lysc_node_action_inout {
1419 union {
1420 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001421
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001422 struct {
1423 uint16_t nodetype; /**< LYS_INPUT or LYS_OUTPUT */
1424 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1425 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1426 struct lys_module *module; /**< module structure */
Radek Krejci5960c312021-01-27 20:24:22 +01001427 struct lysc_node *parent;/**< parent node (NULL in case of top level node) */
Michal Vasko544e58a2021-01-28 14:33:41 +01001428 struct lysc_node *next; /**< next sibling node (output node for input, NULL for output) */
1429 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 +01001430 const char *name; /**< "input" or "output" */
1431 const char *dsc; /**< ALWAYS NULL, compatibility member with ::lysc_node */
1432 const char *ref; /**< ALWAYS NULL, compatibility member with ::lysc_node */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001433 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001434 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 +01001435 };
1436 };
1437
Radek Krejci9a3823e2021-01-27 20:26:46 +01001438 struct lysc_node *child; /**< first child node (linked list) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001439 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1440};
1441
1442struct lysc_node_action {
1443 union {
1444 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001445
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001446 struct {
1447 uint16_t nodetype; /**< LYS_RPC or LYS_ACTION */
1448 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1449 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1450 struct lys_module *module; /**< module structure */
1451 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1452 struct lysc_node_action *next; /**< next sibling node (NULL if there is no one) */
1453 struct lysc_node_action *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1454 never NULL. If there is no sibling node, pointer points to the node
1455 itself. In case of the first node, this pointer points to the last
1456 node in the list. */
1457 const char *name; /**< action/RPC name (mandatory) */
1458 const char *dsc; /**< description */
1459 const char *ref; /**< reference */
1460 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001461 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 +01001462 };
1463 };
1464
Radek Krejci9a3823e2021-01-27 20:26:46 +01001465 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)),
1466 the action/RPC nodes do not contain the when statement on their own, but they can
1467 inherit it from the parent's uses. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001468 struct lysc_node_action_inout input; /**< RPC's/action's input */
1469 struct lysc_node_action_inout output; /**< RPC's/action's output */
1470
1471};
1472
1473struct lysc_node_notif {
1474 union {
1475 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001476
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001477 struct {
1478 uint16_t nodetype; /**< LYS_NOTIF */
1479 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1480 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1481 struct lys_module *module; /**< module structure */
1482 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1483 struct lysc_node_notif *next; /**< next sibling node (NULL if there is no one) */
1484 struct lysc_node_notif *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1485 never NULL. If there is no sibling node, pointer points to the node
1486 itself. In case of the first node, this pointer points to the last
1487 node in the list. */
1488 const char *name; /**< Notification name (mandatory) */
1489 const char *dsc; /**< description */
1490 const char *ref; /**< reference */
1491 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001492 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 +01001493 };
1494 };
1495
Radek Krejci9a3823e2021-01-27 20:26:46 +01001496 struct lysc_node *child; /**< first child node (linked list) */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001497 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001498 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)),
1499 the notification nodes do not contain the when statement on their own, but they can
1500 inherit it from the parent's uses. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001501};
1502
1503struct lysc_node_container {
1504 union {
1505 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001506
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001507 struct {
1508 uint16_t nodetype; /**< LYS_CONTAINER */
1509 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1510 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1511 struct lys_module *module; /**< module structure */
1512 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1513 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1514 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1515 never NULL. If there is no sibling node, pointer points to the node
1516 itself. In case of the first node, this pointer points to the last
1517 node in the list. */
1518 const char *name; /**< node name (mandatory) */
1519 const char *dsc; /**< description */
1520 const char *ref; /**< reference */
1521 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001522 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 +01001523 };
1524 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001525
1526 struct lysc_node *child; /**< first child node (linked list) */
1527 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001528 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001529 struct lysc_node_action *actions;/**< first of actions nodes (linked list) */
1530 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001531};
1532
Radek Krejcia3045382018-11-22 14:30:31 +01001533struct lysc_node_case {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001534 union {
1535 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001536
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001537 struct {
1538 uint16_t nodetype; /**< LYS_CASE */
1539 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1540 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
1541 struct lys_module *module; /**< module structure */
1542 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1543 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1544 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejci056d0a82018-12-06 16:57:25 +01001545 never NULL. If there is no sibling node, pointer points to the node
1546 itself. In case of the first node, this pointer points to the last
1547 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001548 const char *name; /**< name of the case, including the implicit case */
1549 const char *dsc; /**< description */
1550 const char *ref; /**< reference */
1551 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001552 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 +01001553 };
1554 };
Radek Krejci056d0a82018-12-06 16:57:25 +01001555
Radek Krejcia3045382018-11-22 14:30:31 +01001556 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 +01001557 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001558 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcia3045382018-11-22 14:30:31 +01001559};
1560
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001561struct lysc_node_choice {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001562 union {
1563 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001564
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001565 struct {
1566 uint16_t nodetype; /**< LYS_CHOICE */
1567 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1568 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser, unused */
1569 struct lys_module *module; /**< module structure */
1570 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1571 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1572 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001573 never NULL. If there is no sibling node, pointer points to the node
1574 itself. In case of the first node, this pointer points to the last
1575 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001576 const char *name; /**< node name (mandatory) */
1577 const char *dsc; /**< description */
1578 const char *ref; /**< reference */
1579 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001580 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 +01001581 };
1582 };
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001583
Radek Krejcia9026eb2018-12-12 16:04:47 +01001584 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1585 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1586 case is simple. */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001587 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001588 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001589};
1590
1591struct lysc_node_leaf {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001592 union {
1593 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001594
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001595 struct {
1596 uint16_t nodetype; /**< LYS_LEAF */
1597 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1598 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1599 struct lys_module *module; /**< module structure */
1600 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1601 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1602 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001603 never NULL. If there is no sibling node, pointer points to the node
1604 itself. In case of the first node, this pointer points to the last
1605 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001606 const char *name; /**< node name (mandatory) */
1607 const char *dsc; /**< description */
1608 const char *ref; /**< reference */
1609 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001610 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 +01001611 };
1612 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001613
1614 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001615 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001616 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001617
Radek Krejci4f28eda2018-11-12 11:46:16 +01001618 const char *units; /**< units of the leaf's type */
Michal Vasko33876022021-04-27 16:42:24 +02001619 struct lyd_value *dflt; /**< default value, use ::lyd_value_get_canonical() to get the canonical string */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001620};
1621
1622struct lysc_node_leaflist {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001623 union {
1624 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001625
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001626 struct {
1627 uint16_t nodetype; /**< LYS_LEAFLIST */
1628 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1629 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1630 struct lys_module *module; /**< module structure */
1631 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1632 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1633 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001634 never NULL. If there is no sibling node, pointer points to the node
1635 itself. In case of the first node, this pointer points to the last
1636 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001637 const char *name; /**< node name (mandatory) */
1638 const char *dsc; /**< description */
1639 const char *ref; /**< reference */
1640 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001641 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 +01001642 };
1643 };
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001644
1645 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001646 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001647 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1648
Radek Krejci0e5d8382018-11-28 16:37:53 +01001649 const char *units; /**< units of the leaf's type */
Michal Vasko33876022021-04-27 16:42:24 +02001650 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values, use
1651 ::lyd_value_get_canonical() to get the canonical strings */
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001652
Radek Krejci0e5d8382018-11-28 16:37:53 +01001653 uint32_t min; /**< min-elements constraint */
1654 uint32_t max; /**< max-elements constraint */
1655
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001656};
1657
1658struct lysc_node_list {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001659 union {
1660 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001661
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001662 struct {
1663 uint16_t nodetype; /**< LYS_LIST */
1664 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1665 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1666 struct lys_module *module; /**< module structure */
1667 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1668 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1669 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001670 never NULL. If there is no sibling node, pointer points to the node
1671 itself. In case of the first node, this pointer points to the last
1672 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001673 const char *name; /**< node name (mandatory) */
1674 const char *dsc; /**< description */
1675 const char *ref; /**< reference */
1676 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 };
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001680
1681 struct lysc_node *child; /**< first child node (linked list) */
1682 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001683 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001684 struct lysc_node_action *actions;/**< first of actions nodes (linked list) */
1685 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001686
Radek Krejci2a9fc652021-01-22 17:44:34 +01001687 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 +01001688 uint32_t min; /**< min-elements constraint */
1689 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001690};
1691
1692struct lysc_node_anydata {
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001693 union {
1694 struct lysc_node node; /**< implicit cast for the members compatible with ::lysc_node */
Michal Vasko26bbb272022-08-02 14:54:33 +02001695
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001696 struct {
1697 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1698 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1699 uint8_t hash[LYS_NODE_HASH_COUNT]; /**< schema hash required for LYB printer/parser */
1700 struct lys_module *module; /**< module structure */
1701 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1702 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1703 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001704 never NULL. If there is no sibling node, pointer points to the node
1705 itself. In case of the first node, this pointer points to the last
1706 node in the list. */
Radek Krejci00a3e8a2021-01-27 08:24:49 +01001707 const char *name; /**< node name (mandatory) */
1708 const char *dsc; /**< description */
1709 const char *ref; /**< reference */
1710 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
aPiecek9922ea92021-04-12 07:59:20 +02001711 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 +01001712 };
1713 };
Radek Krejci9800fb82018-12-13 14:26:23 +01001714
1715 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci9a3823e2021-01-27 20:26:46 +01001716 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001717};
1718
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001719/**
1720 * @brief Compiled YANG schema tree structure representing YANG module.
1721 *
1722 * Semantically validated YANG schema tree for data tree parsing.
1723 * Contains only the necessary information for the data validation.
1724 */
1725struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001726 struct lys_module *mod; /**< covering module structure */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001727
Radek Krejci2a408df2018-10-29 16:32:26 +01001728 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejci2a9fc652021-01-22 17:44:34 +01001729 struct lysc_node_action *rpcs; /**< first of actions nodes (linked list) */
1730 struct lysc_node_notif *notifs; /**< first of notifications nodes (linked list) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001731 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001732};
1733
1734/**
Radek Krejci490a5462020-11-05 08:44:42 +01001735 * @brief Examine whether a node is user-ordered list or leaf-list.
1736 *
1737 * @param[in] lysc_node Schema node to examine.
1738 * @return Boolean value whether the @p node is user-ordered or not.
1739 */
1740#define lysc_is_userordered(lysc_node) \
1741 ((!lysc_node || !(lysc_node->nodetype & (LYS_LEAFLIST | LYS_LIST)) || !(lysc_node->flags & LYS_ORDBY_USER)) ? 0 : 1)
1742
1743/**
1744 * @brief Examine whether a node is a list's key.
1745 *
1746 * @param[in] lysc_node Schema node to examine.
1747 * @return Boolean value whether the @p node is a key or not.
1748 */
1749#define lysc_is_key(lysc_node) \
Michal Vaskobce7ee32021-02-04 11:05:25 +01001750 ((!lysc_node || (lysc_node->nodetype != LYS_LEAF) || !(lysc_node->flags & LYS_KEY)) ? 0 : 1)
Radek Krejci490a5462020-11-05 08:44:42 +01001751
1752/**
Michal Vasko5c123b02020-12-04 14:34:04 +01001753 * @brief Examine whether a node is a non-presence container.
1754 *
1755 * @param[in] lysc_node Schema node to examine.
1756 * @return Boolean value whether the @p node is a NP container or not.
1757 */
1758#define lysc_is_np_cont(lysc_node) \
Michal Vaskobce7ee32021-02-04 11:05:25 +01001759 ((!lysc_node || (lysc_node->nodetype != LYS_CONTAINER) || (lysc_node->flags & LYS_PRESENCE)) ? 0 : 1)
1760
1761/**
Michal Vaskoe78faec2021-04-08 17:24:43 +02001762 * @brief Examine whether a node is a key-less list or a non-configuration leaf-list.
Michal Vaskobce7ee32021-02-04 11:05:25 +01001763 *
1764 * @param[in] lysc_node Schema node to examine.
1765 * @return Boolean value whether the @p node is a list with duplicate instances allowed.
1766 */
1767#define lysc_is_dup_inst_list(lysc_node) \
1768 ((lysc_node && (((lysc_node->nodetype == LYS_LIST) && (lysc_node->flags & LYS_KEYLESS)) || \
Michal Vaskoe78faec2021-04-08 17:24:43 +02001769 ((lysc_node->nodetype == LYS_LEAFLIST) && !(lysc_node->flags & LYS_CONFIG_W)))) ? 1 : 0)
Michal Vasko5c123b02020-12-04 14:34:04 +01001770
1771/**
Michal Vaskof8ded142022-02-17 10:48:01 +01001772 * @brief Get nearest @p schema parent (including the node itself) that can be instantiated in data.
1773 *
1774 * @param[in] schema Schema node to get the nearest data node for.
1775 * @return Schema data node, NULL if top-level (in data).
1776 */
1777LIBYANG_API_DECL const struct lysc_node *lysc_data_node(const struct lysc_node *schema);
1778
1779/**
1780 * @brief Same as ::lysc_data_node() but never returns the node itself.
1781 */
1782#define lysc_data_parent(SCHEMA) lysc_data_node((SCHEMA) ? (SCHEMA)->parent : NULL)
1783
1784/**
Michal Vaskod5cfa6e2020-11-23 16:56:08 +01001785 * @brief Check whether the schema node data instance existence depends on any when conditions.
1786 * This node and any direct parent choice and case schema nodes are also examined for when conditions.
1787 *
1788 * Be careful, this function is not recursive and checks only conditions that apply to this node directly.
1789 * Meaning if there are any conditions associated with any data parent instance of @p node, they are not returned.
1790 *
1791 * @param[in] node Schema node to examine.
1792 * @return When condition associated with the node data instance, NULL if there is none.
1793 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001794LIBYANG_API_DECL const struct lysc_when *lysc_has_when(const struct lysc_node *node);
Michal Vaskod5cfa6e2020-11-23 16:56:08 +01001795
1796/**
Michal Vaskoef53c812021-10-13 10:21:03 +02001797 * @brief Get the owner module of the schema node. It is the module of the top-level node. Generally,
1798 * in case of augments it is the target module, recursively, otherwise it is the module where the node is defined.
1799 *
1800 * @param[in] node Schema node to examine.
1801 * @return Module owner of the node.
1802 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001803LIBYANG_API_DECL const struct lys_module *lysc_owner_module(const struct lysc_node *node);
Michal Vaskoef53c812021-10-13 10:21:03 +02001804
1805/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001806 * @brief Get the groupings linked list of the given (parsed) schema node.
Radek Krejci53ea6152018-12-13 15:21:15 +01001807 * Decides the node's type and in case it has a groupings array, returns it.
1808 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01001809 * @return The node's groupings linked list if any, NULL otherwise.
Radek Krejci53ea6152018-12-13 15:21:15 +01001810 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001811LIBYANG_API_DECL const struct lysp_node_grp *lysp_node_groupings(const struct lysp_node *node);
Radek Krejci53ea6152018-12-13 15:21:15 +01001812
1813/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001814 * @brief Get the typedefs sized array of the given (parsed) schema node.
1815 * Decides the node's type and in case it has a typedefs array, returns it.
1816 * @param[in] node Node to examine.
1817 * @return The node's typedefs sized array if any, NULL otherwise.
1818 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001819LIBYANG_API_DECL const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01001820
1821/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001822 * @brief Get the actions/RPCs linked list of the given (parsed) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01001823 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1824 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01001825 * @return The node's actions/RPCs linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01001826 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001827LIBYANG_API_DECL const struct lysp_node_action *lysp_node_actions(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01001828
1829/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001830 * @brief Get the Notifications linked list of the given (parsed) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01001831 * Decides the node's type and in case it has a Notifications array, returns it.
1832 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01001833 * @return The node's Notifications linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01001834 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001835LIBYANG_API_DECL const struct lysp_node_notif *lysp_node_notifs(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01001836
1837/**
1838 * @brief Get the children linked list of the given (parsed) schema node.
1839 * Decides the node's type and in case it has a children list, returns it.
1840 * @param[in] node Node to examine.
1841 * @return The node's children linked list if any, NULL otherwise.
1842 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001843LIBYANG_API_DECL const struct lysp_node *lysp_node_child(const struct lysp_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01001844
1845/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001846 * @brief Get the actions/RPCs linked list of the given (compiled) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01001847 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1848 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01001849 * @return The node's actions/RPCs linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01001850 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001851LIBYANG_API_DECL const struct lysc_node_action *lysc_node_actions(const struct lysc_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01001852
1853/**
Radek Krejci2a9fc652021-01-22 17:44:34 +01001854 * @brief Get the Notifications linked list of the given (compiled) schema node.
Radek Krejci056d0a82018-12-06 16:57:25 +01001855 * Decides the node's type and in case it has a Notifications array, returns it.
1856 * @param[in] node Node to examine.
Radek Krejci2a9fc652021-01-22 17:44:34 +01001857 * @return The node's Notifications linked list if any, NULL otherwise.
Radek Krejci056d0a82018-12-06 16:57:25 +01001858 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001859LIBYANG_API_DECL const struct lysc_node_notif *lysc_node_notifs(const struct lysc_node *node);
Radek Krejci056d0a82018-12-06 16:57:25 +01001860
1861/**
1862 * @brief Get the children linked list of the given (compiled) schema node.
Michal Vasko2a668712020-10-21 11:48:09 +02001863 *
Michal Vasko544e58a2021-01-28 14:33:41 +01001864 * Note that ::LYS_CHOICE has only ::LYS_CASE children.
1865 * Also, ::LYS_RPC and ::LYS_ACTION have the first child ::LYS_INPUT, its sibling is ::LYS_OUTPUT.
1866 *
Michal Vasko2a668712020-10-21 11:48:09 +02001867 * @param[in] node Node to examine.
Michal Vasko2a668712020-10-21 11:48:09 +02001868 * @return Children linked list if any,
1869 * @return NULL otherwise.
1870 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001871LIBYANG_API_DECL const struct lysc_node *lysc_node_child(const struct lysc_node *node);
Michal Vasko2a668712020-10-21 11:48:09 +02001872
1873/**
Radek Krejci9a3823e2021-01-27 20:26:46 +01001874 * @brief Get the must statements list if present in the @p node
1875 *
1876 * @param[in] node Node to examine.
1877 * @return Pointer to the list of must restrictions ([sized array](@ref sizedarrays))
1878 * @return NULL if there is no must statement in the node, no matter if it is not even allowed or just present
1879 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001880LIBYANG_API_DECL struct lysc_must *lysc_node_musts(const struct lysc_node *node);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001881
1882/**
1883 * @brief Get the when statements list if present in the @p node
1884 *
1885 * @param[in] node Node to examine.
1886 * @return Pointer to the list of pointers to when statements ([sized array](@ref sizedarrays))
1887 * @return NULL if there is no when statement in the node, no matter if it is not even allowed or just present
1888 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001889LIBYANG_API_DECL struct lysc_when **lysc_node_when(const struct lysc_node *node);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001890
1891/**
Michal Vaskof1ab44f2020-10-22 08:58:32 +02001892 * @brief Callback to be called for every schema node in a DFS traversal.
1893 *
1894 * @param[in] node Current node.
1895 * @param[in] data Arbitrary user data.
1896 * @param[out] dfs_continue Set to true if the current subtree should be skipped and continue with siblings instead.
1897 * @return LY_SUCCESS on success,
1898 * @return LY_ERR value to terminate DFS and return this value.
1899 */
Michal Vasko8f07dfe2021-03-02 16:10:24 +01001900typedef LY_ERR (*lysc_dfs_clb)(struct lysc_node *node, void *data, ly_bool *dfs_continue);
Michal Vaskof1ab44f2020-10-22 08:58:32 +02001901
1902/**
1903 * @brief DFS traversal of all the schema nodes in a (sub)tree including any actions and nested notifications.
1904 *
1905 * Node with children, actions, and notifications is traversed in this order:
1906 * 1) each child subtree;
1907 * 2) each action subtree;
1908 * 3) each notification subtree.
1909 *
1910 * For algorithm illustration or traversal with actions and notifications skipped, see ::LYSC_TREE_DFS_BEGIN.
1911 *
1912 * @param[in] root Schema root to fully traverse.
1913 * @param[in] dfs_clb Callback to call for each node.
1914 * @param[in] data Arbitrary user data passed to @p dfs_clb.
1915 * @return LY_SUCCESS on success,
1916 * @return LY_ERR value returned by @p dfs_clb.
1917 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001918LIBYANG_API_DECL LY_ERR lysc_tree_dfs_full(const struct lysc_node *root, lysc_dfs_clb dfs_clb, void *data);
Michal Vaskof1ab44f2020-10-22 08:58:32 +02001919
1920/**
1921 * @brief DFS traversal of all the schema nodes in a module including RPCs and notifications.
1922 *
1923 * For more details, see ::lysc_tree_dfs_full().
1924 *
1925 * @param[in] mod Module to fully traverse.
1926 * @param[in] dfs_clb Callback to call for each node.
1927 * @param[in] data Arbitrary user data passed to @p dfs_clb.
1928 * @return LY_SUCCESS on success,
1929 * @return LY_ERR value returned by @p dfs_clb.
1930 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001931LIBYANG_API_DECL LY_ERR lysc_module_dfs_full(const struct lys_module *mod, lysc_dfs_clb dfs_clb, void *data);
Michal Vaskof1ab44f2020-10-22 08:58:32 +02001932
1933/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001934 * @brief Get how the if-feature statement currently evaluates.
1935 *
1936 * @param[in] iff Compiled if-feature statement to evaluate.
Michal Vasko28d78432020-05-26 13:10:53 +02001937 * @return LY_SUCCESS if the statement evaluates to true,
1938 * @return LY_ENOT if it evaluates to false,
1939 * @return LY_ERR on error.
Radek Krejci151a5b72018-10-19 14:21:44 +02001940 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001941LIBYANG_API_DECL LY_ERR lysc_iffeature_value(const struct lysc_iffeature *iff);
Radek Krejci151a5b72018-10-19 14:21:44 +02001942
1943/**
aPiecekf4a0a192021-08-03 15:14:17 +02001944 * @brief Get how the if-feature statement is evaluated for certain identity.
1945 *
1946 * The function can be called even if the identity does not contain
1947 * if-features, in which case ::LY_SUCCESS is returned.
1948 *
1949 * @param[in] ident Compiled identity statement to evaluate.
1950 * @return LY_SUCCESS if the statement evaluates to true,
1951 * @return LY_ENOT if it evaluates to false,
1952 * @return LY_ERR on error.
1953 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001954LIBYANG_API_DECL LY_ERR lys_identity_iffeature_value(const struct lysc_ident *ident);
aPiecekf4a0a192021-08-03 15:14:17 +02001955
1956/**
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001957 * @brief Get the next feature in the module or submodules.
Radek Krejci151a5b72018-10-19 14:21:44 +02001958 *
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001959 * @param[in] last Last returned feature.
Michal Vasko4ec4bc02021-10-12 10:17:28 +02001960 * @param[in] pmod Parsed module and submodules whose features to iterate over.
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001961 * @param[in,out] idx Submodule index, set to 0 on first call.
1962 * @return Next found feature, NULL if the last has already been returned.
Radek Krejci151a5b72018-10-19 14:21:44 +02001963 */
Michal Vaskoc1a0ff62022-02-28 14:27:16 +01001964LIBYANG_API_DECL struct lysp_feature *lysp_feature_next(const struct lysp_feature *last, const struct lysp_module *pmod,
1965 uint32_t *idx);
Radek Krejci151a5b72018-10-19 14:21:44 +02001966
Radek Krejcibed13942020-10-19 16:06:28 +02001967/**
1968 * @defgroup findxpathoptions Atomize XPath options
1969 * Options to modify behavior of ::lys_find_xpath() and ::lys_find_xpath_atoms() searching for schema nodes in schema tree.
1970 * @{
1971 */
Michal Vasko4ad69e72021-10-26 16:25:55 +02001972#define LYS_FIND_XP_SCHEMA 0x08 /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */
1973#define LYS_FIND_XP_OUTPUT 0x10 /**< Search RPC/action output nodes instead of input ones. */
Michal Vaskoa2fe0812022-05-26 09:24:32 +02001974#define LYS_FIND_NO_MATCH_ERROR 0x40 /**< Return error if a path segment matches no nodes, otherwise only warning
Michal Vasko4ad69e72021-10-26 16:25:55 +02001975 is printed. */
Radek Krejci576f8fa2020-10-26 21:23:58 +01001976/** @} findxpathoptions */
Michal Vasko072de482020-08-05 13:27:21 +02001977
Radek Krejci151a5b72018-10-19 14:21:44 +02001978/**
Michal Vasko40308e72020-10-20 16:38:40 +02001979 * @brief Get all the schema nodes that are required for @p xpath to be evaluated (atoms).
Michal Vasko519fd602020-05-26 12:17:39 +02001980 *
Michal Vasko26512682021-01-11 11:35:40 +01001981 * @param[in] ctx libyang context to use. May be NULL if @p ctx_node is set.
1982 * @param[in] ctx_node XPath schema context node. Use NULL for the root node.
Radek Krejci8df109d2021-04-23 12:19:08 +02001983 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_VALUE_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02001984 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko519fd602020-05-26 12:17:39 +02001985 * @param[out] set Set of found atoms (schema nodes).
1986 * @return LY_SUCCESS on success, @p set is returned.
Michal Vasko40308e72020-10-20 16:38:40 +02001987 * @return LY_ERR value on error.
Michal Vasko519fd602020-05-26 12:17:39 +02001988 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001989LIBYANG_API_DECL LY_ERR lys_find_xpath_atoms(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *xpath,
Michal Vasko26512682021-01-11 11:35:40 +01001990 uint32_t options, struct ly_set **set);
Michal Vasko519fd602020-05-26 12:17:39 +02001991
Michal Vasko072de482020-08-05 13:27:21 +02001992/**
Michal Vasko40308e72020-10-20 16:38:40 +02001993 * @brief Get all the schema nodes that are required for @p expr to be evaluated (atoms).
Michal Vasko072de482020-08-05 13:27:21 +02001994 *
Michal Vasko26512682021-01-11 11:35:40 +01001995 * @param[in] ctx_node XPath schema context node. Use NULL for the root node.
Michal Vasko40308e72020-10-20 16:38:40 +02001996 * @param[in] cur_mod Current module for the expression (where it was "instantiated").
1997 * @param[in] expr Parsed expression to use.
1998 * @param[in] prefixes Sized array of compiled prefixes.
1999 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
2000 * @param[out] set Set of found atoms (schema nodes).
2001 * @return LY_SUCCESS on success, @p set is returned.
2002 * @return LY_ERR value on error.
2003 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002004LIBYANG_API_DECL LY_ERR lys_find_expr_atoms(const struct lysc_node *ctx_node, const struct lys_module *cur_mod,
Michal Vasko40308e72020-10-20 16:38:40 +02002005 const struct lyxp_expr *expr, const struct lysc_prefix *prefixes, uint32_t options, struct ly_set **set);
2006
2007/**
2008 * @brief Evaluate an @p xpath expression on schema nodes.
2009 *
Michal Vasko26512682021-01-11 11:35:40 +01002010 * @param[in] ctx libyang context to use for absolute @p xpath. May be NULL if @p ctx_node is set.
2011 * @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 +02002012 * @param[in] xpath Data XPath expression filtering the matching nodes. ::LY_VALUE_JSON prefix format is expected.
Radek Krejcibed13942020-10-19 16:06:28 +02002013 * @param[in] options Whether to apply some node access restrictions, see @ref findxpathoptions.
Michal Vasko072de482020-08-05 13:27:21 +02002014 * @param[out] set Set of found schema nodes.
2015 * @return LY_SUCCESS on success, @p set is returned.
2016 * @return LY_ERR value if an error occurred.
2017 */
Michal Vaskoc1a0ff62022-02-28 14:27:16 +01002018LIBYANG_API_DECL LY_ERR lys_find_xpath(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *xpath,
2019 uint32_t options, struct ly_set **set);
Michal Vasko519fd602020-05-26 12:17:39 +02002020
2021/**
Radek Krejcibc5644c2020-10-27 14:53:17 +01002022 * @brief Get all the schema nodes that are required for @p path to be evaluated (atoms).
2023 *
2024 * @param[in] path Compiled path to use.
2025 * @param[out] set Set of found atoms (schema nodes).
2026 * @return LY_SUCCESS on success, @p set is returned.
2027 * @return LY_ERR value on error.
2028 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002029LIBYANG_API_DECL LY_ERR lys_find_lypath_atoms(const struct ly_path *path, struct ly_set **set);
Radek Krejcibc5644c2020-10-27 14:53:17 +01002030
2031/**
2032 * @brief Get all the schema nodes that are required for @p path to be evaluated (atoms).
2033 *
Michal Vasko26512682021-01-11 11:35:40 +01002034 * @param[in] ctx libyang context to use for absolute @p path. May be NULL if @p ctx_node is set.
2035 * @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 +01002036 * @param[in] path JSON path to examine.
2037 * @param[in] output Search operation output instead of input.
2038 * @param[out] set Set of found atoms (schema nodes).
2039 * @return LY_ERR value on error.
2040 */
Michal Vaskoc1a0ff62022-02-28 14:27:16 +01002041LIBYANG_API_DECL LY_ERR lys_find_path_atoms(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *path,
2042 ly_bool output, struct ly_set **set);
Radek Krejcibc5644c2020-10-27 14:53:17 +01002043
2044/**
2045 * @brief Get a schema node based on the given data path (JSON format, see @ref howtoXPath).
2046 *
Michal Vasko26512682021-01-11 11:35:40 +01002047 * @param[in] ctx libyang context to use for absolute @p path. May be NULL if @p ctx_node is set.
2048 * @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 +01002049 * @param[in] path JSON path of the node to get.
2050 * @param[in] output Search operation output instead of input.
2051 * @return Found schema node or NULL.
2052 */
Michal Vaskoc1a0ff62022-02-28 14:27:16 +01002053LIBYANG_API_DECL const struct lysc_node *lys_find_path(const struct ly_ctx *ctx, const struct lysc_node *ctx_node,
2054 const char *path, ly_bool output);
Radek Krejcibc5644c2020-10-27 14:53:17 +01002055
2056/**
Michal Vasko03ff5a72019-09-11 13:49:33 +02002057 * @brief Types of the different schema paths.
2058 */
2059typedef enum {
Michal Vasko65de0402020-08-03 16:34:19 +02002060 LYSC_PATH_LOG, /**< Descriptive path format used in log messages */
Michal Vaskobde22b62022-03-22 15:32:56 +01002061 LYSC_PATH_DATA, /**< Similar to ::LYSC_PATH_LOG except that schema-only nodes (choice, case) are skipped */
2062 LYSC_PATH_DATA_PATTERN /**< Similar to ::LYSC_PATH_DATA but there are predicates for all list keys added with
2063 "%s" where their values should be so that they can be printed there */
Michal Vasko03ff5a72019-09-11 13:49:33 +02002064} LYSC_PATH_TYPE;
2065
2066/**
Radek Krejci327de162019-06-14 12:52:07 +02002067 * @brief Generate path of the given node in the requested format.
2068 *
2069 * @param[in] node Schema path of this node will be generated.
2070 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02002071 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
2072 * If NULL, memory for the complete path is allocated.
2073 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02002074 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02002075 * 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 +02002076 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002077LIBYANG_API_DECL char *lysc_path(const struct lysc_node *node, LYSC_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02002078
2079/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002080 * @brief Available YANG schema tree structures representing YANG module.
2081 */
2082struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002083 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
2084 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01002085 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01002086 const char *ns; /**< namespace of the module (module - mandatory) */
2087 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
2088 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
2089 const char *org; /**< party/company responsible for the module */
2090 const char *contact; /**< contact information for the module */
2091 const char *dsc; /**< description of the module */
2092 const char *ref; /**< cross-reference for the module */
2093
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002094 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01002095 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
2096 Available only for implemented modules. */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002097
Radek Krejci80d281e2020-09-14 17:42:54 +02002098 struct lysc_ident *identities; /**< List of compiled identities of the module ([sized array](@ref sizedarrays))
aPiecek6b3d5422021-07-30 15:55:43 +02002099 also contains the disabled identities when their if-feature(s) are evaluated to \"false\",
2100 and also the list is filled even if the module is not implemented.
2101 The list is located here because it avoids problems when the module became implemented in
Radek Krejci80d281e2020-09-14 17:42:54 +02002102 future (no matter if implicitly via augment/deviate or explicitly via
2103 ::lys_set_implemented()). Note that if the module is not implemented (compiled), the
2104 identities cannot be instantiated in data (in identityrefs). */
Michal Vasko7f45cf22020-10-01 12:49:44 +02002105
2106 struct lys_module **augmented_by;/**< List of modules that augment this module ([sized array](@ref sizedarrays)) */
2107 struct lys_module **deviated_by; /**< List of modules that deviate this module ([sized array](@ref sizedarrays)) */
2108
Michal Vasko89b5c072020-10-06 13:52:44 +02002109 ly_bool implemented; /**< flag if the module is implemented, not just imported */
Michal Vasko01db7de2021-04-16 12:23:30 +02002110 ly_bool to_compile; /**< flag marking a module that was changed but not (re)compiled, see
2111 ::LY_CTX_EXPLICIT_COMPILE. */
aPiecek8ca21bd2021-07-26 14:31:01 +02002112 uint8_t latest_revision; /**< Flag to mark the latest available revision, see [latest_revision options](@ref latestrevflags). */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002113};
2114
Radek Krejci151a5b72018-10-19 14:21:44 +02002115/**
aPiecek8ca21bd2021-07-26 14:31:01 +02002116 * @defgroup latestrevflags Options for ::lys_module.latest_revision.
2117 *
2118 * Various information bits of ::lys_module.latest_revision.
2119 *
2120 * @{
2121 */
aPiecek94d330b2021-08-04 11:57:31 +02002122#define LYS_MOD_LATEST_REV 0x01 /**< This is the latest revision of the module in the current context. */
2123#define LYS_MOD_LATEST_SEARCHDIRS 0x02 /**< This is the latest revision of the module found in searchdirs. */
Michal Vaskobdac23f2022-01-12 14:02:35 +01002124#define LYS_MOD_IMPORTED_REV 0x04 /**< This is the module revision used when importing the module without
2125 an explicit revision-date. It is used for all such imports regardless of
2126 any changes made in the context. */
2127#define LYS_MOD_LATEST_IMPCLB 0x08 /**< This is the latest revision of the module obtained from import callback. */
aPiecek8ca21bd2021-07-26 14:31:01 +02002128/** @} latestrevflags */
2129
2130/**
Michal Vasko82c31e62020-07-17 15:30:40 +02002131 * @brief Get the current real status of the specified feature in the module.
2132 *
2133 * If the feature is enabled, but some of its if-features are false, the feature is considered
2134 * disabled.
Radek Krejci151a5b72018-10-19 14:21:44 +02002135 *
2136 * @param[in] module Module where the feature is defined.
2137 * @param[in] feature Name of the feature to inspect.
Michal Vasko82c31e62020-07-17 15:30:40 +02002138 * @return LY_SUCCESS if the feature is enabled,
2139 * @return LY_ENOT if the feature is disabled,
2140 * @return LY_ENOTFOUND if the feature was not found.
Radek Krejci151a5b72018-10-19 14:21:44 +02002141 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002142LIBYANG_API_DECL LY_ERR lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02002143
2144/**
Michal Vasko3608d252022-02-28 14:28:12 +01002145 * @brief Get next schema (sibling) node element in the schema order that can be instantiated in a data tree.
2146 * Returned node may be from an augment.
Radek Krejcia3045382018-11-22 14:30:31 +01002147 *
Michal Vasko3608d252022-02-28 14:28:12 +01002148 * ::lys_getnext() is supposed to be called sequentially. In the first call, the @p last parameter is usually NULL
2149 * and function starts returning 1) the first @p parent child (if it is set) or 2) the first top level element of
2150 * @p module. Consequent calls should provide the previously returned node as @p last and the same @p parent and
2151 * @p module parameters.
Radek Krejcia3045382018-11-22 14:30:31 +01002152 *
2153 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
Michal Vasko3608d252022-02-28 14:28:12 +01002154 * data nodes in a data tree. By setting some @p options the behavior can be modified to the extent that
Radek Krejcia3045382018-11-22 14:30:31 +01002155 * all the schema nodes are iteratively returned.
2156 *
2157 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
Michal Vasko3608d252022-02-28 14:28:12 +01002158 * @param[in] parent Parent of the subtree to iterate over. If set, @p module is ignored.
2159 * @param[in] module Module of the top level elements to iterate over. If @p parent is NULL, it must be specified.
Radek Krejcia3045382018-11-22 14:30:31 +01002160 * @param[in] options [ORed options](@ref sgetnextflags).
Michal Vasko3608d252022-02-28 14:28:12 +01002161 * @return Next schema tree node, NULL in case there are no more.
Radek Krejcia3045382018-11-22 14:30:31 +01002162 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002163LIBYANG_API_DECL const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002164 const struct lysc_module *module, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002165
2166/**
Michal Vasko3608d252022-02-28 14:28:12 +01002167 * @brief Get next schema (sibling) node element in the schema order of an extension that can be instantiated in
2168 * a data tree.
Radek Krejci8678fa42020-08-18 16:07:28 +02002169 *
Michal Vasko3608d252022-02-28 14:28:12 +01002170 * It is just ::lys_getnext() for extensions.
Radek Krejci035dacf2021-02-12 18:25:53 +01002171 *
2172 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
Michal Vasko3608d252022-02-28 14:28:12 +01002173 * @param[in] parent Parent of the subtree to iterate over. If set, @p ext is ignored.
2174 * @param[in] ext Extension instance with schema nodes to iterate over. If @p parent is NULL, it must be specified.
Radek Krejci035dacf2021-02-12 18:25:53 +01002175 * @param[in] options [ORed options](@ref sgetnextflags).
Michal Vasko3608d252022-02-28 14:28:12 +01002176 * @return Next schema tree node, NULL in case there are no more.
Radek Krejci035dacf2021-02-12 18:25:53 +01002177 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002178LIBYANG_API_DECL const struct lysc_node *lys_getnext_ext(const struct lysc_node *last, const struct lysc_node *parent,
Radek Krejci035dacf2021-02-12 18:25:53 +01002179 const struct lysc_ext_instance *ext, uint32_t options);
2180
2181/**
2182 * @defgroup sgetnextflags Options for ::lys_getnext() and ::lys_getnext_ext().
2183 *
2184 * Various options setting behavior of ::lys_getnext() and ::lys_getnext_ext().
Radek Krejci8678fa42020-08-18 16:07:28 +02002185 *
Radek Krejcia3045382018-11-22 14:30:31 +01002186 * @{
2187 */
Radek Krejci8678fa42020-08-18 16:07:28 +02002188#define LYS_GETNEXT_WITHCHOICE 0x01 /**< ::lys_getnext() option to allow returning #LYS_CHOICE nodes instead of looking into them */
2189#define LYS_GETNEXT_NOCHOICE 0x02 /**< ::lys_getnext() option to ignore (kind of conditional) nodes within choice node */
2190#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 +01002191#define LYS_GETNEXT_INTONPCONT 0x08 /**< ::lys_getnext() option to look into non-presence container, instead of returning container itself */
2192#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 +01002193 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01002194/** @} sgetnextflags */
2195
2196/**
2197 * @brief Get child node according to the specified criteria.
2198 *
2199 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
2200 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
2201 * @param[in] name Name of the node to find.
2202 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
2203 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
2204 * Used as a bitmask, so multiple nodetypes can be specified.
2205 * @param[in] options [ORed options](@ref sgetnextflags).
2206 * @return Found node if any.
2207 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002208LIBYANG_API_DECL const struct lysc_node *lys_find_child(const struct lysc_node *parent, const struct lys_module *module,
Radek Krejci1deb5be2020-08-26 16:43:36 +02002209 const char *name, size_t name_len, uint16_t nodetype, uint32_t options);
Radek Krejcia3045382018-11-22 14:30:31 +01002210
2211/**
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002212 * @brief Make the specific module implemented.
2213 *
Michal Vaskoe8988e92021-01-25 11:26:29 +01002214 * If the module is already implemented but with a different set of features, the whole context is recompiled.
2215 *
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002216 * @param[in] mod Module to make implemented. It is not an error
2217 * to provide already implemented module, it just does nothing.
Michal Vaskoe8988e92021-01-25 11:26:29 +01002218 * @param[in] features Optional array specifying the enabled features terminated with NULL overriding any previous
2219 * feature setting. The feature string '*' enables all the features and array of length 1 with only the terminating
2220 * NULL explicitly disables all the features. In case the parameter is NULL, the features are untouched - left disabled
2221 * 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 +01002222 * @return LY_SUCCESS on success.
2223 * @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 +01002224 * @return LY_ERR on other errors during module compilation.
Radek Krejci77a8bcd2019-09-11 11:20:02 +02002225 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002226LIBYANG_API_DECL LY_ERR lys_set_implemented(struct lys_module *mod, const char **features);
Radek Krejcia3045382018-11-22 14:30:31 +01002227
Radek Krejci084289f2019-07-09 17:35:30 +02002228/**
Radek Krejci0935f412019-08-20 16:15:18 +02002229 * @brief Stringify schema nodetype.
Michal Vaskod43d71a2020-08-07 14:54:58 +02002230 *
Radek Krejci0935f412019-08-20 16:15:18 +02002231 * @param[in] nodetype Nodetype to stringify.
2232 * @return Constant string with the name of the node's type.
2233 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002234LIBYANG_API_DECL const char *lys_nodetype2str(uint16_t nodetype);
Radek Krejci0935f412019-08-20 16:15:18 +02002235
Michal Vaskod43d71a2020-08-07 14:54:58 +02002236/**
2237 * @brief Getter for original XPath expression from a parsed expression.
2238 *
2239 * @param[in] path Parsed expression.
2240 * @return Original string expression.
2241 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01002242LIBYANG_API_DECL const char *lyxp_get_expr(const struct lyxp_expr *path);
Michal Vaskod43d71a2020-08-07 14:54:58 +02002243
Radek Krejci2ff0d572020-05-21 15:27:28 +02002244/** @} schematree */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002245
Radek Krejci70853c52018-10-15 14:46:16 +02002246#ifdef __cplusplus
2247}
2248#endif
2249
Radek Krejci5aeea3a2018-09-05 13:29:36 +02002250#endif /* LY_TREE_SCHEMA_H_ */