blob: 004a1959e7acb5a60167c53939676030f337cf4b [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 Krejcice8c1592018-10-29 15:35:51 +010026#include "extensions.h"
Radek Krejci084289f2019-07-09 17:35:30 +020027#include "tree_data.h"
Radek Krejcice8c1592018-10-29 15:35:51 +010028
Radek Krejcie7b95092019-05-15 11:03:07 +020029struct ly_ctx;
30
Radek Krejci70853c52018-10-15 14:46:16 +020031#ifdef __cplusplus
32extern "C" {
33#endif
34
Radek Krejci5aeea3a2018-09-05 13:29:36 +020035/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +020036 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
37 */
38typedef enum {
39 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
40 LYS_IN_YANG = 1, /**< YANG schema input format */
Radek Krejci693262f2019-04-29 15:23:20 +020041 LYS_IN_YIN = 3 /**< YIN schema input format */
Radek Krejci0af5f5d2018-09-07 15:00:30 +020042} LYS_INFORMAT;
43
44/**
45 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
46 */
47typedef enum {
48 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
49 LYS_OUT_YANG = 1, /**< YANG schema output format */
Radek Krejci693262f2019-04-29 15:23:20 +020050 LYS_OUT_YIN = 3, /**< YIN schema output format */
51 LYS_OUT_YANG_COMPILED = 2, /**< YANG schema output format of the compiled schema tree */
Radek Krejcid3ca0632019-04-16 16:54:54 +020052
Radek Krejci0af5f5d2018-09-07 15:00:30 +020053 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
54 LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
55 LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */
56} LYS_OUTFORMAT;
57
Radek Krejci5aeea3a2018-09-05 13:29:36 +020058#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
59
Michal Vaskob55f6c12018-09-12 11:13:15 +020060#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
61#define LYS_CONTAINER 0x0001 /**< container statement node */
62#define LYS_CHOICE 0x0002 /**< choice statement node */
63#define LYS_LEAF 0x0004 /**< leaf statement node */
64#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
65#define LYS_LIST 0x0010 /**< list statement node */
66#define LYS_ANYXML 0x0020 /**< anyxml statement node */
Michal Vaskob55f6c12018-09-12 11:13:15 +020067#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 +020068
Radek Krejcie7b95092019-05-15 11:03:07 +020069#define LYS_ACTION 0x400 /**< RPC or action */
Radek Krejcif3b6fec2019-07-24 15:53:11 +020070#define LYS_RPC LYS_ACTION /**< RPC or action (for backward compatibility) */
Radek Krejcie7b95092019-05-15 11:03:07 +020071#define LYS_NOTIF 0x800
72
Radek Krejcia3045382018-11-22 14:30:31 +010073#define LYS_CASE 0x0040 /**< case statement node */
74#define LYS_USES 0x0080 /**< uses statement node */
Radek Krejcid3ca0632019-04-16 16:54:54 +020075#define LYS_INPUT 0x100
76#define LYS_OUTPUT 0x200
77#define LYS_INOUT 0x300
Radek Krejci6d9b9b52018-11-02 12:43:39 +010078#define LYS_GROUPING 0x1000
79#define LYS_AUGMENT 0x2000
80
Radek Krejci5aeea3a2018-09-05 13:29:36 +020081/**
82 * @brief YANG import-stmt
83 */
84struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +020085 struct lys_module *module; /**< pointer to the imported module
86 (mandatory, but resolved when the referring module is completely parsed) */
87 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020088 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020089 const char *dsc; /**< description */
90 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +020091 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020092 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
93};
94
95/**
96 * @brief YANG include-stmt
97 */
98struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +010099 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200100 (mandatory, but resolved when the referring module is completely parsed) */
101 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200102 const char *dsc; /**< description */
103 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200104 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200105 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
106};
107
108/**
109 * @brief YANG extension-stmt
110 */
111struct lysp_ext {
112 const char *name; /**< extension name */
113 const char *argument; /**< argument name, NULL if not specified */
114 const char *dsc; /**< description statement */
115 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200116 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200117 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
118};
119
120/**
121 * @brief Helper structure for generic storage of the extension instances content.
122 */
123struct lysp_stmt {
124 const char *stmt; /**< identifier of the statement */
125 const char *arg; /**< statement's argument */
126 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200127 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200128 uint16_t flags;
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200129};
130
131/**
132 * @brief YANG extension instance
133 */
134struct lysp_ext_instance {
135 const char *name; /**< extension identifier, including possible prefix */
136 const char *argument; /**< optional value of the extension's argument */
Radek Krejci693262f2019-04-29 15:23:20 +0200137 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200138 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
139 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
140 the index of that substatement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200141};
142
143/**
144 * @brief YANG feature-stmt
145 */
146struct lysp_feature {
147 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200148 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200149 const char *dsc; /**< description statement */
150 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200151 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200152 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
153};
154
155/**
156 * @brief YANG identity-stmt
157 */
158struct lysp_ident {
159 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200160 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
161 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200162 const char *dsc; /**< description statement */
163 const char *ref; /**< reference statement */
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 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
166};
167
Michal Vasko71e64ca2018-09-07 16:30:29 +0200168/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200169 * @brief Covers restrictions: range, length, pattern, must
170 */
171struct lysp_restr {
172 const char *arg; /**< The restriction expression/value (mandatory);
173 in case of pattern restriction, the first byte has a special meaning:
174 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
175 const char *emsg; /**< error-message */
176 const char *eapptag; /**< error-app-tag value */
177 const char *dsc; /**< description */
178 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200179 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200180};
181
182/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200183 * @brief YANG revision-stmt
184 */
185struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200186 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200187 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)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200190};
191
192/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200193 * @brief Enumeration/Bit value definition
194 */
195struct lysp_type_enum {
196 const char *name; /**< name (mandatory) */
197 const char *dsc; /**< description statement */
198 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200199 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200200 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200201 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200202 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
203 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200204};
205
206/**
207 * @brief YANG type-stmt
208 *
209 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
210 */
211struct lysp_type {
212 const char *name; /**< name of the type (mandatory) */
213 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
214 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200215 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
216 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
217 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200218 const char *path; /**< path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200219 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200220 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
221 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200222
Radek Krejci2167ee12018-11-02 16:09:07 +0100223 struct lysc_type *compiled; /**< pointer to the compiled type */
224
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200225 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
226 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100227 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200228};
229
230/**
231 * @brief YANG typedef-stmt
232 */
233struct lysp_tpdf {
234 const char *name; /**< name of the newly defined type (mandatory) */
235 const char *units; /**< units of the newly defined type */
236 const char *dflt; /**< default value of the newly defined type */
237 const char *dsc; /**< description statement */
238 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200239 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200240 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100241 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200242};
243
244/**
245 * @brief YANG grouping-stmt
246 */
247struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100248 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
249 uint16_t nodetype; /**< LYS_GROUPING */
250 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200251 const char *name; /**< grouping name (mandatory) */
252 const char *dsc; /**< description statement */
253 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200254 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
255 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200256 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200257 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
258 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
259 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200260};
261
262/**
263 * @brief YANG when-stmt
264 */
265struct lysp_when {
266 const char *cond; /**< specified condition (mandatory) */
267 const char *dsc; /**< description statement */
268 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200269 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200270};
271
272/**
273 * @brief YANG refine-stmt
274 */
275struct lysp_refine {
276 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
277 const char *dsc; /**< description statement */
278 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200279 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200280 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200281 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200282 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200283 uint32_t min; /**< min-elements constraint */
284 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200285 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200286 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
287};
288
289/**
290 * @brief YANG uses-augment-stmt and augment-stmt
291 */
292struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100293 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
294 uint16_t nodetype; /**< LYS_AUGMENT */
295 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200296 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
297 const char *dsc; /**< description statement */
298 const char *ref; /**< reference statement */
299 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200300 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200301 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200302 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
303 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
304 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200305};
306
307/**
308 * @defgroup deviatetypes Deviate types
309 * @{
310 */
311#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
312#define LYS_DEV_ADD 2 /**< deviate type add */
313#define LYS_DEV_DELETE 3 /**< deviate type delete */
314#define LYS_DEV_REPLACE 4 /**< deviate type replace */
315/** @} */
316
317/**
318 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
319 */
320struct lysp_deviate {
321 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
322 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200323 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200324};
325
326struct lysp_deviate_add {
327 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
328 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200329 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200330 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200331 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200332 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
333 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200334 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
335 uint32_t min; /**< min-elements constraint */
336 uint32_t max; /**< max-elements constraint, 0 means unbounded */
337};
338
339struct lysp_deviate_del {
340 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
341 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200342 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200343 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200344 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200345 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
346 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200347 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200348};
349
350struct lysp_deviate_rpl {
351 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
352 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200353 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200354 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200355 const char *units; /**< units of the values */
356 const char *dflt; /**< default value */
357 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
358 uint32_t min; /**< min-elements constraint */
359 uint32_t max; /**< max-elements constraint, 0 means unbounded */
360};
361
362struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200363 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200364 const char *dsc; /**< description statement */
365 const char *ref; /**< reference statement */
366 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200367 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200368};
369
Radek Krejci4f28eda2018-11-12 11:46:16 +0100370/**
371 * @defgroup spnodeflags Parsed schema nodes flags
372 * @ingroup snodeflags
373 *
374 * Various flags for parsed schema nodes.
375 *
376 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
377 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200378 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100379 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
380 * 5 - list 10 - input 15 - typedef 20 - deviate
381 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200382 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
383 * 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
384 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
385 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
386 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
387 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
388 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
389 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
390 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
391 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
392 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
393 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
394 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
395 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
396 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
397 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
398 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
399 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
400 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
401 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
402 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
403 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
404 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
405 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
406 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
407 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
408 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
409 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
410 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
411 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
412 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
413 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
414 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
415 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
416 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
417 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
418 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
419 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
420 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200421 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200422 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100423 *
424 */
425
426/**
427 * @defgroup scnodeflags Compiled schema nodes flags
428 * @ingroup snodeflags
429 *
430 * Various flags for compiled schema nodes.
431 *
432 * 1 - container 6 - anydata/anyxml 11 - output
433 * 2 - choice 7 - case 12 - feature
434 * 3 - leaf 8 - notification 13 - identity
435 * 4 - leaflist 9 - rpc 14 - extension
Radek Krejci693262f2019-04-29 15:23:20 +0200436 * 5 - list 10 - input 15 - bitenum
Radek Krejci4f28eda2018-11-12 11:46:16 +0100437 *
Radek Krejci693262f2019-04-29 15:23:20 +0200438 * 1 1 1 1 1 1
439 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
440 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
441 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | |
442 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
443 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | |
444 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
445 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x| |
446 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
447 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x| |
448 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
449 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x| |
450 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
451 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | | |
452 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
453 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | | |
454 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | |
455 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
456 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | |
457 * LYS_PRESENCE |x| | | | | | | | | | | | | | |
458 * LYS_UNIQUE | | |x| | | | | | | | | | | | |
459 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
460 * 9 LYS_KEY | | |x| | | | | | | | | | | | |
461 * LYS_FENABLED | | | | | | | | | | | |x| | | |
462 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
463 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | | |
464 * LYS_ISENUM | | | | | | | | | | | | | | |x|
465 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
466 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | | |
467 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci1c0c3442019-07-23 16:08:47 +0200468 * 12 LYS_SET_CONFIG |x|x|x|x|x|x|x| | |x|x| | | | |
Radek Krejci693262f2019-04-29 15:23:20 +0200469 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100470 *
471 */
472
473/**
474 * @defgroup snodeflags Schema nodes flags
475 * @ingroup schematree
476 * @{
477 */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200478#define LYS_CONFIG_W 0x01 /**< config true; */
479#define LYS_CONFIG_R 0x02 /**< config false; */
480#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100481#define LYS_STATUS_CURR 0x04 /**< status current; */
482#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
483#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
484#define LYS_STATUS_MASK 0x1C /**< mask for status value */
485#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100486 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
487 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
488 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
489 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100490#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
491 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
492 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100493#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100494#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, applicable only to ::lysc_node_container */
495#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
496#define LYS_KEY 0x100 /**< flag for leafs being a key of a list, applicable only to ::lysc_node_leaf */
497#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysc_feature */
Radek Krejcife909632019-02-12 15:34:42 +0100498#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 +0100499 ::lysc_node_list/::lysp_node_list */
500#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
501 ::lysc_node_list/::lysp_node_list */
502#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
503#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
504#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
505#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200506#define LYS_USED_GRP 0x400 /**< internal flag for validating not-instantiated groupings
507 (resp. do not validate again the instantiated groupings). */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100508#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100509#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200510#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100511
512#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
513#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
514#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
515#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
516#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
517#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
518#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
519#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
520#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
521#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100522#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 +0100523 cases of choice. This information is important for refines, since it is prohibited to make leafs
524 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100525 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
526 between own default or the default values taken from the type. */
527#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 +0100528#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 +0100529
Radek Krejcid3ca0632019-04-16 16:54:54 +0200530#define LYS_SINGLEQUOTED 0x100 /**< flag for single-quoted argument of an extension instance's substatement */
531#define LYS_DOUBLEQUOTED 0x200 /**< flag for double-quoted argument of an extension instance's substatement */
532
Radek Krejci693262f2019-04-29 15:23:20 +0200533#define LYS_ISENUM 0x200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
534
Radek Krejcife909632019-02-12 15:34:42 +0100535#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100536/** @} */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200537
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200538/**
539 * @brief Generic YANG data node
540 */
541struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100542 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200543 uint16_t nodetype; /**< type of the node (mandatory) */
544 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100545 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200546 const char *name; /**< node name (mandatory) */
547 const char *dsc; /**< description statement */
548 const char *ref; /**< reference statement */
549 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200550 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200551 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200552};
553
554/**
555 * @brief Extension structure of the lysp_node for YANG container
556 */
557struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100558 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200559 uint16_t nodetype; /**< LYS_CONTAINER */
560 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
561 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
562 const char *name; /**< node name (mandatory) */
563 const char *dsc; /**< description statement */
564 const char *ref; /**< reference statement */
565 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200566 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200567 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200568
569 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200570 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200571 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200572 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
573 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200574 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200575 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
576 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200577};
578
579struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100580 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200581 uint16_t nodetype; /**< LYS_LEAF */
582 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
583 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
584 const char *name; /**< node name (mandatory) */
585 const char *dsc; /**< description statement */
586 const char *ref; /**< reference statement */
587 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200588 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200589 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200590
591 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200592 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200593 struct lysp_type type; /**< type of the leaf node (mandatory) */
594 const char *units; /**< units of the leaf's type */
595 const char *dflt; /**< default value */
596};
597
598struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100599 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200600 uint16_t nodetype; /**< LYS_LEAFLIST */
601 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
602 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
603 const char *name; /**< node name (mandatory) */
604 const char *dsc; /**< description statement */
605 const char *ref; /**< reference statement */
606 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200607 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200608 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200609
610 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200611 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200612 struct lysp_type type; /**< type of the leaf node (mandatory) */
613 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200614 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200615 uint32_t min; /**< min-elements constraint */
616 uint32_t max; /**< max-elements constraint, 0 means unbounded */
617};
618
619struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100620 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200621 uint16_t nodetype; /**< LYS_LIST */
622 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
623 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
624 const char *name; /**< node name (mandatory) */
625 const char *dsc; /**< description statement */
626 const char *ref; /**< reference statement */
627 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200628 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200629 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200630
631 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200632 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200633 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200634 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
635 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200636 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200637 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
638 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200639 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200640 uint32_t min; /**< min-elements constraint */
641 uint32_t max; /**< max-elements constraint, 0 means unbounded */
642};
643
644struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100645 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200646 uint16_t nodetype; /**< LYS_CHOICE */
647 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
648 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
649 const char *name; /**< node name (mandatory) */
650 const char *dsc; /**< description statement */
651 const char *ref; /**< reference statement */
652 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200653 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200654 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200655
656 /* choice */
657 struct lysp_node *child; /**< list of data nodes (linked list) */
658 const char* dflt; /**< default case */
659};
660
661struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100662 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200663 uint16_t nodetype; /**< LYS_CASE */
664 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
665 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
666 const char *name; /**< node name (mandatory) */
667 const char *dsc; /**< description statement */
668 const char *ref; /**< reference statement */
669 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200670 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200671 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200672
673 /* case */
674 struct lysp_node *child; /**< list of data nodes (linked list) */
675};
676
677struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100678 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200679 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
680 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
681 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
682 const char *name; /**< node name (mandatory) */
683 const char *dsc; /**< description statement */
684 const char *ref; /**< reference statement */
685 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200686 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200687 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200688
689 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200690 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200691};
692
693struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100694 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200695 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200696 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
697 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
698 const char *name; /**< grouping name reference (mandatory) */
699 const char *dsc; /**< description statement */
700 const char *ref; /**< reference statement */
701 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200702 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200703 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200704
705 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200706 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
707 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200708};
709
710/**
711 * @brief YANG input-stmt and output-stmt
712 */
713struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100714 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
715 uint16_t nodetype; /**< LYS_INOUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200716 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
717 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
718 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200719 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200720 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200721};
722
723/**
724 * @brief YANG rpc-stmt and action-stmt
725 */
726struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100727 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
728 uint16_t nodetype; /**< LYS_ACTION */
729 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200730 const char *name; /**< grouping name reference (mandatory) */
731 const char *dsc; /**< description statement */
732 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200733 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200734 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
735 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100736 struct lysp_action_inout input; /**< RPC's/Action's input */
737 struct lysp_action_inout output; /**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200738 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200739};
740
741/**
742 * @brief YANG notification-stmt
743 */
744struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100745 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
746 uint16_t nodetype; /**< LYS_NOTIF */
747 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200748 const char *name; /**< grouping name reference (mandatory) */
749 const char *dsc; /**< description statement */
750 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200751 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200752 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
753 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
754 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200755 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200756 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200757};
758
759/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200760 * @brief supported YANG schema version values
761 */
762typedef enum LYS_VERSION {
763 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
764 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
765 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
766} LYS_VERSION;
767
768/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200769 * @brief Printable YANG schema tree structure representing YANG module.
770 *
771 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
772 */
773struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100774 struct lys_module *mod; /**< covering module structure */
775
Radek Krejcib7db73a2018-10-24 14:18:40 +0200776 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
777 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200778 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
779 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200780 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
781 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
782 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
783 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
784 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200785 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200786 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
787 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
788 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
789 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
790 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200791
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100792 uint8_t parsing:1; /**< flag for circular check */
793};
794
795struct lysp_submodule {
796 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
797
798 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
799 in the list is always the last (newest) revision of the module */
800 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
801 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
802 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
803 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
804 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
805 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
806 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
807 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
808 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
809 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
810 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
811 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
812 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
813
814 uint8_t parsing:1; /**< flag for circular check */
815
Radek Krejci086c7132018-10-26 15:29:04 +0200816 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
817 1 - the latest revision in searchdirs was not searched yet and this is the
818 latest revision in the current context
819 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100820 const char *name; /**< name of the module (mandatory) */
821 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
822 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
823 const char *org; /**< party/company responsible for the module */
824 const char *contact; /**< contact information for the module */
825 const char *dsc; /**< description of the module */
826 const char *ref; /**< cross-reference for the module */
Radek Krejci086c7132018-10-26 15:29:04 +0200827 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200828};
829
830/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200831 * @brief Free the printable YANG schema tree structure.
832 *
833 * @param[in] module Printable YANG schema tree structure to free.
834 */
835void lysp_module_free(struct lysp_module *module);
836
837/**
Radek Krejcice8c1592018-10-29 15:35:51 +0100838 * @brief YANG extension instance
839 */
840struct lysc_ext_instance {
841 struct lyext_plugin *plugin; /**< pointer to the plugin implementing the extension (if present) */
842 void *parent; /**< pointer to the parent element holding the extension instance(s), use
843 ::lysc_ext_instance#parent_type to access the schema element */
844 const char *argument; /**< optional value of the extension's argument */
845 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
846 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
847 this identifies the index of the substatement for this extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +0100848 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejcice8c1592018-10-29 15:35:51 +0100849#if 0
Radek Krejcice8c1592018-10-29 15:35:51 +0100850 uint8_t ext_type; /**< extension type (#LYEXT_TYPE) */
851 uint8_t padding; /**< 32b padding */
Radek Krejcice8c1592018-10-29 15:35:51 +0100852 struct lys_module *module; /**< pointer to the extension instance's module (mandatory) */
853 LYS_NODE nodetype; /**< LYS_EXT */
854#endif
Radek Krejci2a408df2018-10-29 16:32:26 +0100855 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
856 void *priv; /**< private caller's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +0100857};
858
859/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +0100860 * @brief Compiled YANG if-feature-stmt
861 */
862struct lysc_iffeature {
863 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
864 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
865};
866
867/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200868 * @brief YANG import-stmt
869 */
870struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100871 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +0200872 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejcice8c1592018-10-29 15:35:51 +0100873 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200874};
875
876/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200877 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200878 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200879struct lysc_when {
880 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +0100881 const char *dsc; /**< description */
882 const char *ref; /**< reference */
Radek Krejci00b874b2019-02-12 10:54:50 +0100883 struct lysc_node *context; /**< context node for evaluating the expression */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200884 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +0100885 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200886};
887
888/**
Radek Krejci2a408df2018-10-29 16:32:26 +0100889 * @brief YANG identity-stmt
890 */
891struct lysc_ident {
892 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +0100893 const char *dsc; /**< description */
894 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +0200895 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +0100896 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
897 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +0200898 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +0100899 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
900};
901
902/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200903 * @brief YANG feature-stmt
904 */
905struct lysc_feature {
906 const char *name; /**< feature name (mandatory) */
Radek Krejcic8b31002019-01-08 10:24:45 +0100907 const char *dsc; /**< description */
908 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +0200909 struct lys_module *module; /**< module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +0200910 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 +0100911 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +0200912 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200913 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
914 #LYS_FENABLED values allowed */
915};
916
Radek Krejci151a5b72018-10-19 14:21:44 +0200917/**
918 * @defgroup ifftokens if-feature expression tokens
919 * Tokens of if-feature expression used in ::lysc_iffeature#expr
920 *
921 * @{
922 */
923#define LYS_IFF_NOT 0x00 /**< operand "not" */
924#define LYS_IFF_AND 0x01 /**< operand "and" */
925#define LYS_IFF_OR 0x02 /**< operand "or" */
926#define LYS_IFF_F 0x03 /**< feature */
927/**
928 * @}
929 */
930
931/**
Radek Krejcib7db73a2018-10-24 14:18:40 +0200932 * @brief Compiled YANG revision statement
933 */
934struct lysc_revision {
935 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
936 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
937};
938
Radek Krejci2167ee12018-11-02 16:09:07 +0100939struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +0100940 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +0200941 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +0200942 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
943 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100944 };
Radek Krejci693262f2019-04-29 15:23:20 +0200945 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +0200946 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
947 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100948 };
Radek Krejci4f28eda2018-11-12 11:46:16 +0100949 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +0100950 const char *dsc; /**< description */
951 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +0100952 const char *emsg; /**< error-message */
953 const char *eapptag; /**< error-app-tag value */
954 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
955};
956
957struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +0200958 const char *expr; /**< original, not compiled, regular expression */
959 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +0100960 const char *dsc; /**< description */
961 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +0100962 const char *emsg; /**< error-message */
963 const char *eapptag; /**< error-app-tag value */
964 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4586a022018-11-13 11:29:26 +0100965 uint32_t inverted:1; /**< invert-match flag */
966 uint32_t refcount:31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +0100967};
968
969struct lysc_must {
970 struct lys_module *module; /**< module where the must was defined */
971 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +0100972 const char *dsc; /**< description */
973 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +0100974 const char *emsg; /**< error-message */
975 const char *eapptag; /**< error-app-tag value */
976 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
977};
978
979struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +0100980 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +0200981 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200982 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 +0200983 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 +0100984 LY_DATA_TYPE basetype; /**< Base type of the type */
985 uint32_t refcount; /**< reference counter for type sharing */
986};
987
988struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +0100989 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +0200990 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200991 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 +0200992 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 +0100993 LY_DATA_TYPE basetype; /**< Base type of the type */
994 uint32_t refcount; /**< reference counter for type sharing */
995 struct lysc_range *range; /**< Optional range limitation */
996};
997
998struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +0100999 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001000 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001001 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 +02001002 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 +01001003 LY_DATA_TYPE basetype; /**< Base type of the type */
1004 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001005 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001006 struct lysc_range *range; /**< Optional range limitation */
1007};
1008
1009struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001010 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001011 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001012 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 +02001013 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 +01001014 LY_DATA_TYPE basetype; /**< Base type of the type */
1015 uint32_t refcount; /**< reference counter for type sharing */
1016 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001017 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001018};
1019
Radek Krejci693262f2019-04-29 15:23:20 +02001020struct lysc_type_bitenum_item {
1021 const char *name; /**< enumeration identifier */
1022 const char *dsc; /**< description */
1023 const char *ref; /**< reference */
1024 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1025 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1026 union {
1027 int32_t value; /**< integer value associated with the enumeration */
1028 uint32_t position; /**< non-negative integer value associated with the bit */
1029 };
1030 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1031 values are allowed */
1032};
1033
Radek Krejci2167ee12018-11-02 16:09:07 +01001034struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001035 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001036 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001037 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 +02001038 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 +01001039 LY_DATA_TYPE basetype; /**< Base type of the type */
1040 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001041 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1042};
1043
1044struct lysc_type_bits {
1045 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1046 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001047 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 +02001048 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 +02001049 LY_DATA_TYPE basetype; /**< Base type of the type */
1050 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001051 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1052 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001053};
1054
1055struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001056 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001057 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001058 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 +02001059 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 +01001060 LY_DATA_TYPE basetype; /**< Base type of the type */
1061 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejcia3045382018-11-22 14:30:31 +01001062 const char* path; /**< target path */
Radek Krejci96a0bfd2018-11-22 15:25:06 +01001063 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 +01001064 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001065 uint8_t require_instance; /**< require-instance flag */
1066};
1067
1068struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001069 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001070 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001071 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 +02001072 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 +01001073 LY_DATA_TYPE basetype; /**< Base type of the type */
1074 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001075 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001076 mandatory (at least 1 item) */
1077};
1078
1079struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001080 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001081 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001082 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 +02001083 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 +01001084 LY_DATA_TYPE basetype; /**< Base type of the type */
1085 uint32_t refcount; /**< reference counter for type sharing */
1086 uint8_t require_instance; /**< require-instance flag */
1087};
1088
Radek Krejci2167ee12018-11-02 16:09:07 +01001089struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001090 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001091 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001092 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 +02001093 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 +01001094 LY_DATA_TYPE basetype; /**< Base type of the type */
1095 uint32_t refcount; /**< reference counter for type sharing */
1096 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1097};
1098
1099struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001100 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001101 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001102 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 +02001103 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 +01001104 LY_DATA_TYPE basetype; /**< Base type of the type */
1105 uint32_t refcount; /**< reference counter for type sharing */
1106 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001107};
1108
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001109struct lysc_action_inout {
1110 struct lysc_node *data; /**< first child node (linked list) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001111 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1112};
1113
Radek Krejci056d0a82018-12-06 16:57:25 +01001114struct lysc_action {
1115 uint16_t nodetype; /**< LYS_ACTION */
1116 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001117 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001118 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. */
1119 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1120
Radek Krejcifc11bd72019-04-11 16:00:05 +02001121 struct lysc_ext_instance *input_exts; /**< list of the extension instances of input ([sized array](@ref sizedarrays)) */
1122 struct lysc_ext_instance *output_exts; /**< list of the extension instances of outpu ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001123
Radek Krejci056d0a82018-12-06 16:57:25 +01001124 const char *name; /**< action/RPC name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001125 const char *dsc; /**< description */
1126 const char *ref; /**< reference */
1127
Radek Krejcifc11bd72019-04-11 16:00:05 +02001128 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1129 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1130
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001131 struct lysc_action_inout input; /**< RPC's/action's input */
1132 struct lysc_action_inout output; /**< RPC's/action's output */
1133
Radek Krejci056d0a82018-12-06 16:57:25 +01001134};
1135
1136struct lysc_notif {
1137 uint16_t nodetype; /**< LYS_NOTIF */
1138 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001139 struct lys_module *module; /**< module structure */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001140 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 +01001141 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1142
Radek Krejcifc11bd72019-04-11 16:00:05 +02001143 struct lysc_node *data; /**< first child node (linked list) */
1144 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1145
Radek Krejci056d0a82018-12-06 16:57:25 +01001146 const char *name; /**< Notification name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001147 const char *dsc; /**< description */
1148 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001149
1150 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1151 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001152};
1153
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001154/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001155 * @brief Compiled YANG data node
1156 */
1157struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001158 uint16_t nodetype; /**< type of the node (mandatory) */
1159 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001160 struct lys_module *module; /**< module structure */
1161 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. */
1162 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1163 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1164 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1165 never NULL. If there is no sibling node, pointer points to the node
1166 itself. In case of the first node, this pointer points to the last
1167 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001168 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001169 const char *dsc; /**< description */
1170 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001171 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001172 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001173 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001174};
1175
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001176struct lysc_node_container {
1177 uint16_t nodetype; /**< LYS_CONTAINER */
1178 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1179 struct lys_module *module; /**< module structure */
1180 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. */
1181 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1182 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1183 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1184 never NULL. If there is no sibling node, pointer points to the node
1185 itself. In case of the first node, this pointer points to the last
1186 node in the list. */
1187 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001188 const char *dsc; /**< description */
1189 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001190 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001191 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001192 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001193
1194 struct lysc_node *child; /**< first child node (linked list) */
1195 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1196 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1197 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001198};
1199
Radek Krejcia3045382018-11-22 14:30:31 +01001200struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001201 uint16_t nodetype; /**< LYS_CASE */
1202 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1203 struct lys_module *module; /**< module structure */
1204 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. */
1205 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1206 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1207 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1208 never NULL. If there is no sibling node, pointer points to the node
1209 itself. In case of the first node, this pointer points to the last
1210 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001211 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001212 const char *dsc; /**< description */
1213 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001214 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001215 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001216 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001217
Radek Krejcia3045382018-11-22 14:30:31 +01001218 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 +01001219 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001220};
1221
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001222struct lysc_node_choice {
1223 uint16_t nodetype; /**< LYS_CHOICE */
1224 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1225 struct lys_module *module; /**< module structure */
1226 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. */
1227 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1228 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1229 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1230 never NULL. If there is no sibling node, pointer points to the node
1231 itself. In case of the first node, this pointer points to the last
1232 node in the list. */
1233 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001234 const char *dsc; /**< description */
1235 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001236 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001237 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001238 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001239
Radek Krejcia9026eb2018-12-12 16:04:47 +01001240 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1241 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1242 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001243 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001244};
1245
1246struct lysc_node_leaf {
1247 uint16_t nodetype; /**< LYS_LEAF */
1248 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1249 struct lys_module *module; /**< module structure */
1250 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. */
1251 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1252 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1253 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1254 never NULL. If there is no sibling node, pointer points to the node
1255 itself. In case of the first node, this pointer points to the last
1256 node in the list. */
1257 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001258 const char *dsc; /**< description */
1259 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001260 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001261 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001262 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001263
1264 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1265 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001266
Radek Krejci4f28eda2018-11-12 11:46:16 +01001267 const char *units; /**< units of the leaf's type */
Radek Krejcia1911222019-07-22 17:24:50 +02001268 struct lyd_value *dflt; /**< default value */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001269 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 +01001270};
1271
1272struct lysc_node_leaflist {
1273 uint16_t nodetype; /**< LYS_LEAFLIST */
1274 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1275 struct lys_module *module; /**< module structure */
1276 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. */
1277 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1278 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1279 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1280 never NULL. If there is no sibling node, pointer points to the node
1281 itself. In case of the first node, this pointer points to the last
1282 node in the list. */
1283 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001284 const char *dsc; /**< description */
1285 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001286 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001287 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001288 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001289
1290 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1291 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1292
Radek Krejci0e5d8382018-11-28 16:37:53 +01001293 const char *units; /**< units of the leaf's type */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001294 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values */
1295 struct lys_module **dflts_mods; /**< list ([sized array](@ref sizedarrays)) of modules where the lysc_node_leaflist::dflts values were defined
1296 (needed to correctly map prefixes). */
Radek Krejci0e5d8382018-11-28 16:37:53 +01001297 uint32_t min; /**< min-elements constraint */
1298 uint32_t max; /**< max-elements constraint */
1299
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001300};
1301
1302struct lysc_node_list {
1303 uint16_t nodetype; /**< LYS_LIST */
1304 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1305 struct lys_module *module; /**< module structure */
1306 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. */
1307 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1308 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1309 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1310 never NULL. If there is no sibling node, pointer points to the node
1311 itself. In case of the first node, this pointer points to the last
1312 node in the list. */
1313 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001314 const char *dsc; /**< description */
1315 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001316 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001317 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001318 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001319
1320 struct lysc_node *child; /**< first child node (linked list) */
1321 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1322 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1323 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1324
1325 struct lysc_node_leaf **keys; /**< list of pointers to the keys ([sized array](@ref sizedarrays)) */
1326 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1327 uint32_t min; /**< min-elements constraint */
1328 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001329};
1330
1331struct lysc_node_anydata {
1332 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1333 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1334 struct lys_module *module; /**< module structure */
1335 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. */
1336 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1337 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1338 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1339 never NULL. If there is no sibling node, pointer points to the node
1340 itself. In case of the first node, this pointer points to the last
1341 node in the list. */
1342 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001343 const char *dsc; /**< description */
1344 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001345 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001346 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001347 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9800fb82018-12-13 14:26:23 +01001348
1349 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001350};
1351
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001352/**
1353 * @brief Compiled YANG schema tree structure representing YANG module.
1354 *
1355 * Semantically validated YANG schema tree for data tree parsing.
1356 * Contains only the necessary information for the data validation.
1357 */
1358struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001359 struct lys_module *mod; /**< covering module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001360 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001361
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001362 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001363 struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1364 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1365 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1366 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001367 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001368};
1369
1370/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001371 * @brief Get the groupings sized array of the given (parsed) schema node.
1372 * Decides the node's type and in case it has a groupings array, returns it.
1373 * @param[in] node Node to examine.
1374 * @return The node's groupings sized array if any, NULL otherwise.
1375 */
1376const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1377
1378/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001379 * @brief Get the typedefs sized array of the given (parsed) schema node.
1380 * Decides the node's type and in case it has a typedefs array, returns it.
1381 * @param[in] node Node to examine.
1382 * @return The node's typedefs sized array if any, NULL otherwise.
1383 */
1384const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1385
1386/**
1387 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1388 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1389 * @param[in] node Node to examine.
1390 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1391 */
1392const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1393
1394/**
1395 * @brief Get the Notifications sized array of the given (parsed) schema node.
1396 * Decides the node's type and in case it has a Notifications array, returns it.
1397 * @param[in] node Node to examine.
1398 * @return The node's Notifications sized array if any, NULL otherwise.
1399 */
1400const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1401
1402/**
1403 * @brief Get the children linked list of the given (parsed) schema node.
1404 * Decides the node's type and in case it has a children list, returns it.
1405 * @param[in] node Node to examine.
1406 * @return The node's children linked list if any, NULL otherwise.
1407 */
1408const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1409
1410/**
1411 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1412 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1413 * @param[in] node Node to examine.
1414 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1415 */
1416const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1417
1418/**
1419 * @brief Get the Notifications sized array of the given (compiled) schema node.
1420 * Decides the node's type and in case it has a Notifications array, returns it.
1421 * @param[in] node Node to examine.
1422 * @return The node's Notifications sized array if any, NULL otherwise.
1423 */
1424const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1425
1426/**
1427 * @brief Get the children linked list of the given (compiled) schema node.
1428 * Decides the node's type and in case it has a children list, returns it.
1429 * @param[in] node Node to examine.
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001430 * @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 +01001431 * @return The node's children linked list if any, NULL otherwise.
1432 */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001433const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Radek Krejci056d0a82018-12-06 16:57:25 +01001434
1435/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001436 * @brief Get how the if-feature statement currently evaluates.
1437 *
1438 * @param[in] iff Compiled if-feature statement to evaluate.
1439 * @return If the statement evaluates to true, 1 is returned. 0 is returned when the statement evaluates to false.
1440 */
1441int lysc_iffeature_value(const struct lysc_iffeature *iff);
1442
1443/**
1444 * @brief Get the current status of the provided feature.
1445 *
1446 * @param[in] feature Compiled feature statement to examine.
1447 * @return
1448 * - 1 if feature is enabled,
1449 * - 0 if feature is disabled,
1450 * - -1 in case of error (invalid argument)
1451 */
1452int lysc_feature_value(const struct lysc_feature *feature);
1453
1454/**
Radek Krejci327de162019-06-14 12:52:07 +02001455 * @brief Generate path of the given node in the requested format.
1456 *
1457 * @param[in] node Schema path of this node will be generated.
1458 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001459 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
1460 * If NULL, memory for the complete path is allocated.
1461 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02001462 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001463 * 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 +02001464 */
Radek Krejci1c0c3442019-07-23 16:08:47 +02001465char *lysc_path(struct lysc_node *node, LY_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02001466
1467/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001468 * @brief Available YANG schema tree structures representing YANG module.
1469 */
1470struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001471 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
1472 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01001473 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001474 const char *ns; /**< namespace of the module (module - mandatory) */
1475 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
1476 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1477 const char *org; /**< party/company responsible for the module */
1478 const char *contact; /**< contact information for the module */
1479 const char *dsc; /**< description of the module */
1480 const char *ref; /**< cross-reference for the module */
1481
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001482 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01001483 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
1484 Available only for implemented modules. */
1485 struct lysc_feature *off_features;/**< List of pre-compiled features of the module in non implemented modules ([sized array](@ref sizedarrays)).
1486 These features are always disabled and cannot be enabled until the module
1487 become implemented. The features are present in this form to allow their linkage
1488 from if-feature statements of the compiled schemas and their proper use in case
1489 the module became implemented in future (no matter if implicitly via augment/deviate
1490 or explicitly via ly_ctx_module_implement()). */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001491
Radek Krejci95710c92019-02-11 15:49:55 +01001492 uint8_t implemented; /**< flag if the module is implemented, not just imported. The module is implemented if
1493 the flag has non-zero value. Specific values are used internally:
1494 1 - implemented module
1495 2 - recently implemented module by dependency, it can be reverted in rollback procedure */
1496 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001497 1 - the latest revision in searchdirs was not searched yet and this is the
1498 latest revision in the current context
1499 2 - searchdirs were searched and this is the latest available revision */
1500 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001501};
1502
Radek Krejci151a5b72018-10-19 14:21:44 +02001503/**
1504 * @brief Enable specified feature in the module
1505 *
1506 * By default, when the module is loaded by libyang parser, all features are disabled.
1507 *
Radek Krejcica3db002018-11-01 10:31:01 +01001508 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
1509 * enabling all features on the following feature set will fail since it is not possible to enable both features
1510 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
1511 * is untouched.
1512 *
1513 * feature f1;
1514 * feature f2 { if-feature 'not f1';}
1515 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001516 * @param[in] module Module where the feature will be enabled.
1517 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
1518 * @return LY_ERR value.
1519 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001520LY_ERR lys_feature_enable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001521
1522/**
1523 * @brief Disable specified feature in the module
1524 *
1525 * By default, when the module is loaded by libyang parser, all features are disabled.
1526 *
1527 * @param[in] module Module where the feature will be disabled.
1528 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
1529 * @return LY_ERR value
1530 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001531LY_ERR lys_feature_disable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001532
1533/**
1534 * @brief Get the current status of the specified feature in the module.
1535 *
1536 * @param[in] module Module where the feature is defined.
1537 * @param[in] feature Name of the feature to inspect.
1538 * @return
1539 * - 1 if feature is enabled,
1540 * - 0 if feature is disabled,
1541 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
1542 */
1543int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001544
1545/**
Radek Krejci86d106e2018-10-18 09:53:19 +02001546 * @brief Load a schema into the specified context.
1547 *
1548 * @param[in] ctx libyang context where to process the data model.
1549 * @param[in] data The string containing the dumped data model in the specified
1550 * format.
1551 * @param[in] format Format of the input data (YANG or YIN).
1552 * @return Pointer to the data model structure or NULL on error.
1553 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001554struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001555
1556/**
1557 * @brief Read a schema from file descriptor into the specified context.
1558 *
1559 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
1560 *
1561 * @param[in] ctx libyang context where to process the data model.
1562 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
1563 * in the specified format.
1564 * @param[in] format Format of the input data (YANG or YIN).
1565 * @return Pointer to the data model structure or NULL on error.
1566 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001567struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001568
1569/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001570 * @brief Read a schema into the specified context from a file.
Radek Krejci86d106e2018-10-18 09:53:19 +02001571 *
1572 * @param[in] ctx libyang context where to process the data model.
1573 * @param[in] path Path to the file with the model in the specified format.
1574 * @param[in] format Format of the input data (YANG or YIN).
1575 * @return Pointer to the data model structure or NULL on error.
1576 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001577struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001578
1579/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001580 * @brief Search for the schema file in the specified searchpaths.
1581 *
1582 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
1583 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
1584 * result of the ly_ctx_get_searchdirs().
1585 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
1586 * @param[in] name Name of the schema to find.
1587 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
1588 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
1589 * complying the provided restriction is found, NULL is set.
1590 * @param[out] format Optional output variable containing expected format of the schema document according to the
1591 * file suffix.
1592 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
1593 */
1594LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
1595
1596/**
Radek Krejcia3045382018-11-22 14:30:31 +01001597 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
1598 * be from an augment.
1599 *
1600 * lys_getnext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
1601 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
1602 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
1603 * \p parent and \p module parameters.
1604 *
1605 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
1606 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
1607 * all the schema nodes are iteratively returned.
1608 *
1609 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
1610 * @param[in] parent Parent of the subtree where the function starts processing.
1611 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
1612 * module must be specified.
1613 * @param[in] options [ORed options](@ref sgetnextflags).
1614 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
1615 */
1616const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
1617 const struct lysc_module *module, int options);
1618
1619/**
1620 * @defgroup sgetnextflags lys_getnext() flags
1621 * @ingroup schematree
1622 *
1623 * @{
1624 */
1625#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 +01001626#define LYS_GETNEXT_NOCHOICE 0x02 /**< lys_getnext() option to ignore (kind of conditional) nodes within choice node */
Radek Krejci056d0a82018-12-06 16:57:25 +01001627#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 +01001628#define LYS_GETNEXT_INTONPCONT 0x40 /**< lys_getnext() option to look into non-presence container, instead of returning container itself */
1629#define LYS_GETNEXT_NOSTATECHECK 0x100 /**< lys_getnext() option to skip checking module validity (import-only, disabled) and
1630 relevant if-feature conditions state */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001631#define LYS_GETNEXT_OUTPUT 0x200 /**< lys_getnext() option to provide RPC's/action's output schema nodes instead of input schema nodes
1632 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01001633/** @} sgetnextflags */
1634
1635/**
1636 * @brief Get child node according to the specified criteria.
1637 *
1638 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
1639 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
1640 * @param[in] name Name of the node to find.
1641 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
1642 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
1643 * Used as a bitmask, so multiple nodetypes can be specified.
1644 * @param[in] options [ORed options](@ref sgetnextflags).
1645 * @return Found node if any.
1646 */
1647const struct lysc_node *lys_child(const struct lysc_node *parent, const struct lys_module *module,
1648 const char *name, size_t name_len, uint16_t nodetype, int options);
1649
1650/**
1651 * @brief Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statement
1652 * affecting the node.
1653 *
1654 * @param[in] node Schema node to check.
1655 * @param[in] recursive - 0 to check if-feature only in the \p node schema node,
1656 * - 1 to check if-feature in all ascendant schema nodes until there is a node possibly having an instance in a data tree
1657 * @return - NULL if enabled,
1658 * - pointer to the node with the unsatisfied (disabling) if-feature expression.
1659 */
1660const struct lysc_iffeature *lys_is_disabled(const struct lysc_node *node, int recursive);
1661
Radek Krejci084289f2019-07-09 17:35:30 +02001662/**
1663 * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
1664 *
1665 * This function check just the type's restriction, if you want to check also the data tree context (e.g. in case of
1666 * require-instance restriction), use lyd_value_validate().
1667 *
1668 * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
1669 * @param[in] node Schema node for the @p value.
1670 * @param[in] value String value to be checked.
1671 * @param[in] value_len Length of the given @p value (mandatory).
1672 * @param[in] get_prefix Callback function to resolve prefixes used in the @p value string.
1673 * @param[in] get_prefix_data Private data for the @p get_prefix callback.
1674 * @param[in] format Input format of the @p value.
1675 * @return LY_SUCCESS on success
1676 * @return LY_ERR value if an error occurred.
1677 */
1678LY_ERR lys_value_validate(struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len,
1679 ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format);
1680
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001681/** @} */
1682
Radek Krejci70853c52018-10-15 14:46:16 +02001683#ifdef __cplusplus
1684}
1685#endif
1686
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001687#endif /* LY_TREE_SCHEMA_H_ */