blob: 4a3dbec8f01211f0bb5983f27e84581cc33eb8b2 [file] [log] [blame]
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001/**
2 * @file tree_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief libyang representation of YANG schema trees.
5 *
6 * Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_TREE_SCHEMA_H_
16#define LY_TREE_SCHEMA_H_
17
Radek Krejci54579462019-04-30 12:47:06 +020018#define PCRE2_CODE_UNIT_WIDTH 8
19
20#include <pcre2.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020021#include <stdint.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020022#include <stdio.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020023
Radek Krejcie7b95092019-05-15 11:03:07 +020024#include "log.h"
25#include "tree.h"
Radek Krejci084289f2019-07-09 17:35:30 +020026#include "tree_data.h"
Radek Krejcice8c1592018-10-29 15:35:51 +010027
Radek Krejcie7b95092019-05-15 11:03:07 +020028struct ly_ctx;
29
Radek Krejci70853c52018-10-15 14:46:16 +020030#ifdef __cplusplus
31extern "C" {
32#endif
33
Radek Krejci5aeea3a2018-09-05 13:29:36 +020034/**
Radek Krejci0935f412019-08-20 16:15:18 +020035 * @brief Macro to iterate via all elements in a schema tree which can be instantiated in data tree
36 * (skips cases, input, output). This is the opening part to the #LYS_TREE_DFS_END - they always have to be used together.
37 *
38 * The function follows deep-first search algorithm:
39 * <pre>
40 * 1
41 * / \
42 * 2 4
43 * / / \
44 * 3 5 6
45 * </pre>
46 *
47 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
48 * START can be any of the lysc_node* types (including lysc_action and lysc_notif),
49 * ELEM variable must be of the struct lysc_node* type.
50 *
51 * To skip a particular subtree, instead of the continue statement, set LYSC_TREE_DFS_continue
52 * variable to non-zero value.
53 *
54 * Use with opening curly bracket '{' after the macro.
55 *
56 * @param START Pointer to the starting element processed first.
57 * @param ELEM Iterator intended for use in the block.
58 */
59#define LYSC_TREE_DFS_BEGIN(START, ELEM) \
60 { int LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
61 for ((ELEM) = (LYSC_TREE_DFS_next) = (START); \
62 (ELEM); \
63 (ELEM) = (LYSC_TREE_DFS_next), LYSC_TREE_DFS_continue = 0)
64
65/**
66 * @brief Macro to iterate via all elements in a (sub)tree. This is the closing part
67 * to the #LYSC_TREE_DFS_BEGIN - they always have to be used together.
68 *
69 * Use the same parameters for #LYSC_TREE_DFS_BEGIN and #LYSC_TREE_DFS_END. While
70 * START can be a pointer to any of the lysc_node* types (including lysc_action and lysc_notif),
71 * ELEM variable must be pointer to the lysc_node type.
72 *
73 * Use with closing curly bracket '}' after the macro.
74 *
75 * @param START Pointer to the starting element processed first.
76 * @param ELEM Iterator intended for use in the block.
77 */
78
79#define LYSC_TREE_DFS_END(START, ELEM) \
80 /* select element for the next run - children first */ \
81 if (LYSC_TREE_DFS_continue) { \
82 (LYSC_TREE_DFS_next) = NULL; \
83 } else { \
84 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, 0); \
85 }\
86 if (!(LYSC_TREE_DFS_next)) { \
87 /* in case of RPC/action, get also the output children */ \
88 if (!LYSC_TREE_DFS_continue && (ELEM)->nodetype == LYS_ACTION) { \
89 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, LYS_CONFIG_R); \
90 } \
91 if (!(LYSC_TREE_DFS_next)) { \
92 /* no children */ \
93 if ((ELEM) == (struct lysc_node*)(START)) { \
94 /* we are done, (START) has no children */ \
95 break; \
96 } \
97 /* try siblings */ \
98 (LYSC_TREE_DFS_next) = (ELEM)->next; \
99 } \
100 } \
101 while (!(LYSC_TREE_DFS_next)) { \
102 /* parent is already processed, go to its sibling */ \
103 (ELEM) = (ELEM)->parent; \
104 /* no siblings, go back through parents */ \
105 if ((ELEM) == (struct lysc_node*)(START)) { \
106 /* we are done, no next element to process */ \
107 break; \
108 } \
109 if ((ELEM)->nodetype == LYS_ACTION) { \
110 /* there is actually next node as a child of action's output */ \
111 (LYSC_TREE_DFS_next) = (struct lysc_node*)lysc_node_children(ELEM, LYS_CONFIG_R); \
112 } \
113 if (!(LYSC_TREE_DFS_next)) { \
114 (LYSC_TREE_DFS_next) = (ELEM)->next; \
115 } \
116 } } \
117
118/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200119 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
120 */
121typedef enum {
122 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
123 LYS_IN_YANG = 1, /**< YANG schema input format */
Radek Krejci693262f2019-04-29 15:23:20 +0200124 LYS_IN_YIN = 3 /**< YIN schema input format */
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200125} LYS_INFORMAT;
126
127/**
128 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
129 */
130typedef enum {
131 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
132 LYS_OUT_YANG = 1, /**< YANG schema output format */
Radek Krejci693262f2019-04-29 15:23:20 +0200133 LYS_OUT_YIN = 3, /**< YIN schema output format */
134 LYS_OUT_YANG_COMPILED = 2, /**< YANG schema output format of the compiled schema tree */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200135
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200136 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
137 LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
138 LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */
139} LYS_OUTFORMAT;
140
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200141#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
142
Michal Vaskob55f6c12018-09-12 11:13:15 +0200143#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
144#define LYS_CONTAINER 0x0001 /**< container statement node */
145#define LYS_CHOICE 0x0002 /**< choice statement node */
146#define LYS_LEAF 0x0004 /**< leaf statement node */
147#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
148#define LYS_LIST 0x0010 /**< list statement node */
149#define LYS_ANYXML 0x0020 /**< anyxml statement node */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200150#define LYS_ANYDATA 0x0120 /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200151
Radek Krejcie7b95092019-05-15 11:03:07 +0200152#define LYS_ACTION 0x400 /**< RPC or action */
Radek Krejcif3b6fec2019-07-24 15:53:11 +0200153#define LYS_RPC LYS_ACTION /**< RPC or action (for backward compatibility) */
Radek Krejcie7b95092019-05-15 11:03:07 +0200154#define LYS_NOTIF 0x800
155
Radek Krejcia3045382018-11-22 14:30:31 +0100156#define LYS_CASE 0x0040 /**< case statement node */
157#define LYS_USES 0x0080 /**< uses statement node */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200158#define LYS_INPUT 0x100
159#define LYS_OUTPUT 0x200
160#define LYS_INOUT 0x300
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100161#define LYS_GROUPING 0x1000
162#define LYS_AUGMENT 0x2000
163
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200164/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200165 * @brief Extension instance structure parent enumeration
166 */
167typedef enum {
Radek Krejci0935f412019-08-20 16:15:18 +0200168 LYEXT_PAR_MODULE, /**< ::lysc_module */
169 LYEXT_PAR_NODE, /**< ::lysc_node (and the derived structures including ::lysc_action and ::lysc_notif) */
170 LYEXT_PAR_INPUT, /**< ::lysc_action_inout */
171 LYEXT_PAR_OUTPUT, /**< ::lysc_action_inout */
172 LYEXT_PAR_TYPE, /**< ::lysc_type */
173 LYEXT_PAR_TYPE_BIT, /**< ::lysc_type_bitenum_item */
174 LYEXT_PAR_TYPE_ENUM, /**< ::lysc_type_bitenum_item */
175 LYEXT_PAR_FEATURE, /**< ::lysc_feature */
176 LYEXT_PAR_MUST, /**< ::lysc_must */
177 LYEXT_PAR_PATTERN, /**< ::lysc_pattern */
178 LYEXT_PAR_LENGTH, /**< ::lysc_range */
179 LYEXT_PAR_RANGE, /**< ::lysc_range */
180 LYEXT_PAR_WHEN, /**< ::lysc_when */
181 LYEXT_PAR_IDENT, /**< ::lysc_ident */
182 LYEXT_PAR_EXT, /**< ::lysc_ext */
183 LYEXT_PAR_IMPORT, /**< ::lysc_import */
184// LYEXT_PAR_TPDF, /**< ::lysp_tpdf */
185// LYEXT_PAR_EXTINST, /**< ::lysp_ext_instance */
186// LYEXT_PAR_REFINE, /**< ::lysp_refine */
187// LYEXT_PAR_DEVIATION, /**< ::lysp_deviation */
188// LYEXT_PAR_DEVIATE, /**< ::lysp_deviate */
189// LYEXT_PAR_INCLUDE, /**< ::lysp_include */
190// LYEXT_PAR_REVISION, /**< ::lysp_revision */
Radek Krejci0e59c312019-08-15 15:34:15 +0200191} LYEXT_PARENT;
192
193/**
Radek Krejci0935f412019-08-20 16:15:18 +0200194 * @brief Stringify extension instance parent type.
195 * @param[in] type Parent type to stringify.
196 * @return Constant string with the name of the parent statement.
197 */
198const char *lyext_parent2str(LYEXT_PARENT type);
199
200/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200201 * @brief Enum of substatements in which extension instances can appear.
202 */
203typedef enum {
204 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
205 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
206 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
207 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
208 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
209 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
210 lys_node_choice and lys_deviate */
211 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
212 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
213 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
214 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
215 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
216 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
217 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
218 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
219 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
220 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
221 belongs-to's prefix) and lys_import */
222 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
223 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
224 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
225 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
226 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
227 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
228 lys_node_leaflist and lys_deviate */
229 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
230 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
231 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
232 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
233 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
234 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
235 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
236 lys_node_anydata and lys_deviate */
237 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
238 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
239 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
240 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
241 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
242 lys_node_leaflist and lys_deviate */
243 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
244 lys_node_leaflist and lys_deviate */
245 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
246 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
247 LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */
248} LYEXT_SUBSTMT;
249
250/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200251 * @brief YANG import-stmt
252 */
253struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200254 struct lys_module *module; /**< pointer to the imported module
255 (mandatory, but resolved when the referring module is completely parsed) */
256 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200257 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200258 const char *dsc; /**< description */
259 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200260 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200261 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
262};
263
264/**
265 * @brief YANG include-stmt
266 */
267struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100268 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200269 (mandatory, but resolved when the referring module is completely parsed) */
270 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200271 const char *dsc; /**< description */
272 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200273 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200274 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
275};
276
277/**
278 * @brief YANG extension-stmt
279 */
280struct lysp_ext {
281 const char *name; /**< extension name */
282 const char *argument; /**< argument name, NULL if not specified */
283 const char *dsc; /**< description statement */
284 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200285 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200286 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
287};
288
289/**
290 * @brief Helper structure for generic storage of the extension instances content.
291 */
292struct lysp_stmt {
293 const char *stmt; /**< identifier of the statement */
294 const char *arg; /**< statement's argument */
295 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200296 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
David Sedlákb9d75c42019-08-14 10:49:42 +0200297 uint16_t flags; /**< statement flags, can be set to LYS_YIN_ATTR */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200298};
299
David Sedlákae4b4512019-08-14 10:45:56 +0200300#define LYS_YIN 0x1 /**< used to specify input format of extension instance */
301
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200302/**
303 * @brief YANG extension instance
304 */
305struct lysp_ext_instance {
David Sedlákbbd06ca2019-06-27 14:15:38 +0200306 const char *name; /**< extension identifier, including possible prefix */
307 const char *argument; /**< optional value of the extension's argument */
308 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
309 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
310 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
311 the index of that substatement */
David Sedlákae4b4512019-08-14 10:45:56 +0200312 uint8_t yin; /** flag for YIN source format, can be set to LYS_YIN */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200313};
314
315/**
316 * @brief YANG feature-stmt
317 */
318struct lysp_feature {
319 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200320 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200321 const char *dsc; /**< description statement */
322 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200323 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200324 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
325};
326
327/**
328 * @brief YANG identity-stmt
329 */
330struct lysp_ident {
331 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200332 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
333 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200334 const char *dsc; /**< description statement */
335 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200336 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200337 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
338};
339
Michal Vasko71e64ca2018-09-07 16:30:29 +0200340/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200341 * @brief Covers restrictions: range, length, pattern, must
342 */
343struct lysp_restr {
344 const char *arg; /**< The restriction expression/value (mandatory);
345 in case of pattern restriction, the first byte has a special meaning:
346 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
347 const char *emsg; /**< error-message */
348 const char *eapptag; /**< error-app-tag value */
349 const char *dsc; /**< description */
350 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200351 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200352};
353
354/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200355 * @brief YANG revision-stmt
356 */
357struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200358 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200359 const char *dsc; /**< description statement */
360 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200361 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200362};
363
364/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200365 * @brief Enumeration/Bit value definition
366 */
367struct lysp_type_enum {
368 const char *name; /**< name (mandatory) */
369 const char *dsc; /**< description statement */
370 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200371 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200372 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200373 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200374 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
375 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200376};
377
378/**
379 * @brief YANG type-stmt
380 *
381 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
382 */
383struct lysp_type {
384 const char *name; /**< name of the type (mandatory) */
385 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
386 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200387 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
388 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
389 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200390 const char *path; /**< path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200391 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200392 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
393 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200394
Radek Krejci2167ee12018-11-02 16:09:07 +0100395 struct lysc_type *compiled; /**< pointer to the compiled type */
396
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200397 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
398 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100399 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200400};
401
402/**
403 * @brief YANG typedef-stmt
404 */
405struct lysp_tpdf {
406 const char *name; /**< name of the newly defined type (mandatory) */
407 const char *units; /**< units of the newly defined type */
408 const char *dflt; /**< default value of the newly defined type */
409 const char *dsc; /**< description statement */
410 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200411 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200412 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100413 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200414};
415
416/**
417 * @brief YANG grouping-stmt
418 */
419struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100420 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
421 uint16_t nodetype; /**< LYS_GROUPING */
422 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200423 const char *name; /**< grouping name (mandatory) */
424 const char *dsc; /**< description statement */
425 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200426 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
427 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200428 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200429 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
430 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
431 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200432};
433
434/**
435 * @brief YANG when-stmt
436 */
437struct lysp_when {
438 const char *cond; /**< specified condition (mandatory) */
439 const char *dsc; /**< description statement */
440 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200441 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200442};
443
444/**
445 * @brief YANG refine-stmt
446 */
447struct lysp_refine {
448 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
449 const char *dsc; /**< description statement */
450 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200451 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200452 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200453 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200454 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200455 uint32_t min; /**< min-elements constraint */
456 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200457 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200458 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
459};
460
461/**
462 * @brief YANG uses-augment-stmt and augment-stmt
463 */
464struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100465 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
466 uint16_t nodetype; /**< LYS_AUGMENT */
467 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200468 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
469 const char *dsc; /**< description statement */
470 const char *ref; /**< reference statement */
471 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200472 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200473 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200474 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
475 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
476 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200477};
478
479/**
480 * @defgroup deviatetypes Deviate types
481 * @{
482 */
483#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
484#define LYS_DEV_ADD 2 /**< deviate type add */
485#define LYS_DEV_DELETE 3 /**< deviate type delete */
486#define LYS_DEV_REPLACE 4 /**< deviate type replace */
487/** @} */
488
489/**
490 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
491 */
492struct lysp_deviate {
493 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
494 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200495 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200496};
497
498struct lysp_deviate_add {
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)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200504 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
505 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200506 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
507 uint32_t min; /**< min-elements constraint */
508 uint32_t max; /**< max-elements constraint, 0 means unbounded */
509};
510
511struct lysp_deviate_del {
512 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
513 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200514 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200515 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200516 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200517 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
518 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200519};
520
521struct lysp_deviate_rpl {
522 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
523 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200524 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200525 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200526 const char *units; /**< units of the values */
527 const char *dflt; /**< default value */
528 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
529 uint32_t min; /**< min-elements constraint */
530 uint32_t max; /**< max-elements constraint, 0 means unbounded */
531};
532
533struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200534 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200535 const char *dsc; /**< description statement */
536 const char *ref; /**< reference statement */
537 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200538 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200539};
540
Radek Krejci4f28eda2018-11-12 11:46:16 +0100541/**
542 * @defgroup spnodeflags Parsed schema nodes flags
543 * @ingroup snodeflags
544 *
545 * Various flags for parsed schema nodes.
546 *
547 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
548 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200549 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100550 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
551 * 5 - list 10 - input 15 - typedef 20 - deviate
552 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200553 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
554 * 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
555 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
556 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
557 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
558 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
559 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
560 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
561 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
562 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
563 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
564 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
565 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
566 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
567 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
568 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
569 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
570 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
571 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
572 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
573 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
574 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
575 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
576 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
577 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
578 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
579 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
580 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
581 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
582 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
583 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
584 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
585 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
586 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
587 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
588 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
589 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
590 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
591 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200592 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
David Sedlákae4b4512019-08-14 10:45:56 +0200593 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejcid3ca0632019-04-16 16:54:54 +0200594 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100595 *
596 */
597
598/**
599 * @defgroup scnodeflags Compiled schema nodes flags
600 * @ingroup snodeflags
601 *
602 * Various flags for compiled schema nodes.
603 *
604 * 1 - container 6 - anydata/anyxml 11 - output
605 * 2 - choice 7 - case 12 - feature
606 * 3 - leaf 8 - notification 13 - identity
607 * 4 - leaflist 9 - rpc 14 - extension
Radek Krejci693262f2019-04-29 15:23:20 +0200608 * 5 - list 10 - input 15 - bitenum
Radek Krejci4f28eda2018-11-12 11:46:16 +0100609 *
Radek Krejci693262f2019-04-29 15:23:20 +0200610 * 1 1 1 1 1 1
611 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
612 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
613 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | |
614 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
615 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | |
616 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
617 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x| |
618 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
619 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x| |
620 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
621 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x| |
622 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
623 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | | |
624 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
625 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | | |
626 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | |
627 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
628 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | |
629 * LYS_PRESENCE |x| | | | | | | | | | | | | | |
630 * LYS_UNIQUE | | |x| | | | | | | | | | | | |
631 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
632 * 9 LYS_KEY | | |x| | | | | | | | | | | | |
633 * LYS_FENABLED | | | | | | | | | | | |x| | | |
634 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
635 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | | |
636 * LYS_ISENUM | | | | | | | | | | | | | | |x|
Radek Krejci0fe9b512019-07-26 17:51:05 +0200637 * LYS_KEYLESS | | | | |x| | | | | | | | | | |
Radek Krejci693262f2019-04-29 15:23:20 +0200638 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
639 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | | |
640 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci1c0c3442019-07-23 16:08:47 +0200641 * 12 LYS_SET_CONFIG |x|x|x|x|x|x|x| | |x|x| | | | |
Radek Krejci693262f2019-04-29 15:23:20 +0200642 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100643 *
644 */
645
646/**
647 * @defgroup snodeflags Schema nodes flags
648 * @ingroup schematree
649 * @{
650 */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200651#define LYS_CONFIG_W 0x01 /**< config true; */
652#define LYS_CONFIG_R 0x02 /**< config false; */
653#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100654#define LYS_STATUS_CURR 0x04 /**< status current; */
655#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
656#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
657#define LYS_STATUS_MASK 0x1C /**< mask for status value */
658#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100659 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
660 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
661 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
662 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100663#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
664 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
665 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100666#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100667#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, applicable only to ::lysc_node_container */
668#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
669#define LYS_KEY 0x100 /**< flag for leafs being a key of a list, applicable only to ::lysc_node_leaf */
Radek Krejci0fe9b512019-07-26 17:51:05 +0200670#define LYS_KEYLESS 0x200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100671#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysc_feature */
Radek Krejcife909632019-02-12 15:34:42 +0100672#define LYS_ORDBY_SYSTEM 0x80 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
Radek Krejci4f28eda2018-11-12 11:46:16 +0100673 ::lysc_node_list/::lysp_node_list */
674#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
675 ::lysc_node_list/::lysp_node_list */
676#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
677#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
678#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
679#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200680#define LYS_USED_GRP 0x400 /**< internal flag for validating not-instantiated groupings
681 (resp. do not validate again the instantiated groupings). */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100682#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100683#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200684#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100685
686#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
687#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
688#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
689#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
690#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
691#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
692#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
693#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
694#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
695#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100696#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 +0100697 cases of choice. This information is important for refines, since it is prohibited to make leafs
698 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100699 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
700 between own default or the default values taken from the type. */
701#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 +0100702#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 +0100703
Radek Krejcid3ca0632019-04-16 16:54:54 +0200704#define LYS_SINGLEQUOTED 0x100 /**< flag for single-quoted argument of an extension instance's substatement */
705#define LYS_DOUBLEQUOTED 0x200 /**< flag for double-quoted argument of an extension instance's substatement */
706
David Sedlákae4b4512019-08-14 10:45:56 +0200707#define LYS_YIN_ATTR 0x400 /**< flag to identify YIN attribute */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200708
Radek Krejci693262f2019-04-29 15:23:20 +0200709#define LYS_ISENUM 0x200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
710
Radek Krejcife909632019-02-12 15:34:42 +0100711#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100712/** @} */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200713
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200714/**
715 * @brief Generic YANG data node
716 */
717struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100718 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200719 uint16_t nodetype; /**< type of the node (mandatory) */
720 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100721 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200722 const char *name; /**< node name (mandatory) */
723 const char *dsc; /**< description statement */
724 const char *ref; /**< reference statement */
725 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200726 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200727 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200728};
729
730/**
731 * @brief Extension structure of the lysp_node for YANG container
732 */
733struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100734 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200735 uint16_t nodetype; /**< LYS_CONTAINER */
736 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
737 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
738 const char *name; /**< node name (mandatory) */
739 const char *dsc; /**< description statement */
740 const char *ref; /**< reference statement */
741 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200742 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200743 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200744
745 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200746 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200747 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200748 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
749 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200750 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200751 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
752 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200753};
754
755struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100756 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200757 uint16_t nodetype; /**< LYS_LEAF */
758 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
759 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
760 const char *name; /**< node name (mandatory) */
761 const char *dsc; /**< description statement */
762 const char *ref; /**< reference statement */
763 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200764 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200765 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200766
767 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200768 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200769 struct lysp_type type; /**< type of the leaf node (mandatory) */
770 const char *units; /**< units of the leaf's type */
771 const char *dflt; /**< default value */
772};
773
774struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100775 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200776 uint16_t nodetype; /**< LYS_LEAFLIST */
777 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
778 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
779 const char *name; /**< node name (mandatory) */
780 const char *dsc; /**< description statement */
781 const char *ref; /**< reference statement */
782 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200783 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200784 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200785
786 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200787 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200788 struct lysp_type type; /**< type of the leaf node (mandatory) */
789 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200790 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200791 uint32_t min; /**< min-elements constraint */
792 uint32_t max; /**< max-elements constraint, 0 means unbounded */
793};
794
795struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100796 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200797 uint16_t nodetype; /**< LYS_LIST */
798 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
799 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
800 const char *name; /**< node name (mandatory) */
801 const char *dsc; /**< description statement */
802 const char *ref; /**< reference statement */
803 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200804 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200805 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200806
807 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200808 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200809 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200810 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
811 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200812 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200813 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
814 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200815 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200816 uint32_t min; /**< min-elements constraint */
817 uint32_t max; /**< max-elements constraint, 0 means unbounded */
818};
819
820struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100821 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200822 uint16_t nodetype; /**< LYS_CHOICE */
823 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
824 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
825 const char *name; /**< node name (mandatory) */
826 const char *dsc; /**< description statement */
827 const char *ref; /**< reference statement */
828 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200829 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200830 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200831
832 /* choice */
833 struct lysp_node *child; /**< list of data nodes (linked list) */
834 const char* dflt; /**< default case */
835};
836
837struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100838 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200839 uint16_t nodetype; /**< LYS_CASE */
840 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
841 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
842 const char *name; /**< node name (mandatory) */
843 const char *dsc; /**< description statement */
844 const char *ref; /**< reference statement */
845 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200846 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200847 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200848
849 /* case */
850 struct lysp_node *child; /**< list of data nodes (linked list) */
851};
852
853struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100854 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200855 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
856 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
857 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
858 const char *name; /**< node name (mandatory) */
859 const char *dsc; /**< description statement */
860 const char *ref; /**< reference statement */
861 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200862 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200863 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200864
865 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200866 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200867};
868
869struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100870 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200871 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200872 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
873 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
874 const char *name; /**< grouping name reference (mandatory) */
875 const char *dsc; /**< description statement */
876 const char *ref; /**< reference statement */
877 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200878 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200879 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200880
881 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200882 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
883 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200884};
885
886/**
887 * @brief YANG input-stmt and output-stmt
888 */
889struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100890 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
891 uint16_t nodetype; /**< LYS_INOUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200892 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
893 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
894 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200895 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200896 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200897};
898
899/**
900 * @brief YANG rpc-stmt and action-stmt
901 */
902struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100903 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
904 uint16_t nodetype; /**< LYS_ACTION */
905 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200906 const char *name; /**< grouping name reference (mandatory) */
907 const char *dsc; /**< description statement */
908 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200909 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200910 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
911 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100912 struct lysp_action_inout input; /**< RPC's/Action's input */
913 struct lysp_action_inout output; /**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200914 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200915};
916
917/**
918 * @brief YANG notification-stmt
919 */
920struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100921 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
922 uint16_t nodetype; /**< LYS_NOTIF */
923 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200924 const char *name; /**< grouping name reference (mandatory) */
925 const char *dsc; /**< description statement */
926 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200927 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200928 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
929 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
930 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200931 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200932 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200933};
934
935/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200936 * @brief supported YANG schema version values
937 */
938typedef enum LYS_VERSION {
939 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
940 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
941 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
942} LYS_VERSION;
943
944/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200945 * @brief Printable YANG schema tree structure representing YANG module.
946 *
947 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
948 */
949struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100950 struct lys_module *mod; /**< covering module structure */
951
Radek Krejcib7db73a2018-10-24 14:18:40 +0200952 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
953 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200954 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
955 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200956 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
957 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
958 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
959 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
960 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200961 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200962 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
963 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
964 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
965 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
966 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200967
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100968 uint8_t parsing:1; /**< flag for circular check */
969};
970
971struct lysp_submodule {
972 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
973
974 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
975 in the list is always the last (newest) revision of the module */
976 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
977 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
978 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
979 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
980 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
981 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
982 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
983 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
984 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
985 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
986 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
987 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
988 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
989
990 uint8_t parsing:1; /**< flag for circular check */
991
Radek Krejci086c7132018-10-26 15:29:04 +0200992 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
993 1 - the latest revision in searchdirs was not searched yet and this is the
994 latest revision in the current context
995 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100996 const char *name; /**< name of the module (mandatory) */
997 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
998 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
999 const char *org; /**< party/company responsible for the module */
1000 const char *contact; /**< contact information for the module */
1001 const char *dsc; /**< description of the module */
1002 const char *ref; /**< cross-reference for the module */
Radek Krejci086c7132018-10-26 15:29:04 +02001003 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001004};
1005
1006/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +02001007 * @brief Free the printable YANG schema tree structure.
1008 *
1009 * @param[in] module Printable YANG schema tree structure to free.
1010 */
1011void lysp_module_free(struct lysp_module *module);
1012
1013/**
Radek Krejci0e59c312019-08-15 15:34:15 +02001014 * @brief Compiled YANG extension-stmt
1015 */
1016struct lysc_ext {
1017 const char *name; /**< extension name */
1018 const char *argument; /**< argument name, NULL if not specified */
Radek Krejci0e59c312019-08-15 15:34:15 +02001019 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1020 struct lyext_plugin *plugin; /**< Plugin implementing the specific extension */
Radek Krejci0935f412019-08-20 16:15:18 +02001021 struct lys_module *module; /**< module structure */
Radek Krejci0e59c312019-08-15 15:34:15 +02001022 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
1023};
1024
1025/**
Radek Krejcice8c1592018-10-29 15:35:51 +01001026 * @brief YANG extension instance
1027 */
1028struct lysc_ext_instance {
Radek Krejci0935f412019-08-20 16:15:18 +02001029 struct lysc_ext *def; /**< pointer to the extension definition */
Radek Krejcice8c1592018-10-29 15:35:51 +01001030 void *parent; /**< pointer to the parent element holding the extension instance(s), use
1031 ::lysc_ext_instance#parent_type to access the schema element */
1032 const char *argument; /**< optional value of the extension's argument */
1033 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
1034 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
1035 this identifies the index of the substatement for this extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +01001036 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001037 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0e59c312019-08-15 15:34:15 +02001038 void *data; /**< private plugins's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +01001039};
1040
1041/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001042 * @brief Compiled YANG if-feature-stmt
1043 */
1044struct lysc_iffeature {
1045 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
1046 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
1047};
1048
1049/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001050 * @brief YANG import-stmt
1051 */
1052struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +01001053 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +02001054 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001055 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +02001056};
1057
1058/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001059 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001060 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001061struct lysc_when {
1062 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001063 const char *dsc; /**< description */
1064 const char *ref; /**< reference */
Radek Krejci00b874b2019-02-12 10:54:50 +01001065 struct lysc_node *context; /**< context node for evaluating the expression */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001066 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001067 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001068};
1069
1070/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001071 * @brief YANG identity-stmt
1072 */
1073struct lysc_ident {
1074 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +01001075 const char *dsc; /**< description */
1076 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001077 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001078 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
1079 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001080 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001081 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1082};
1083
1084/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001085 * @brief YANG feature-stmt
1086 */
1087struct lysc_feature {
1088 const char *name; /**< feature name (mandatory) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001089 const char *dsc; /**< description */
1090 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001091 struct lys_module *module; /**< module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001092 struct lysc_feature **depfeatures;/**< list of pointers to other features depending on this one ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001093 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001094 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001095 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
1096 #LYS_FENABLED values allowed */
1097};
1098
Radek Krejci151a5b72018-10-19 14:21:44 +02001099/**
1100 * @defgroup ifftokens if-feature expression tokens
1101 * Tokens of if-feature expression used in ::lysc_iffeature#expr
1102 *
1103 * @{
1104 */
1105#define LYS_IFF_NOT 0x00 /**< operand "not" */
1106#define LYS_IFF_AND 0x01 /**< operand "and" */
1107#define LYS_IFF_OR 0x02 /**< operand "or" */
1108#define LYS_IFF_F 0x03 /**< feature */
1109/**
1110 * @}
1111 */
1112
1113/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001114 * @brief Compiled YANG revision statement
1115 */
1116struct lysc_revision {
1117 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1118 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1119};
1120
Radek Krejci2167ee12018-11-02 16:09:07 +01001121struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001122 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001123 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001124 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1125 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001126 };
Radek Krejci693262f2019-04-29 15:23:20 +02001127 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001128 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1129 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001130 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001131 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001132 const char *dsc; /**< description */
1133 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001134 const char *emsg; /**< error-message */
1135 const char *eapptag; /**< error-app-tag value */
1136 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1137};
1138
1139struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001140 const char *expr; /**< original, not compiled, regular expression */
1141 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001142 const char *dsc; /**< description */
1143 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001144 const char *emsg; /**< error-message */
1145 const char *eapptag; /**< error-app-tag value */
1146 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4586a022018-11-13 11:29:26 +01001147 uint32_t inverted:1; /**< invert-match flag */
1148 uint32_t refcount:31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001149};
1150
1151struct lysc_must {
1152 struct lys_module *module; /**< module where the must was defined */
1153 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001154 const char *dsc; /**< description */
1155 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001156 const char *emsg; /**< error-message */
1157 const char *eapptag; /**< error-app-tag value */
1158 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1159};
1160
1161struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001162 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001163 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001164 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001165 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001166 LY_DATA_TYPE basetype; /**< Base type of the type */
1167 uint32_t refcount; /**< reference counter for type sharing */
1168};
1169
1170struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001171 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001172 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001173 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001174 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001175 LY_DATA_TYPE basetype; /**< Base type of the type */
1176 uint32_t refcount; /**< reference counter for type sharing */
1177 struct lysc_range *range; /**< Optional range limitation */
1178};
1179
1180struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001181 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001182 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001183 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001184 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001185 LY_DATA_TYPE basetype; /**< Base type of the type */
1186 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001187 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001188 struct lysc_range *range; /**< Optional range limitation */
1189};
1190
1191struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001192 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001193 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001194 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001195 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001196 LY_DATA_TYPE basetype; /**< Base type of the type */
1197 uint32_t refcount; /**< reference counter for type sharing */
1198 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001199 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001200};
1201
Radek Krejci693262f2019-04-29 15:23:20 +02001202struct lysc_type_bitenum_item {
1203 const char *name; /**< enumeration identifier */
1204 const char *dsc; /**< description */
1205 const char *ref; /**< reference */
1206 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1207 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1208 union {
1209 int32_t value; /**< integer value associated with the enumeration */
1210 uint32_t position; /**< non-negative integer value associated with the bit */
1211 };
1212 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1213 values are allowed */
1214};
1215
Radek Krejci2167ee12018-11-02 16:09:07 +01001216struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001217 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001218 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001219 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001220 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001221 LY_DATA_TYPE basetype; /**< Base type of the type */
1222 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001223 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1224};
1225
1226struct lysc_type_bits {
1227 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1228 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001229 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001230 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci693262f2019-04-29 15:23:20 +02001231 LY_DATA_TYPE basetype; /**< Base type of the type */
1232 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001233 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1234 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001235};
1236
1237struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001238 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001239 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001240 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001241 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001242 LY_DATA_TYPE basetype; /**< Base type of the type */
1243 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejcia3045382018-11-22 14:30:31 +01001244 const char* path; /**< target path */
Radek Krejci96a0bfd2018-11-22 15:25:06 +01001245 struct lys_module *path_context; /**< module where the path is defined, so it provides context to resolve prefixes */
Radek Krejci412ddfa2018-11-23 11:44:11 +01001246 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001247 uint8_t require_instance; /**< require-instance flag */
1248};
1249
1250struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001251 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001252 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001253 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001254 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001255 LY_DATA_TYPE basetype; /**< Base type of the type */
1256 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001257 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001258 mandatory (at least 1 item) */
1259};
1260
1261struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001262 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001263 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001264 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001265 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001266 LY_DATA_TYPE basetype; /**< Base type of the type */
1267 uint32_t refcount; /**< reference counter for type sharing */
1268 uint8_t require_instance; /**< require-instance flag */
1269};
1270
Radek Krejci2167ee12018-11-02 16:09:07 +01001271struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001272 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001273 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001274 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001275 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001276 LY_DATA_TYPE basetype; /**< Base type of the type */
1277 uint32_t refcount; /**< reference counter for type sharing */
1278 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1279};
1280
1281struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001282 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001283 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001284 struct lys_module *dflt_mod; /**< module where the lysc_type::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcie7b95092019-05-15 11:03:07 +02001285 struct lysc_type_plugin *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
Radek Krejci2167ee12018-11-02 16:09:07 +01001286 LY_DATA_TYPE basetype; /**< Base type of the type */
1287 uint32_t refcount; /**< reference counter for type sharing */
1288 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001289};
1290
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001291struct lysc_action_inout {
1292 struct lysc_node *data; /**< first child node (linked list) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001293 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1294};
1295
Radek Krejci056d0a82018-12-06 16:57:25 +01001296struct lysc_action {
1297 uint16_t nodetype; /**< LYS_ACTION */
1298 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001299 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001300 struct lysp_action *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1301 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1302
Radek Krejcifc11bd72019-04-11 16:00:05 +02001303 struct lysc_ext_instance *input_exts; /**< list of the extension instances of input ([sized array](@ref sizedarrays)) */
1304 struct lysc_ext_instance *output_exts; /**< list of the extension instances of outpu ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001305
Radek Krejci056d0a82018-12-06 16:57:25 +01001306 const char *name; /**< action/RPC name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001307 const char *dsc; /**< description */
1308 const char *ref; /**< reference */
1309
Radek Krejcifc11bd72019-04-11 16:00:05 +02001310 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1311 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1312
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001313 struct lysc_action_inout input; /**< RPC's/action's input */
1314 struct lysc_action_inout output; /**< RPC's/action's output */
1315
Radek Krejci056d0a82018-12-06 16:57:25 +01001316};
1317
1318struct lysc_notif {
1319 uint16_t nodetype; /**< LYS_NOTIF */
1320 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001321 struct lys_module *module; /**< module structure */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001322 struct lysp_notif *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001323 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1324
Radek Krejcifc11bd72019-04-11 16:00:05 +02001325 struct lysc_node *data; /**< first child node (linked list) */
1326 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1327
Radek Krejci056d0a82018-12-06 16:57:25 +01001328 const char *name; /**< Notification name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001329 const char *dsc; /**< description */
1330 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001331
1332 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1333 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001334};
1335
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001336/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001337 * @brief Compiled YANG data node
1338 */
1339struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001340 uint16_t nodetype; /**< type of the node (mandatory) */
1341 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001342 struct lys_module *module; /**< module structure */
1343 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1344 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1345 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1346 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1347 never NULL. If there is no sibling node, pointer points to the node
1348 itself. In case of the first node, this pointer points to the last
1349 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001350 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001351 const char *dsc; /**< description */
1352 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001353 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001354 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001355 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001356};
1357
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001358struct lysc_node_container {
1359 uint16_t nodetype; /**< LYS_CONTAINER */
1360 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1361 struct lys_module *module; /**< module structure */
1362 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1363 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1364 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1365 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1366 never NULL. If there is no sibling node, pointer points to the node
1367 itself. In case of the first node, this pointer points to the last
1368 node in the list. */
1369 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001370 const char *dsc; /**< description */
1371 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001372 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001373 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001374 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001375
1376 struct lysc_node *child; /**< first child node (linked list) */
1377 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1378 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1379 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001380};
1381
Radek Krejcia3045382018-11-22 14:30:31 +01001382struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001383 uint16_t nodetype; /**< LYS_CASE */
1384 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1385 struct lys_module *module; /**< module structure */
1386 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1387 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1388 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1389 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1390 never NULL. If there is no sibling node, pointer points to the node
1391 itself. In case of the first node, this pointer points to the last
1392 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001393 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001394 const char *dsc; /**< description */
1395 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001396 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001397 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001398 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001399
Radek Krejcia3045382018-11-22 14:30:31 +01001400 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 +01001401 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001402};
1403
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001404struct lysc_node_choice {
1405 uint16_t nodetype; /**< LYS_CHOICE */
1406 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1407 struct lys_module *module; /**< module structure */
1408 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1409 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1410 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1411 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1412 never NULL. If there is no sibling node, pointer points to the node
1413 itself. In case of the first node, this pointer points to the last
1414 node in the list. */
1415 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001416 const char *dsc; /**< description */
1417 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001418 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001419 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001420 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001421
Radek Krejcia9026eb2018-12-12 16:04:47 +01001422 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1423 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1424 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001425 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001426};
1427
1428struct lysc_node_leaf {
1429 uint16_t nodetype; /**< LYS_LEAF */
1430 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1431 struct lys_module *module; /**< module structure */
1432 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1433 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1434 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1435 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1436 never NULL. If there is no sibling node, pointer points to the node
1437 itself. In case of the first node, this pointer points to the last
1438 node in the list. */
1439 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001440 const char *dsc; /**< description */
1441 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001442 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001443 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001444 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001445
1446 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1447 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001448
Radek Krejci4f28eda2018-11-12 11:46:16 +01001449 const char *units; /**< units of the leaf's type */
Radek Krejcia1911222019-07-22 17:24:50 +02001450 struct lyd_value *dflt; /**< default value */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001451 struct lys_module *dflt_mod; /**< module where the lysc_node_leaf::dflt value was defined (needed to correctly map prefixes). */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001452};
1453
1454struct lysc_node_leaflist {
1455 uint16_t nodetype; /**< LYS_LEAFLIST */
1456 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1457 struct lys_module *module; /**< module structure */
1458 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1459 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1460 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1461 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1462 never NULL. If there is no sibling node, pointer points to the node
1463 itself. In case of the first node, this pointer points to the last
1464 node in the list. */
1465 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001466 const char *dsc; /**< description */
1467 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001468 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001469 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001470 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001471
1472 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1473 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1474
Radek Krejci0e5d8382018-11-28 16:37:53 +01001475 const char *units; /**< units of the leaf's type */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001476 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values */
1477 struct lys_module **dflts_mods; /**< list ([sized array](@ref sizedarrays)) of modules where the lysc_node_leaflist::dflts values were defined
1478 (needed to correctly map prefixes). */
Radek Krejci0e5d8382018-11-28 16:37:53 +01001479 uint32_t min; /**< min-elements constraint */
1480 uint32_t max; /**< max-elements constraint */
1481
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001482};
1483
1484struct lysc_node_list {
1485 uint16_t nodetype; /**< LYS_LIST */
1486 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1487 struct lys_module *module; /**< module structure */
1488 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1489 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1490 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1491 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1492 never NULL. If there is no sibling node, pointer points to the node
1493 itself. In case of the first node, this pointer points to the last
1494 node in the list. */
1495 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001496 const char *dsc; /**< description */
1497 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001498 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001499 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001500 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001501
1502 struct lysc_node *child; /**< first child node (linked list) */
1503 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1504 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1505 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1506
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001507 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1508 uint32_t min; /**< min-elements constraint */
1509 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001510};
1511
1512struct lysc_node_anydata {
1513 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1514 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1515 struct lys_module *module; /**< module structure */
1516 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1517 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1518 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1519 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1520 never NULL. If there is no sibling node, pointer points to the node
1521 itself. In case of the first node, this pointer points to the last
1522 node in the list. */
1523 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001524 const char *dsc; /**< description */
1525 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001526 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001527 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001528 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9800fb82018-12-13 14:26:23 +01001529
1530 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001531};
1532
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001533/**
1534 * @brief Compiled YANG schema tree structure representing YANG module.
1535 *
1536 * Semantically validated YANG schema tree for data tree parsing.
1537 * Contains only the necessary information for the data validation.
1538 */
1539struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001540 struct lys_module *mod; /**< covering module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001541 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001542
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001543 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001544 struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1545 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1546 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1547 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci0935f412019-08-20 16:15:18 +02001548 struct lysc_ext *extensions; /**< list of the extension definitions ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001549 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001550};
1551
1552/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001553 * @brief Get the groupings sized array of the given (parsed) schema node.
1554 * Decides the node's type and in case it has a groupings array, returns it.
1555 * @param[in] node Node to examine.
1556 * @return The node's groupings sized array if any, NULL otherwise.
1557 */
1558const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1559
1560/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001561 * @brief Get the typedefs sized array of the given (parsed) schema node.
1562 * Decides the node's type and in case it has a typedefs array, returns it.
1563 * @param[in] node Node to examine.
1564 * @return The node's typedefs sized array if any, NULL otherwise.
1565 */
1566const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1567
1568/**
1569 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1570 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1571 * @param[in] node Node to examine.
1572 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1573 */
1574const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1575
1576/**
1577 * @brief Get the Notifications sized array of the given (parsed) schema node.
1578 * Decides the node's type and in case it has a Notifications array, returns it.
1579 * @param[in] node Node to examine.
1580 * @return The node's Notifications sized array if any, NULL otherwise.
1581 */
1582const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1583
1584/**
1585 * @brief Get the children linked list of the given (parsed) schema node.
1586 * Decides the node's type and in case it has a children list, returns it.
1587 * @param[in] node Node to examine.
1588 * @return The node's children linked list if any, NULL otherwise.
1589 */
1590const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1591
1592/**
1593 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1594 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1595 * @param[in] node Node to examine.
1596 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1597 */
1598const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1599
1600/**
1601 * @brief Get the Notifications sized array of the given (compiled) schema node.
1602 * Decides the node's type and in case it has a Notifications array, returns it.
1603 * @param[in] node Node to examine.
1604 * @return The node's Notifications sized array if any, NULL otherwise.
1605 */
1606const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1607
1608/**
1609 * @brief Get the children linked list of the given (compiled) schema node.
1610 * Decides the node's type and in case it has a children list, returns it.
1611 * @param[in] node Node to examine.
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001612 * @param[in] flags Config flag to distinguish input (LYS_CONFIG_W) and output (LYS_CONFIG_R) data in case of RPC/action node.
Radek Krejci056d0a82018-12-06 16:57:25 +01001613 * @return The node's children linked list if any, NULL otherwise.
1614 */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001615const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Radek Krejci056d0a82018-12-06 16:57:25 +01001616
1617/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001618 * @brief Get how the if-feature statement currently evaluates.
1619 *
1620 * @param[in] iff Compiled if-feature statement to evaluate.
1621 * @return If the statement evaluates to true, 1 is returned. 0 is returned when the statement evaluates to false.
1622 */
1623int lysc_iffeature_value(const struct lysc_iffeature *iff);
1624
1625/**
1626 * @brief Get the current status of the provided feature.
1627 *
1628 * @param[in] feature Compiled feature statement to examine.
1629 * @return
1630 * - 1 if feature is enabled,
1631 * - 0 if feature is disabled,
1632 * - -1 in case of error (invalid argument)
1633 */
1634int lysc_feature_value(const struct lysc_feature *feature);
1635
1636/**
Radek Krejci327de162019-06-14 12:52:07 +02001637 * @brief Generate path of the given node in the requested format.
1638 *
1639 * @param[in] node Schema path of this node will be generated.
1640 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001641 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
1642 * If NULL, memory for the complete path is allocated.
1643 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02001644 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001645 * 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 +02001646 */
Radek Krejci1c0c3442019-07-23 16:08:47 +02001647char *lysc_path(struct lysc_node *node, LY_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02001648
1649/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001650 * @brief Available YANG schema tree structures representing YANG module.
1651 */
1652struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001653 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
1654 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01001655 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001656 const char *ns; /**< namespace of the module (module - mandatory) */
1657 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
1658 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1659 const char *org; /**< party/company responsible for the module */
1660 const char *contact; /**< contact information for the module */
1661 const char *dsc; /**< description of the module */
1662 const char *ref; /**< cross-reference for the module */
1663
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001664 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01001665 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
1666 Available only for implemented modules. */
1667 struct lysc_feature *off_features;/**< List of pre-compiled features of the module in non implemented modules ([sized array](@ref sizedarrays)).
1668 These features are always disabled and cannot be enabled until the module
1669 become implemented. The features are present in this form to allow their linkage
1670 from if-feature statements of the compiled schemas and their proper use in case
1671 the module became implemented in future (no matter if implicitly via augment/deviate
1672 or explicitly via ly_ctx_module_implement()). */
Radek Krejci0935f412019-08-20 16:15:18 +02001673 struct lysc_ext *off_extensions; /**< List of pre-compiled extension definitions of the module in non-implemented modules
1674 ([sized array](@ref sizedarrays)). These extensions are prepared to be linked with the extension instances,
1675 but they are not implemented (connected with any extension plugin). In case the module become
1676 implemented, the list is moved into the compiled module structure and available extension plugins
1677 are connected with the appropriate extension definision. */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001678
Radek Krejci95710c92019-02-11 15:49:55 +01001679 uint8_t implemented; /**< flag if the module is implemented, not just imported. The module is implemented if
1680 the flag has non-zero value. Specific values are used internally:
1681 1 - implemented module
1682 2 - recently implemented module by dependency, it can be reverted in rollback procedure */
1683 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001684 1 - the latest revision in searchdirs was not searched yet and this is the
1685 latest revision in the current context
1686 2 - searchdirs were searched and this is the latest available revision */
1687 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001688};
1689
Radek Krejci151a5b72018-10-19 14:21:44 +02001690/**
1691 * @brief Enable specified feature in the module
1692 *
1693 * By default, when the module is loaded by libyang parser, all features are disabled.
1694 *
Radek Krejcica3db002018-11-01 10:31:01 +01001695 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
1696 * enabling all features on the following feature set will fail since it is not possible to enable both features
1697 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
1698 * is untouched.
1699 *
1700 * feature f1;
1701 * feature f2 { if-feature 'not f1';}
1702 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001703 * @param[in] module Module where the feature will be enabled.
1704 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
1705 * @return LY_ERR value.
1706 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001707LY_ERR lys_feature_enable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001708
1709/**
1710 * @brief Disable specified feature in the module
1711 *
1712 * By default, when the module is loaded by libyang parser, all features are disabled.
1713 *
1714 * @param[in] module Module where the feature will be disabled.
1715 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
1716 * @return LY_ERR value
1717 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001718LY_ERR lys_feature_disable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001719
1720/**
1721 * @brief Get the current status of the specified feature in the module.
1722 *
1723 * @param[in] module Module where the feature is defined.
1724 * @param[in] feature Name of the feature to inspect.
1725 * @return
1726 * - 1 if feature is enabled,
1727 * - 0 if feature is disabled,
1728 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
1729 */
1730int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001731
1732/**
Radek Krejci86d106e2018-10-18 09:53:19 +02001733 * @brief Load a schema into the specified context.
1734 *
1735 * @param[in] ctx libyang context where to process the data model.
1736 * @param[in] data The string containing the dumped data model in the specified
1737 * format.
1738 * @param[in] format Format of the input data (YANG or YIN).
1739 * @return Pointer to the data model structure or NULL on error.
1740 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001741struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001742
1743/**
1744 * @brief Read a schema from file descriptor into the specified context.
1745 *
1746 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
1747 *
1748 * @param[in] ctx libyang context where to process the data model.
1749 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
1750 * in the specified format.
1751 * @param[in] format Format of the input data (YANG or YIN).
1752 * @return Pointer to the data model structure or NULL on error.
1753 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001754struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001755
1756/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001757 * @brief Read a schema into the specified context from a file.
Radek Krejci86d106e2018-10-18 09:53:19 +02001758 *
1759 * @param[in] ctx libyang context where to process the data model.
1760 * @param[in] path Path to the file with the model in the specified format.
1761 * @param[in] format Format of the input data (YANG or YIN).
1762 * @return Pointer to the data model structure or NULL on error.
1763 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001764struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001765
1766/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001767 * @brief Search for the schema file in the specified searchpaths.
1768 *
1769 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
1770 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
1771 * result of the ly_ctx_get_searchdirs().
1772 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
1773 * @param[in] name Name of the schema to find.
1774 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
1775 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
1776 * complying the provided restriction is found, NULL is set.
1777 * @param[out] format Optional output variable containing expected format of the schema document according to the
1778 * file suffix.
1779 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
1780 */
1781LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
1782
1783/**
Radek Krejcia3045382018-11-22 14:30:31 +01001784 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
1785 * be from an augment.
1786 *
1787 * lys_getnext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
1788 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
1789 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
1790 * \p parent and \p module parameters.
1791 *
1792 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
1793 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
1794 * all the schema nodes are iteratively returned.
1795 *
1796 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
1797 * @param[in] parent Parent of the subtree where the function starts processing.
1798 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
1799 * module must be specified.
1800 * @param[in] options [ORed options](@ref sgetnextflags).
1801 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
1802 */
1803const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
1804 const struct lysc_module *module, int options);
1805
1806/**
1807 * @defgroup sgetnextflags lys_getnext() flags
1808 * @ingroup schematree
1809 *
1810 * @{
1811 */
1812#define LYS_GETNEXT_WITHCHOICE 0x01 /**< lys_getnext() option to allow returning #LYS_CHOICE nodes instead of looking into them */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001813#define LYS_GETNEXT_NOCHOICE 0x02 /**< lys_getnext() option to ignore (kind of conditional) nodes within choice node */
Radek Krejci056d0a82018-12-06 16:57:25 +01001814#define LYS_GETNEXT_WITHCASE 0x04 /**< lys_getnext() option to allow returning #LYS_CASE nodes instead of looking into them */
Radek Krejcia3045382018-11-22 14:30:31 +01001815#define LYS_GETNEXT_INTONPCONT 0x40 /**< lys_getnext() option to look into non-presence container, instead of returning container itself */
1816#define LYS_GETNEXT_NOSTATECHECK 0x100 /**< lys_getnext() option to skip checking module validity (import-only, disabled) and
1817 relevant if-feature conditions state */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001818#define LYS_GETNEXT_OUTPUT 0x200 /**< lys_getnext() option to provide RPC's/action's output schema nodes instead of input schema nodes
1819 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01001820/** @} sgetnextflags */
1821
1822/**
1823 * @brief Get child node according to the specified criteria.
1824 *
1825 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
1826 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
1827 * @param[in] name Name of the node to find.
1828 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
1829 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
1830 * Used as a bitmask, so multiple nodetypes can be specified.
1831 * @param[in] options [ORed options](@ref sgetnextflags).
1832 * @return Found node if any.
1833 */
1834const struct lysc_node *lys_child(const struct lysc_node *parent, const struct lys_module *module,
1835 const char *name, size_t name_len, uint16_t nodetype, int options);
1836
1837/**
1838 * @brief Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statement
1839 * affecting the node.
1840 *
1841 * @param[in] node Schema node to check.
1842 * @param[in] recursive - 0 to check if-feature only in the \p node schema node,
1843 * - 1 to check if-feature in all ascendant schema nodes until there is a node possibly having an instance in a data tree
1844 * @return - NULL if enabled,
1845 * - pointer to the node with the unsatisfied (disabling) if-feature expression.
1846 */
1847const struct lysc_iffeature *lys_is_disabled(const struct lysc_node *node, int recursive);
1848
Radek Krejci084289f2019-07-09 17:35:30 +02001849/**
1850 * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
1851 *
1852 * This function check just the type's restriction, if you want to check also the data tree context (e.g. in case of
1853 * require-instance restriction), use lyd_value_validate().
1854 *
1855 * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
1856 * @param[in] node Schema node for the @p value.
1857 * @param[in] value String value to be checked.
1858 * @param[in] value_len Length of the given @p value (mandatory).
1859 * @param[in] get_prefix Callback function to resolve prefixes used in the @p value string.
1860 * @param[in] get_prefix_data Private data for the @p get_prefix callback.
1861 * @param[in] format Input format of the @p value.
1862 * @return LY_SUCCESS on success
1863 * @return LY_ERR value if an error occurred.
1864 */
1865LY_ERR lys_value_validate(struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len,
1866 ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format);
1867
Radek Krejci0935f412019-08-20 16:15:18 +02001868/**
1869 * @brief Stringify schema nodetype.
1870 * @param[in] nodetype Nodetype to stringify.
1871 * @return Constant string with the name of the node's type.
1872 */
1873const char *lys_nodetype2str(uint16_t nodetype);
1874
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001875/** @} */
1876
Radek Krejci70853c52018-10-15 14:46:16 +02001877#ifdef __cplusplus
1878}
1879#endif
1880
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001881#endif /* LY_TREE_SCHEMA_H_ */