blob: 9ba9db3bbd643f05f4b7eb547988810bebb57a2b [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 Krejci0af5f5d2018-09-07 15:00:30 +020035 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
36 */
37typedef enum {
38 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
39 LYS_IN_YANG = 1, /**< YANG schema input format */
Radek Krejci693262f2019-04-29 15:23:20 +020040 LYS_IN_YIN = 3 /**< YIN schema input format */
Radek Krejci0af5f5d2018-09-07 15:00:30 +020041} LYS_INFORMAT;
42
43/**
44 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
45 */
46typedef enum {
47 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
48 LYS_OUT_YANG = 1, /**< YANG schema output format */
Radek Krejci693262f2019-04-29 15:23:20 +020049 LYS_OUT_YIN = 3, /**< YIN schema output format */
50 LYS_OUT_YANG_COMPILED = 2, /**< YANG schema output format of the compiled schema tree */
Radek Krejcid3ca0632019-04-16 16:54:54 +020051
Radek Krejci0af5f5d2018-09-07 15:00:30 +020052 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
53 LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
54 LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */
55} LYS_OUTFORMAT;
56
Radek Krejci5aeea3a2018-09-05 13:29:36 +020057#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
58
Michal Vaskob55f6c12018-09-12 11:13:15 +020059#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
60#define LYS_CONTAINER 0x0001 /**< container statement node */
61#define LYS_CHOICE 0x0002 /**< choice statement node */
62#define LYS_LEAF 0x0004 /**< leaf statement node */
63#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
64#define LYS_LIST 0x0010 /**< list statement node */
65#define LYS_ANYXML 0x0020 /**< anyxml statement node */
Michal Vaskob55f6c12018-09-12 11:13:15 +020066#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 +020067
Radek Krejcie7b95092019-05-15 11:03:07 +020068#define LYS_ACTION 0x400 /**< RPC or action */
Radek Krejcif3b6fec2019-07-24 15:53:11 +020069#define LYS_RPC LYS_ACTION /**< RPC or action (for backward compatibility) */
Radek Krejcie7b95092019-05-15 11:03:07 +020070#define LYS_NOTIF 0x800
71
Radek Krejcia3045382018-11-22 14:30:31 +010072#define LYS_CASE 0x0040 /**< case statement node */
73#define LYS_USES 0x0080 /**< uses statement node */
Radek Krejcid3ca0632019-04-16 16:54:54 +020074#define LYS_INPUT 0x100
75#define LYS_OUTPUT 0x200
76#define LYS_INOUT 0x300
Radek Krejci6d9b9b52018-11-02 12:43:39 +010077#define LYS_GROUPING 0x1000
78#define LYS_AUGMENT 0x2000
79
Radek Krejci5aeea3a2018-09-05 13:29:36 +020080/**
Radek Krejci0e59c312019-08-15 15:34:15 +020081 * @brief Extension instance structure parent enumeration
82 */
83typedef enum {
84 LYEXT_PAR_MODULE, /**< ::lys_module or ::lys_submodule */
85 LYEXT_PAR_NODE, /**< ::lys_node (and the derived structures) */
86 LYEXT_PAR_TPDF, /**< ::lys_tpdf */
87 LYEXT_PAR_TYPE, /**< ::lys_type */
88 LYEXT_PAR_TYPE_BIT, /**< ::lys_type_bit */
89 LYEXT_PAR_TYPE_ENUM, /**< ::lys_type_enum */
90 LYEXT_PAR_FEATURE, /**< ::lys_feature */
91 LYEXT_PAR_RESTR, /**< ::lys_restr - YANG's must, range, length and pattern statements */
92 LYEXT_PAR_WHEN, /**< ::lys_when */
93 LYEXT_PAR_IDENT, /**< ::lys_ident */
94 LYEXT_PAR_EXT, /**< ::lys_ext */
95 LYEXT_PAR_EXTINST, /**< ::lys_ext_instance */
96 LYEXT_PAR_REFINE, /**< ::lys_refine */
97 LYEXT_PAR_DEVIATION, /**< ::lys_deviation */
98 LYEXT_PAR_DEVIATE, /**< ::lys_deviate */
99 LYEXT_PAR_IMPORT, /**< ::lys_import */
100 LYEXT_PAR_INCLUDE, /**< ::lysp_include */
101 LYEXT_PAR_REVISION, /**< ::lysc_revision */
102} LYEXT_PARENT;
103
104/**
105 * @brief Enum of substatements in which extension instances can appear.
106 */
107typedef enum {
108 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
109 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
110 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
111 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
112 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
113 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
114 lys_node_choice and lys_deviate */
115 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
116 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
117 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
118 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
119 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
120 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
121 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
122 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
123 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
124 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
125 belongs-to's prefix) and lys_import */
126 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
127 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
128 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
129 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
130 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
131 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
132 lys_node_leaflist and lys_deviate */
133 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
134 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
135 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
136 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
137 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
138 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
139 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
140 lys_node_anydata and lys_deviate */
141 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
142 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
143 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
144 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
145 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
146 lys_node_leaflist and lys_deviate */
147 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
148 lys_node_leaflist and lys_deviate */
149 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
150 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
151 LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */
152} LYEXT_SUBSTMT;
153
154/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200155 * @brief YANG import-stmt
156 */
157struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200158 struct lys_module *module; /**< pointer to the imported module
159 (mandatory, but resolved when the referring module is completely parsed) */
160 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200161 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200162 const char *dsc; /**< description */
163 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200164 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200165 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
166};
167
168/**
169 * @brief YANG include-stmt
170 */
171struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100172 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200173 (mandatory, but resolved when the referring module is completely parsed) */
174 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200175 const char *dsc; /**< description */
176 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200177 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200178 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
179};
180
181/**
182 * @brief YANG extension-stmt
183 */
184struct lysp_ext {
185 const char *name; /**< extension name */
186 const char *argument; /**< argument name, NULL if not specified */
187 const char *dsc; /**< description statement */
188 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200189 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200190 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
191};
192
193/**
194 * @brief Helper structure for generic storage of the extension instances content.
195 */
196struct lysp_stmt {
197 const char *stmt; /**< identifier of the statement */
198 const char *arg; /**< statement's argument */
199 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200200 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200201 uint16_t flags;
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200202};
203
204/**
205 * @brief YANG extension instance
206 */
207struct lysp_ext_instance {
208 const char *name; /**< extension identifier, including possible prefix */
209 const char *argument; /**< optional value of the extension's argument */
Radek Krejci693262f2019-04-29 15:23:20 +0200210 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200211 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
212 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
213 the index of that substatement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200214};
215
216/**
217 * @brief YANG feature-stmt
218 */
219struct lysp_feature {
220 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200221 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200222 const char *dsc; /**< description statement */
223 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200224 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200225 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
226};
227
228/**
229 * @brief YANG identity-stmt
230 */
231struct lysp_ident {
232 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200233 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
234 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200235 const char *dsc; /**< description statement */
236 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200237 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200238 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
239};
240
Michal Vasko71e64ca2018-09-07 16:30:29 +0200241/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200242 * @brief Covers restrictions: range, length, pattern, must
243 */
244struct lysp_restr {
245 const char *arg; /**< The restriction expression/value (mandatory);
246 in case of pattern restriction, the first byte has a special meaning:
247 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
248 const char *emsg; /**< error-message */
249 const char *eapptag; /**< error-app-tag value */
250 const char *dsc; /**< description */
251 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200252 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200253};
254
255/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200256 * @brief YANG revision-stmt
257 */
258struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200259 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200260 const char *dsc; /**< description statement */
261 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200262 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200263};
264
265/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200266 * @brief Enumeration/Bit value definition
267 */
268struct lysp_type_enum {
269 const char *name; /**< name (mandatory) */
270 const char *dsc; /**< description statement */
271 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200272 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200273 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200274 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200275 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
276 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200277};
278
279/**
280 * @brief YANG type-stmt
281 *
282 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
283 */
284struct lysp_type {
285 const char *name; /**< name of the type (mandatory) */
286 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
287 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200288 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
289 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
290 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200291 const char *path; /**< path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200292 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200293 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
294 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200295
Radek Krejci2167ee12018-11-02 16:09:07 +0100296 struct lysc_type *compiled; /**< pointer to the compiled type */
297
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200298 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
299 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100300 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200301};
302
303/**
304 * @brief YANG typedef-stmt
305 */
306struct lysp_tpdf {
307 const char *name; /**< name of the newly defined type (mandatory) */
308 const char *units; /**< units of the newly defined type */
309 const char *dflt; /**< default value of the newly defined type */
310 const char *dsc; /**< description statement */
311 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200312 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200313 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100314 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200315};
316
317/**
318 * @brief YANG grouping-stmt
319 */
320struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100321 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
322 uint16_t nodetype; /**< LYS_GROUPING */
323 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200324 const char *name; /**< grouping name (mandatory) */
325 const char *dsc; /**< description statement */
326 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200327 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
328 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200329 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200330 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
331 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
332 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200333};
334
335/**
336 * @brief YANG when-stmt
337 */
338struct lysp_when {
339 const char *cond; /**< specified condition (mandatory) */
340 const char *dsc; /**< description statement */
341 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200342 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200343};
344
345/**
346 * @brief YANG refine-stmt
347 */
348struct lysp_refine {
349 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
350 const char *dsc; /**< description statement */
351 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200352 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200353 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200354 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200355 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200356 uint32_t min; /**< min-elements constraint */
357 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200358 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200359 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
360};
361
362/**
363 * @brief YANG uses-augment-stmt and augment-stmt
364 */
365struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100366 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
367 uint16_t nodetype; /**< LYS_AUGMENT */
368 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200369 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
370 const char *dsc; /**< description statement */
371 const char *ref; /**< reference statement */
372 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200373 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200374 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200375 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
376 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
377 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200378};
379
380/**
381 * @defgroup deviatetypes Deviate types
382 * @{
383 */
384#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
385#define LYS_DEV_ADD 2 /**< deviate type add */
386#define LYS_DEV_DELETE 3 /**< deviate type delete */
387#define LYS_DEV_REPLACE 4 /**< deviate type replace */
388/** @} */
389
390/**
391 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
392 */
393struct lysp_deviate {
394 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
395 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200396 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200397};
398
399struct lysp_deviate_add {
400 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
401 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200402 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200403 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200404 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200405 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
406 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200407 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
408 uint32_t min; /**< min-elements constraint */
409 uint32_t max; /**< max-elements constraint, 0 means unbounded */
410};
411
412struct lysp_deviate_del {
413 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
414 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200415 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200416 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200417 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200418 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
419 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200420 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200421};
422
423struct lysp_deviate_rpl {
424 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
425 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200426 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200427 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200428 const char *units; /**< units of the values */
429 const char *dflt; /**< default value */
430 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
431 uint32_t min; /**< min-elements constraint */
432 uint32_t max; /**< max-elements constraint, 0 means unbounded */
433};
434
435struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200436 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200437 const char *dsc; /**< description statement */
438 const char *ref; /**< reference statement */
439 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200440 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200441};
442
Radek Krejci4f28eda2018-11-12 11:46:16 +0100443/**
444 * @defgroup spnodeflags Parsed schema nodes flags
445 * @ingroup snodeflags
446 *
447 * Various flags for parsed schema nodes.
448 *
449 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
450 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200451 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100452 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
453 * 5 - list 10 - input 15 - typedef 20 - deviate
454 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200455 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
456 * 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
457 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
458 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
459 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
460 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
461 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
462 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
463 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
464 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
465 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
466 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
467 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
468 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
469 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
470 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
471 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
472 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
473 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
474 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
475 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
476 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
477 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
478 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
479 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
480 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
481 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
482 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
483 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
484 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
485 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
486 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
487 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
488 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
489 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
490 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
491 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
492 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
493 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200494 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200495 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100496 *
497 */
498
499/**
500 * @defgroup scnodeflags Compiled schema nodes flags
501 * @ingroup snodeflags
502 *
503 * Various flags for compiled schema nodes.
504 *
505 * 1 - container 6 - anydata/anyxml 11 - output
506 * 2 - choice 7 - case 12 - feature
507 * 3 - leaf 8 - notification 13 - identity
508 * 4 - leaflist 9 - rpc 14 - extension
Radek Krejci693262f2019-04-29 15:23:20 +0200509 * 5 - list 10 - input 15 - bitenum
Radek Krejci4f28eda2018-11-12 11:46:16 +0100510 *
Radek Krejci693262f2019-04-29 15:23:20 +0200511 * 1 1 1 1 1 1
512 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
513 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
514 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | |
515 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
516 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | |
517 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
518 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x| |
519 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
520 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x| |
521 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
522 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x| |
523 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
524 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | | |
525 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
526 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | | |
527 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | |
528 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
529 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | |
530 * LYS_PRESENCE |x| | | | | | | | | | | | | | |
531 * LYS_UNIQUE | | |x| | | | | | | | | | | | |
532 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
533 * 9 LYS_KEY | | |x| | | | | | | | | | | | |
534 * LYS_FENABLED | | | | | | | | | | | |x| | | |
535 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
536 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | | |
537 * LYS_ISENUM | | | | | | | | | | | | | | |x|
Radek Krejci0fe9b512019-07-26 17:51:05 +0200538 * LYS_KEYLESS | | | | |x| | | | | | | | | | |
Radek Krejci693262f2019-04-29 15:23:20 +0200539 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
540 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | | |
541 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci1c0c3442019-07-23 16:08:47 +0200542 * 12 LYS_SET_CONFIG |x|x|x|x|x|x|x| | |x|x| | | | |
Radek Krejci693262f2019-04-29 15:23:20 +0200543 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100544 *
545 */
546
547/**
548 * @defgroup snodeflags Schema nodes flags
549 * @ingroup schematree
550 * @{
551 */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200552#define LYS_CONFIG_W 0x01 /**< config true; */
553#define LYS_CONFIG_R 0x02 /**< config false; */
554#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100555#define LYS_STATUS_CURR 0x04 /**< status current; */
556#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
557#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
558#define LYS_STATUS_MASK 0x1C /**< mask for status value */
559#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100560 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
561 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
562 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
563 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100564#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
565 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
566 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100567#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100568#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, applicable only to ::lysc_node_container */
569#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
570#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 +0200571#define LYS_KEYLESS 0x200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100572#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysc_feature */
Radek Krejcife909632019-02-12 15:34:42 +0100573#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 +0100574 ::lysc_node_list/::lysp_node_list */
575#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
576 ::lysc_node_list/::lysp_node_list */
577#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
578#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
579#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
580#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200581#define LYS_USED_GRP 0x400 /**< internal flag for validating not-instantiated groupings
582 (resp. do not validate again the instantiated groupings). */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100583#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100584#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200585#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100586
587#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
588#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
589#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
590#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
591#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
592#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
593#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
594#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
595#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
596#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100597#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 +0100598 cases of choice. This information is important for refines, since it is prohibited to make leafs
599 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100600 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
601 between own default or the default values taken from the type. */
602#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 +0100603#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 +0100604
Radek Krejcid3ca0632019-04-16 16:54:54 +0200605#define LYS_SINGLEQUOTED 0x100 /**< flag for single-quoted argument of an extension instance's substatement */
606#define LYS_DOUBLEQUOTED 0x200 /**< flag for double-quoted argument of an extension instance's substatement */
607
Radek Krejci693262f2019-04-29 15:23:20 +0200608#define LYS_ISENUM 0x200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
609
Radek Krejcife909632019-02-12 15:34:42 +0100610#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100611/** @} */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200612
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200613/**
614 * @brief Generic YANG data node
615 */
616struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100617 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200618 uint16_t nodetype; /**< type of the node (mandatory) */
619 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100620 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200621 const char *name; /**< node name (mandatory) */
622 const char *dsc; /**< description statement */
623 const char *ref; /**< reference statement */
624 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200625 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200626 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200627};
628
629/**
630 * @brief Extension structure of the lysp_node for YANG container
631 */
632struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100633 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200634 uint16_t nodetype; /**< LYS_CONTAINER */
635 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
636 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
637 const char *name; /**< node name (mandatory) */
638 const char *dsc; /**< description statement */
639 const char *ref; /**< reference statement */
640 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200641 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200642 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200643
644 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200645 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200646 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200647 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
648 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200649 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200650 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
651 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200652};
653
654struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100655 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200656 uint16_t nodetype; /**< LYS_LEAF */
657 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
658 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
659 const char *name; /**< node name (mandatory) */
660 const char *dsc; /**< description statement */
661 const char *ref; /**< reference statement */
662 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200663 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200664 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200665
666 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200667 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200668 struct lysp_type type; /**< type of the leaf node (mandatory) */
669 const char *units; /**< units of the leaf's type */
670 const char *dflt; /**< default value */
671};
672
673struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100674 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200675 uint16_t nodetype; /**< LYS_LEAFLIST */
676 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
677 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
678 const char *name; /**< node name (mandatory) */
679 const char *dsc; /**< description statement */
680 const char *ref; /**< reference statement */
681 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200682 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200683 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200684
685 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200686 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200687 struct lysp_type type; /**< type of the leaf node (mandatory) */
688 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200689 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200690 uint32_t min; /**< min-elements constraint */
691 uint32_t max; /**< max-elements constraint, 0 means unbounded */
692};
693
694struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100695 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200696 uint16_t nodetype; /**< LYS_LIST */
697 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
698 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
699 const char *name; /**< node name (mandatory) */
700 const char *dsc; /**< description statement */
701 const char *ref; /**< reference statement */
702 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200703 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200704 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200705
706 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200707 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200708 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200709 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
710 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200711 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200712 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
713 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200714 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200715 uint32_t min; /**< min-elements constraint */
716 uint32_t max; /**< max-elements constraint, 0 means unbounded */
717};
718
719struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100720 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200721 uint16_t nodetype; /**< LYS_CHOICE */
722 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
723 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
724 const char *name; /**< node name (mandatory) */
725 const char *dsc; /**< description statement */
726 const char *ref; /**< reference statement */
727 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200728 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200729 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200730
731 /* choice */
732 struct lysp_node *child; /**< list of data nodes (linked list) */
733 const char* dflt; /**< default case */
734};
735
736struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100737 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200738 uint16_t nodetype; /**< LYS_CASE */
739 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
740 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
741 const char *name; /**< node name (mandatory) */
742 const char *dsc; /**< description statement */
743 const char *ref; /**< reference statement */
744 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200745 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200746 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200747
748 /* case */
749 struct lysp_node *child; /**< list of data nodes (linked list) */
750};
751
752struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100753 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200754 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
755 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
756 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
757 const char *name; /**< node name (mandatory) */
758 const char *dsc; /**< description statement */
759 const char *ref; /**< reference statement */
760 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200761 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200762 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200763
764 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200765 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200766};
767
768struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100769 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200770 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200771 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
772 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
773 const char *name; /**< grouping name reference (mandatory) */
774 const char *dsc; /**< description statement */
775 const char *ref; /**< reference statement */
776 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200777 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200778 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200779
780 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200781 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
782 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200783};
784
785/**
786 * @brief YANG input-stmt and output-stmt
787 */
788struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100789 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
790 uint16_t nodetype; /**< LYS_INOUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200791 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
792 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
793 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200794 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200795 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200796};
797
798/**
799 * @brief YANG rpc-stmt and action-stmt
800 */
801struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100802 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
803 uint16_t nodetype; /**< LYS_ACTION */
804 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200805 const char *name; /**< grouping name reference (mandatory) */
806 const char *dsc; /**< description statement */
807 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200808 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200809 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
810 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100811 struct lysp_action_inout input; /**< RPC's/Action's input */
812 struct lysp_action_inout output; /**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200813 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200814};
815
816/**
817 * @brief YANG notification-stmt
818 */
819struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100820 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
821 uint16_t nodetype; /**< LYS_NOTIF */
822 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200823 const char *name; /**< grouping name reference (mandatory) */
824 const char *dsc; /**< description statement */
825 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200826 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200827 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
828 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
829 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200830 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200831 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200832};
833
834/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200835 * @brief supported YANG schema version values
836 */
837typedef enum LYS_VERSION {
838 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
839 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
840 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
841} LYS_VERSION;
842
843/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200844 * @brief Printable YANG schema tree structure representing YANG module.
845 *
846 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
847 */
848struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100849 struct lys_module *mod; /**< covering module structure */
850
Radek Krejcib7db73a2018-10-24 14:18:40 +0200851 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
852 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200853 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
854 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200855 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
856 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
857 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
858 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
859 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200860 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200861 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
862 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
863 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
864 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
865 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200866
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100867 uint8_t parsing:1; /**< flag for circular check */
868};
869
870struct lysp_submodule {
871 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
872
873 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
874 in the list is always the last (newest) revision of the module */
875 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
876 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
877 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
878 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
879 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
880 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
881 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
882 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
883 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
884 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
885 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
886 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
887 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
888
889 uint8_t parsing:1; /**< flag for circular check */
890
Radek Krejci086c7132018-10-26 15:29:04 +0200891 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
892 1 - the latest revision in searchdirs was not searched yet and this is the
893 latest revision in the current context
894 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100895 const char *name; /**< name of the module (mandatory) */
896 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
897 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
898 const char *org; /**< party/company responsible for the module */
899 const char *contact; /**< contact information for the module */
900 const char *dsc; /**< description of the module */
901 const char *ref; /**< cross-reference for the module */
Radek Krejci086c7132018-10-26 15:29:04 +0200902 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200903};
904
905/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200906 * @brief Free the printable YANG schema tree structure.
907 *
908 * @param[in] module Printable YANG schema tree structure to free.
909 */
910void lysp_module_free(struct lysp_module *module);
911
912/**
Radek Krejci0e59c312019-08-15 15:34:15 +0200913 * @brief Compiled YANG extension-stmt
914 */
915struct lysc_ext {
916 const char *name; /**< extension name */
917 const char *argument; /**< argument name, NULL if not specified */
918 const char *dsc; /**< description statement */
919 const char *ref; /**< reference statement */
920 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
921 struct lyext_plugin *plugin; /**< Plugin implementing the specific extension */
922 uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */
923};
924
925/**
Radek Krejcice8c1592018-10-29 15:35:51 +0100926 * @brief YANG extension instance
927 */
928struct lysc_ext_instance {
Radek Krejci0e59c312019-08-15 15:34:15 +0200929 struct lysc_ext *ext; /**< pointer to the extension definition */
Radek Krejcice8c1592018-10-29 15:35:51 +0100930 void *parent; /**< pointer to the parent element holding the extension instance(s), use
931 ::lysc_ext_instance#parent_type to access the schema element */
932 const char *argument; /**< optional value of the extension's argument */
933 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
934 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
935 this identifies the index of the substatement for this extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +0100936 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejci2a408df2018-10-29 16:32:26 +0100937 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0e59c312019-08-15 15:34:15 +0200938 void *data; /**< private plugins's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +0100939};
940
941/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +0100942 * @brief Compiled YANG if-feature-stmt
943 */
944struct lysc_iffeature {
945 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
946 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
947};
948
949/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200950 * @brief YANG import-stmt
951 */
952struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100953 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +0200954 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejcice8c1592018-10-29 15:35:51 +0100955 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200956};
957
958/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200959 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200960 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200961struct lysc_when {
962 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +0100963 const char *dsc; /**< description */
964 const char *ref; /**< reference */
Radek Krejci00b874b2019-02-12 10:54:50 +0100965 struct lysc_node *context; /**< context node for evaluating the expression */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200966 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +0100967 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200968};
969
970/**
Radek Krejci2a408df2018-10-29 16:32:26 +0100971 * @brief YANG identity-stmt
972 */
973struct lysc_ident {
974 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +0100975 const char *dsc; /**< description */
976 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +0200977 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +0100978 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
979 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +0200980 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +0100981 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
982};
983
984/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200985 * @brief YANG feature-stmt
986 */
987struct lysc_feature {
988 const char *name; /**< feature name (mandatory) */
Radek Krejcic8b31002019-01-08 10:24:45 +0100989 const char *dsc; /**< description */
990 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +0200991 struct lys_module *module; /**< module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +0200992 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 +0100993 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +0200994 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200995 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
996 #LYS_FENABLED values allowed */
997};
998
Radek Krejci151a5b72018-10-19 14:21:44 +0200999/**
1000 * @defgroup ifftokens if-feature expression tokens
1001 * Tokens of if-feature expression used in ::lysc_iffeature#expr
1002 *
1003 * @{
1004 */
1005#define LYS_IFF_NOT 0x00 /**< operand "not" */
1006#define LYS_IFF_AND 0x01 /**< operand "and" */
1007#define LYS_IFF_OR 0x02 /**< operand "or" */
1008#define LYS_IFF_F 0x03 /**< feature */
1009/**
1010 * @}
1011 */
1012
1013/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001014 * @brief Compiled YANG revision statement
1015 */
1016struct lysc_revision {
1017 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1018 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1019};
1020
Radek Krejci2167ee12018-11-02 16:09:07 +01001021struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001022 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001023 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001024 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1025 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001026 };
Radek Krejci693262f2019-04-29 15:23:20 +02001027 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +02001028 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
1029 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001030 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001031 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001032 const char *dsc; /**< description */
1033 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001034 const char *emsg; /**< error-message */
1035 const char *eapptag; /**< error-app-tag value */
1036 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1037};
1038
1039struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001040 const char *expr; /**< original, not compiled, regular expression */
1041 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001042 const char *dsc; /**< description */
1043 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001044 const char *emsg; /**< error-message */
1045 const char *eapptag; /**< error-app-tag value */
1046 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4586a022018-11-13 11:29:26 +01001047 uint32_t inverted:1; /**< invert-match flag */
1048 uint32_t refcount:31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001049};
1050
1051struct lysc_must {
1052 struct lys_module *module; /**< module where the must was defined */
1053 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001054 const char *dsc; /**< description */
1055 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001056 const char *emsg; /**< error-message */
1057 const char *eapptag; /**< error-app-tag value */
1058 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1059};
1060
1061struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001062 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001063 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001064 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 +02001065 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 +01001066 LY_DATA_TYPE basetype; /**< Base type of the type */
1067 uint32_t refcount; /**< reference counter for type sharing */
1068};
1069
1070struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001071 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001072 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001073 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 +02001074 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 +01001075 LY_DATA_TYPE basetype; /**< Base type of the type */
1076 uint32_t refcount; /**< reference counter for type sharing */
1077 struct lysc_range *range; /**< Optional range limitation */
1078};
1079
1080struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001081 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001082 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001083 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 +02001084 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 +01001085 LY_DATA_TYPE basetype; /**< Base type of the type */
1086 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001087 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001088 struct lysc_range *range; /**< Optional range limitation */
1089};
1090
1091struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001092 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001093 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001094 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 +02001095 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 +01001096 LY_DATA_TYPE basetype; /**< Base type of the type */
1097 uint32_t refcount; /**< reference counter for type sharing */
1098 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001099 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001100};
1101
Radek Krejci693262f2019-04-29 15:23:20 +02001102struct lysc_type_bitenum_item {
1103 const char *name; /**< enumeration identifier */
1104 const char *dsc; /**< description */
1105 const char *ref; /**< reference */
1106 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1107 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1108 union {
1109 int32_t value; /**< integer value associated with the enumeration */
1110 uint32_t position; /**< non-negative integer value associated with the bit */
1111 };
1112 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1113 values are allowed */
1114};
1115
Radek Krejci2167ee12018-11-02 16:09:07 +01001116struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001117 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001118 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001119 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 +02001120 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 +01001121 LY_DATA_TYPE basetype; /**< Base type of the type */
1122 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001123 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1124};
1125
1126struct lysc_type_bits {
1127 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1128 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001129 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 +02001130 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 +02001131 LY_DATA_TYPE basetype; /**< Base type of the type */
1132 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001133 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1134 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001135};
1136
1137struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001138 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001139 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001140 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 +02001141 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 +01001142 LY_DATA_TYPE basetype; /**< Base type of the type */
1143 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejcia3045382018-11-22 14:30:31 +01001144 const char* path; /**< target path */
Radek Krejci96a0bfd2018-11-22 15:25:06 +01001145 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 +01001146 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001147 uint8_t require_instance; /**< require-instance flag */
1148};
1149
1150struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001151 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001152 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001153 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 +02001154 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 +01001155 LY_DATA_TYPE basetype; /**< Base type of the type */
1156 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001157 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001158 mandatory (at least 1 item) */
1159};
1160
1161struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001162 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001163 const char *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 uint8_t require_instance; /**< require-instance flag */
1169};
1170
Radek Krejci2167ee12018-11-02 16:09:07 +01001171struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001172 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001173 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001174 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 +02001175 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 +01001176 LY_DATA_TYPE basetype; /**< Base type of the type */
1177 uint32_t refcount; /**< reference counter for type sharing */
1178 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1179};
1180
1181struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001182 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001183 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001184 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 +02001185 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 +01001186 LY_DATA_TYPE basetype; /**< Base type of the type */
1187 uint32_t refcount; /**< reference counter for type sharing */
1188 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001189};
1190
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001191struct lysc_action_inout {
1192 struct lysc_node *data; /**< first child node (linked list) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001193 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1194};
1195
Radek Krejci056d0a82018-12-06 16:57:25 +01001196struct lysc_action {
1197 uint16_t nodetype; /**< LYS_ACTION */
1198 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001199 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001200 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. */
1201 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1202
Radek Krejcifc11bd72019-04-11 16:00:05 +02001203 struct lysc_ext_instance *input_exts; /**< list of the extension instances of input ([sized array](@ref sizedarrays)) */
1204 struct lysc_ext_instance *output_exts; /**< list of the extension instances of outpu ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001205
Radek Krejci056d0a82018-12-06 16:57:25 +01001206 const char *name; /**< action/RPC name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001207 const char *dsc; /**< description */
1208 const char *ref; /**< reference */
1209
Radek Krejcifc11bd72019-04-11 16:00:05 +02001210 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1211 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1212
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001213 struct lysc_action_inout input; /**< RPC's/action's input */
1214 struct lysc_action_inout output; /**< RPC's/action's output */
1215
Radek Krejci056d0a82018-12-06 16:57:25 +01001216};
1217
1218struct lysc_notif {
1219 uint16_t nodetype; /**< LYS_NOTIF */
1220 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001221 struct lys_module *module; /**< module structure */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001222 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 +01001223 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1224
Radek Krejcifc11bd72019-04-11 16:00:05 +02001225 struct lysc_node *data; /**< first child node (linked list) */
1226 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1227
Radek Krejci056d0a82018-12-06 16:57:25 +01001228 const char *name; /**< Notification name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001229 const char *dsc; /**< description */
1230 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001231
1232 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1233 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001234};
1235
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001236/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001237 * @brief Compiled YANG data node
1238 */
1239struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001240 uint16_t nodetype; /**< type of the node (mandatory) */
1241 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001242 struct lys_module *module; /**< module structure */
1243 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. */
1244 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1245 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1246 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1247 never NULL. If there is no sibling node, pointer points to the node
1248 itself. In case of the first node, this pointer points to the last
1249 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001250 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001251 const char *dsc; /**< description */
1252 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001253 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001254 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001255 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001256};
1257
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001258struct lysc_node_container {
1259 uint16_t nodetype; /**< LYS_CONTAINER */
1260 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1261 struct lys_module *module; /**< module structure */
1262 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. */
1263 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1264 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1265 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1266 never NULL. If there is no sibling node, pointer points to the node
1267 itself. In case of the first node, this pointer points to the last
1268 node in the list. */
1269 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001270 const char *dsc; /**< description */
1271 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001272 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001273 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001274 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001275
1276 struct lysc_node *child; /**< first child node (linked list) */
1277 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1278 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1279 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001280};
1281
Radek Krejcia3045382018-11-22 14:30:31 +01001282struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001283 uint16_t nodetype; /**< LYS_CASE */
1284 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1285 struct lys_module *module; /**< module structure */
1286 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. */
1287 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1288 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1289 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1290 never NULL. If there is no sibling node, pointer points to the node
1291 itself. In case of the first node, this pointer points to the last
1292 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001293 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001294 const char *dsc; /**< description */
1295 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001296 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001297 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001298 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001299
Radek Krejcia3045382018-11-22 14:30:31 +01001300 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 +01001301 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001302};
1303
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001304struct lysc_node_choice {
1305 uint16_t nodetype; /**< LYS_CHOICE */
1306 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1307 struct lys_module *module; /**< module structure */
1308 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. */
1309 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1310 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1311 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1312 never NULL. If there is no sibling node, pointer points to the node
1313 itself. In case of the first node, this pointer points to the last
1314 node in the list. */
1315 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001316 const char *dsc; /**< description */
1317 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001318 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001319 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001320 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001321
Radek Krejcia9026eb2018-12-12 16:04:47 +01001322 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1323 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1324 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001325 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001326};
1327
1328struct lysc_node_leaf {
1329 uint16_t nodetype; /**< LYS_LEAF */
1330 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1331 struct lys_module *module; /**< module structure */
1332 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. */
1333 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1334 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1335 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1336 never NULL. If there is no sibling node, pointer points to the node
1337 itself. In case of the first node, this pointer points to the last
1338 node in the list. */
1339 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001340 const char *dsc; /**< description */
1341 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001342 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001343 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001344 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001345
1346 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1347 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001348
Radek Krejci4f28eda2018-11-12 11:46:16 +01001349 const char *units; /**< units of the leaf's type */
Radek Krejcia1911222019-07-22 17:24:50 +02001350 struct lyd_value *dflt; /**< default value */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001351 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 +01001352};
1353
1354struct lysc_node_leaflist {
1355 uint16_t nodetype; /**< LYS_LEAFLIST */
1356 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1357 struct lys_module *module; /**< module structure */
1358 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. */
1359 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1360 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1361 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1362 never NULL. If there is no sibling node, pointer points to the node
1363 itself. In case of the first node, this pointer points to the last
1364 node in the list. */
1365 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001366 const char *dsc; /**< description */
1367 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001368 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001369 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001370 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001371
1372 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1373 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1374
Radek Krejci0e5d8382018-11-28 16:37:53 +01001375 const char *units; /**< units of the leaf's type */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001376 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values */
1377 struct lys_module **dflts_mods; /**< list ([sized array](@ref sizedarrays)) of modules where the lysc_node_leaflist::dflts values were defined
1378 (needed to correctly map prefixes). */
Radek Krejci0e5d8382018-11-28 16:37:53 +01001379 uint32_t min; /**< min-elements constraint */
1380 uint32_t max; /**< max-elements constraint */
1381
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001382};
1383
1384struct lysc_node_list {
1385 uint16_t nodetype; /**< LYS_LIST */
1386 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1387 struct lys_module *module; /**< module structure */
1388 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. */
1389 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1390 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1391 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1392 never NULL. If there is no sibling node, pointer points to the node
1393 itself. In case of the first node, this pointer points to the last
1394 node in the list. */
1395 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001396 const char *dsc; /**< description */
1397 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001398 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001399 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001400 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001401
1402 struct lysc_node *child; /**< first child node (linked list) */
1403 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1404 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1405 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1406
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001407 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1408 uint32_t min; /**< min-elements constraint */
1409 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001410};
1411
1412struct lysc_node_anydata {
1413 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1414 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1415 struct lys_module *module; /**< module structure */
1416 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. */
1417 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1418 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1419 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1420 never NULL. If there is no sibling node, pointer points to the node
1421 itself. In case of the first node, this pointer points to the last
1422 node in the list. */
1423 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001424 const char *dsc; /**< description */
1425 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001426 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001427 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001428 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9800fb82018-12-13 14:26:23 +01001429
1430 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001431};
1432
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001433/**
1434 * @brief Compiled YANG schema tree structure representing YANG module.
1435 *
1436 * Semantically validated YANG schema tree for data tree parsing.
1437 * Contains only the necessary information for the data validation.
1438 */
1439struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001440 struct lys_module *mod; /**< covering module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001441 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001442
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001443 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001444 struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1445 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1446 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1447 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001448 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001449};
1450
1451/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001452 * @brief Get the groupings sized array of the given (parsed) schema node.
1453 * Decides the node's type and in case it has a groupings array, returns it.
1454 * @param[in] node Node to examine.
1455 * @return The node's groupings sized array if any, NULL otherwise.
1456 */
1457const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1458
1459/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001460 * @brief Get the typedefs sized array of the given (parsed) schema node.
1461 * Decides the node's type and in case it has a typedefs array, returns it.
1462 * @param[in] node Node to examine.
1463 * @return The node's typedefs sized array if any, NULL otherwise.
1464 */
1465const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1466
1467/**
1468 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1469 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1470 * @param[in] node Node to examine.
1471 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1472 */
1473const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1474
1475/**
1476 * @brief Get the Notifications sized array of the given (parsed) schema node.
1477 * Decides the node's type and in case it has a Notifications array, returns it.
1478 * @param[in] node Node to examine.
1479 * @return The node's Notifications sized array if any, NULL otherwise.
1480 */
1481const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1482
1483/**
1484 * @brief Get the children linked list of the given (parsed) schema node.
1485 * Decides the node's type and in case it has a children list, returns it.
1486 * @param[in] node Node to examine.
1487 * @return The node's children linked list if any, NULL otherwise.
1488 */
1489const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1490
1491/**
1492 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1493 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1494 * @param[in] node Node to examine.
1495 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1496 */
1497const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1498
1499/**
1500 * @brief Get the Notifications sized array of the given (compiled) schema node.
1501 * Decides the node's type and in case it has a Notifications array, returns it.
1502 * @param[in] node Node to examine.
1503 * @return The node's Notifications sized array if any, NULL otherwise.
1504 */
1505const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1506
1507/**
1508 * @brief Get the children linked list of the given (compiled) schema node.
1509 * Decides the node's type and in case it has a children list, returns it.
1510 * @param[in] node Node to examine.
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001511 * @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 +01001512 * @return The node's children linked list if any, NULL otherwise.
1513 */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001514const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Radek Krejci056d0a82018-12-06 16:57:25 +01001515
1516/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001517 * @brief Get how the if-feature statement currently evaluates.
1518 *
1519 * @param[in] iff Compiled if-feature statement to evaluate.
1520 * @return If the statement evaluates to true, 1 is returned. 0 is returned when the statement evaluates to false.
1521 */
1522int lysc_iffeature_value(const struct lysc_iffeature *iff);
1523
1524/**
1525 * @brief Get the current status of the provided feature.
1526 *
1527 * @param[in] feature Compiled feature statement to examine.
1528 * @return
1529 * - 1 if feature is enabled,
1530 * - 0 if feature is disabled,
1531 * - -1 in case of error (invalid argument)
1532 */
1533int lysc_feature_value(const struct lysc_feature *feature);
1534
1535/**
Radek Krejci327de162019-06-14 12:52:07 +02001536 * @brief Generate path of the given node in the requested format.
1537 *
1538 * @param[in] node Schema path of this node will be generated.
1539 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001540 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
1541 * If NULL, memory for the complete path is allocated.
1542 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02001543 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001544 * 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 +02001545 */
Radek Krejci1c0c3442019-07-23 16:08:47 +02001546char *lysc_path(struct lysc_node *node, LY_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02001547
1548/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001549 * @brief Available YANG schema tree structures representing YANG module.
1550 */
1551struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001552 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
1553 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01001554 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001555 const char *ns; /**< namespace of the module (module - mandatory) */
1556 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
1557 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1558 const char *org; /**< party/company responsible for the module */
1559 const char *contact; /**< contact information for the module */
1560 const char *dsc; /**< description of the module */
1561 const char *ref; /**< cross-reference for the module */
1562
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001563 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01001564 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
1565 Available only for implemented modules. */
1566 struct lysc_feature *off_features;/**< List of pre-compiled features of the module in non implemented modules ([sized array](@ref sizedarrays)).
1567 These features are always disabled and cannot be enabled until the module
1568 become implemented. The features are present in this form to allow their linkage
1569 from if-feature statements of the compiled schemas and their proper use in case
1570 the module became implemented in future (no matter if implicitly via augment/deviate
1571 or explicitly via ly_ctx_module_implement()). */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001572
Radek Krejci95710c92019-02-11 15:49:55 +01001573 uint8_t implemented; /**< flag if the module is implemented, not just imported. The module is implemented if
1574 the flag has non-zero value. Specific values are used internally:
1575 1 - implemented module
1576 2 - recently implemented module by dependency, it can be reverted in rollback procedure */
1577 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001578 1 - the latest revision in searchdirs was not searched yet and this is the
1579 latest revision in the current context
1580 2 - searchdirs were searched and this is the latest available revision */
1581 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001582};
1583
Radek Krejci151a5b72018-10-19 14:21:44 +02001584/**
1585 * @brief Enable specified feature in the module
1586 *
1587 * By default, when the module is loaded by libyang parser, all features are disabled.
1588 *
Radek Krejcica3db002018-11-01 10:31:01 +01001589 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
1590 * enabling all features on the following feature set will fail since it is not possible to enable both features
1591 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
1592 * is untouched.
1593 *
1594 * feature f1;
1595 * feature f2 { if-feature 'not f1';}
1596 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001597 * @param[in] module Module where the feature will be enabled.
1598 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
1599 * @return LY_ERR value.
1600 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001601LY_ERR lys_feature_enable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001602
1603/**
1604 * @brief Disable specified feature in the module
1605 *
1606 * By default, when the module is loaded by libyang parser, all features are disabled.
1607 *
1608 * @param[in] module Module where the feature will be disabled.
1609 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
1610 * @return LY_ERR value
1611 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001612LY_ERR lys_feature_disable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001613
1614/**
1615 * @brief Get the current status of the specified feature in the module.
1616 *
1617 * @param[in] module Module where the feature is defined.
1618 * @param[in] feature Name of the feature to inspect.
1619 * @return
1620 * - 1 if feature is enabled,
1621 * - 0 if feature is disabled,
1622 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
1623 */
1624int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001625
1626/**
Radek Krejci86d106e2018-10-18 09:53:19 +02001627 * @brief Load a schema into the specified context.
1628 *
1629 * @param[in] ctx libyang context where to process the data model.
1630 * @param[in] data The string containing the dumped data model in the specified
1631 * format.
1632 * @param[in] format Format of the input data (YANG or YIN).
1633 * @return Pointer to the data model structure or NULL on error.
1634 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001635struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001636
1637/**
1638 * @brief Read a schema from file descriptor into the specified context.
1639 *
1640 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
1641 *
1642 * @param[in] ctx libyang context where to process the data model.
1643 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
1644 * in the specified format.
1645 * @param[in] format Format of the input data (YANG or YIN).
1646 * @return Pointer to the data model structure or NULL on error.
1647 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001648struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001649
1650/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001651 * @brief Read a schema into the specified context from a file.
Radek Krejci86d106e2018-10-18 09:53:19 +02001652 *
1653 * @param[in] ctx libyang context where to process the data model.
1654 * @param[in] path Path to the file with the model in the specified format.
1655 * @param[in] format Format of the input data (YANG or YIN).
1656 * @return Pointer to the data model structure or NULL on error.
1657 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001658struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001659
1660/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001661 * @brief Search for the schema file in the specified searchpaths.
1662 *
1663 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
1664 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
1665 * result of the ly_ctx_get_searchdirs().
1666 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
1667 * @param[in] name Name of the schema to find.
1668 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
1669 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
1670 * complying the provided restriction is found, NULL is set.
1671 * @param[out] format Optional output variable containing expected format of the schema document according to the
1672 * file suffix.
1673 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
1674 */
1675LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
1676
1677/**
Radek Krejcia3045382018-11-22 14:30:31 +01001678 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
1679 * be from an augment.
1680 *
1681 * lys_getnext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
1682 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
1683 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
1684 * \p parent and \p module parameters.
1685 *
1686 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
1687 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
1688 * all the schema nodes are iteratively returned.
1689 *
1690 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
1691 * @param[in] parent Parent of the subtree where the function starts processing.
1692 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
1693 * module must be specified.
1694 * @param[in] options [ORed options](@ref sgetnextflags).
1695 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
1696 */
1697const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
1698 const struct lysc_module *module, int options);
1699
1700/**
1701 * @defgroup sgetnextflags lys_getnext() flags
1702 * @ingroup schematree
1703 *
1704 * @{
1705 */
1706#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 +01001707#define LYS_GETNEXT_NOCHOICE 0x02 /**< lys_getnext() option to ignore (kind of conditional) nodes within choice node */
Radek Krejci056d0a82018-12-06 16:57:25 +01001708#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 +01001709#define LYS_GETNEXT_INTONPCONT 0x40 /**< lys_getnext() option to look into non-presence container, instead of returning container itself */
1710#define LYS_GETNEXT_NOSTATECHECK 0x100 /**< lys_getnext() option to skip checking module validity (import-only, disabled) and
1711 relevant if-feature conditions state */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001712#define LYS_GETNEXT_OUTPUT 0x200 /**< lys_getnext() option to provide RPC's/action's output schema nodes instead of input schema nodes
1713 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01001714/** @} sgetnextflags */
1715
1716/**
1717 * @brief Get child node according to the specified criteria.
1718 *
1719 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
1720 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
1721 * @param[in] name Name of the node to find.
1722 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
1723 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
1724 * Used as a bitmask, so multiple nodetypes can be specified.
1725 * @param[in] options [ORed options](@ref sgetnextflags).
1726 * @return Found node if any.
1727 */
1728const struct lysc_node *lys_child(const struct lysc_node *parent, const struct lys_module *module,
1729 const char *name, size_t name_len, uint16_t nodetype, int options);
1730
1731/**
1732 * @brief Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statement
1733 * affecting the node.
1734 *
1735 * @param[in] node Schema node to check.
1736 * @param[in] recursive - 0 to check if-feature only in the \p node schema node,
1737 * - 1 to check if-feature in all ascendant schema nodes until there is a node possibly having an instance in a data tree
1738 * @return - NULL if enabled,
1739 * - pointer to the node with the unsatisfied (disabling) if-feature expression.
1740 */
1741const struct lysc_iffeature *lys_is_disabled(const struct lysc_node *node, int recursive);
1742
Radek Krejci084289f2019-07-09 17:35:30 +02001743/**
1744 * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
1745 *
1746 * This function check just the type's restriction, if you want to check also the data tree context (e.g. in case of
1747 * require-instance restriction), use lyd_value_validate().
1748 *
1749 * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
1750 * @param[in] node Schema node for the @p value.
1751 * @param[in] value String value to be checked.
1752 * @param[in] value_len Length of the given @p value (mandatory).
1753 * @param[in] get_prefix Callback function to resolve prefixes used in the @p value string.
1754 * @param[in] get_prefix_data Private data for the @p get_prefix callback.
1755 * @param[in] format Input format of the @p value.
1756 * @return LY_SUCCESS on success
1757 * @return LY_ERR value if an error occurred.
1758 */
1759LY_ERR lys_value_validate(struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len,
1760 ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format);
1761
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001762/** @} */
1763
Radek Krejci70853c52018-10-15 14:46:16 +02001764#ifdef __cplusplus
1765}
1766#endif
1767
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001768#endif /* LY_TREE_SCHEMA_H_ */