blob: f01ad6ec2c6d15ff706c9b3057a5cf55ded3ecc7 [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) */
David Sedlákae4b4512019-08-14 10:45:56 +0200128 uint16_t flags; /**< statement flags, can be se to LYS_YIN */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200129};
David Sedlákae4b4512019-08-14 10:45:56 +0200130
131#define LYS_YIN 0x1 /**< used to specify input format of extension instance */
132
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200133/**
134 * @brief YANG extension instance
135 */
136struct lysp_ext_instance {
David Sedlákbbd06ca2019-06-27 14:15:38 +0200137 const char *name; /**< extension identifier, including possible prefix */
138 const char *argument; /**< optional value of the extension's argument */
139 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
140 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
141 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
142 the index of that substatement */
David Sedlákae4b4512019-08-14 10:45:56 +0200143 uint8_t yin; /** flag for YIN source format, can be set to LYS_YIN */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200144};
145
146/**
147 * @brief YANG feature-stmt
148 */
149struct lysp_feature {
150 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200151 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200152 const char *dsc; /**< description statement */
153 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200154 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200155 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
156};
157
158/**
159 * @brief YANG identity-stmt
160 */
161struct lysp_ident {
162 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200163 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
164 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200165 const char *dsc; /**< description statement */
166 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200167 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200168 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
169};
170
Michal Vasko71e64ca2018-09-07 16:30:29 +0200171/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200172 * @brief Covers restrictions: range, length, pattern, must
173 */
174struct lysp_restr {
175 const char *arg; /**< The restriction expression/value (mandatory);
176 in case of pattern restriction, the first byte has a special meaning:
177 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
178 const char *emsg; /**< error-message */
179 const char *eapptag; /**< error-app-tag value */
180 const char *dsc; /**< description */
181 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200182 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200183};
184
185/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200186 * @brief YANG revision-stmt
187 */
188struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200189 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200190 const char *dsc; /**< description statement */
191 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200192 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200193};
194
195/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200196 * @brief Enumeration/Bit value definition
197 */
198struct lysp_type_enum {
199 const char *name; /**< name (mandatory) */
200 const char *dsc; /**< description statement */
201 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200202 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200203 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200204 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200205 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
206 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200207};
208
209/**
210 * @brief YANG type-stmt
211 *
212 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
213 */
214struct lysp_type {
215 const char *name; /**< name of the type (mandatory) */
216 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
217 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200218 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
219 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
220 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200221 const char *path; /**< path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200222 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200223 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
224 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200225
Radek Krejci2167ee12018-11-02 16:09:07 +0100226 struct lysc_type *compiled; /**< pointer to the compiled type */
227
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200228 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
229 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100230 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200231};
232
233/**
234 * @brief YANG typedef-stmt
235 */
236struct lysp_tpdf {
237 const char *name; /**< name of the newly defined type (mandatory) */
238 const char *units; /**< units of the newly defined type */
239 const char *dflt; /**< default value of the newly defined type */
240 const char *dsc; /**< description statement */
241 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200242 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200243 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100244 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200245};
246
247/**
248 * @brief YANG grouping-stmt
249 */
250struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100251 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
252 uint16_t nodetype; /**< LYS_GROUPING */
253 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200254 const char *name; /**< grouping name (mandatory) */
255 const char *dsc; /**< description statement */
256 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200257 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
258 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200259 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200260 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
261 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
262 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200263};
264
265/**
266 * @brief YANG when-stmt
267 */
268struct lysp_when {
269 const char *cond; /**< specified condition (mandatory) */
270 const char *dsc; /**< description statement */
271 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200272 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200273};
274
275/**
276 * @brief YANG refine-stmt
277 */
278struct lysp_refine {
279 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
280 const char *dsc; /**< description statement */
281 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200282 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200283 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200284 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200285 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200286 uint32_t min; /**< min-elements constraint */
287 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200288 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200289 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
290};
291
292/**
293 * @brief YANG uses-augment-stmt and augment-stmt
294 */
295struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100296 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
297 uint16_t nodetype; /**< LYS_AUGMENT */
298 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200299 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
300 const char *dsc; /**< description statement */
301 const char *ref; /**< reference statement */
302 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200303 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200304 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200305 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
306 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
307 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200308};
309
310/**
311 * @defgroup deviatetypes Deviate types
312 * @{
313 */
314#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
315#define LYS_DEV_ADD 2 /**< deviate type add */
316#define LYS_DEV_DELETE 3 /**< deviate type delete */
317#define LYS_DEV_REPLACE 4 /**< deviate type replace */
318/** @} */
319
320/**
321 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
322 */
323struct lysp_deviate {
324 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
325 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200326 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200327};
328
329struct lysp_deviate_add {
330 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
331 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200332 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200333 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200334 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200335 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
336 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200337 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
338 uint32_t min; /**< min-elements constraint */
339 uint32_t max; /**< max-elements constraint, 0 means unbounded */
340};
341
342struct lysp_deviate_del {
343 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
344 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200345 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200346 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200347 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200348 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
349 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200350};
351
352struct lysp_deviate_rpl {
353 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
354 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200355 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200356 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200357 const char *units; /**< units of the values */
358 const char *dflt; /**< default value */
359 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
360 uint32_t min; /**< min-elements constraint */
361 uint32_t max; /**< max-elements constraint, 0 means unbounded */
362};
363
364struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200365 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200366 const char *dsc; /**< description statement */
367 const char *ref; /**< reference statement */
368 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200369 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200370};
371
Radek Krejci4f28eda2018-11-12 11:46:16 +0100372/**
373 * @defgroup spnodeflags Parsed schema nodes flags
374 * @ingroup snodeflags
375 *
376 * Various flags for parsed schema nodes.
377 *
378 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
379 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200380 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100381 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
382 * 5 - list 10 - input 15 - typedef 20 - deviate
383 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200384 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
385 * 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
386 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
387 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
388 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
389 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
390 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
391 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
392 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
393 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
394 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
395 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
396 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
397 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
398 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
399 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
400 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
401 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
402 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
403 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
404 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
405 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
406 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
407 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
408 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
409 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
410 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
411 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
412 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
413 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
414 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
415 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
416 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
417 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
418 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
419 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
420 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
421 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
422 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200423 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
David Sedlákae4b4512019-08-14 10:45:56 +0200424 * LYS_YIN_ATTR | | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejcid3ca0632019-04-16 16:54:54 +0200425 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100426 *
427 */
428
429/**
430 * @defgroup scnodeflags Compiled schema nodes flags
431 * @ingroup snodeflags
432 *
433 * Various flags for compiled schema nodes.
434 *
435 * 1 - container 6 - anydata/anyxml 11 - output
436 * 2 - choice 7 - case 12 - feature
437 * 3 - leaf 8 - notification 13 - identity
438 * 4 - leaflist 9 - rpc 14 - extension
Radek Krejci693262f2019-04-29 15:23:20 +0200439 * 5 - list 10 - input 15 - bitenum
Radek Krejci4f28eda2018-11-12 11:46:16 +0100440 *
Radek Krejci693262f2019-04-29 15:23:20 +0200441 * 1 1 1 1 1 1
442 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
443 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
444 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | |
445 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
446 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | |
447 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
448 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x| |
449 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
450 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x| |
451 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
452 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x| |
453 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
454 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | | |
455 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
456 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | | |
457 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | |
458 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
459 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | |
460 * LYS_PRESENCE |x| | | | | | | | | | | | | | |
461 * LYS_UNIQUE | | |x| | | | | | | | | | | | |
462 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
463 * 9 LYS_KEY | | |x| | | | | | | | | | | | |
464 * LYS_FENABLED | | | | | | | | | | | |x| | | |
465 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
466 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | | |
467 * LYS_ISENUM | | | | | | | | | | | | | | |x|
Radek Krejci0fe9b512019-07-26 17:51:05 +0200468 * LYS_KEYLESS | | | | |x| | | | | | | | | | |
Radek Krejci693262f2019-04-29 15:23:20 +0200469 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
470 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | | |
471 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci1c0c3442019-07-23 16:08:47 +0200472 * 12 LYS_SET_CONFIG |x|x|x|x|x|x|x| | |x|x| | | | |
Radek Krejci693262f2019-04-29 15:23:20 +0200473 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100474 *
475 */
476
477/**
478 * @defgroup snodeflags Schema nodes flags
479 * @ingroup schematree
480 * @{
481 */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200482#define LYS_CONFIG_W 0x01 /**< config true; */
483#define LYS_CONFIG_R 0x02 /**< config false; */
484#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100485#define LYS_STATUS_CURR 0x04 /**< status current; */
486#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
487#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
488#define LYS_STATUS_MASK 0x1C /**< mask for status value */
489#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100490 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
491 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
492 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
493 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100494#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
495 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
496 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100497#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100498#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, applicable only to ::lysc_node_container */
499#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
500#define LYS_KEY 0x100 /**< flag for leafs being a key of a list, applicable only to ::lysc_node_leaf */
Radek Krejci0fe9b512019-07-26 17:51:05 +0200501#define LYS_KEYLESS 0x200 /**< flag for list without any key, applicable only to ::lysc_node_list */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100502#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysc_feature */
Radek Krejcife909632019-02-12 15:34:42 +0100503#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 +0100504 ::lysc_node_list/::lysp_node_list */
505#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
506 ::lysc_node_list/::lysp_node_list */
507#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
508#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
509#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
510#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200511#define LYS_USED_GRP 0x400 /**< internal flag for validating not-instantiated groupings
512 (resp. do not validate again the instantiated groupings). */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100513#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100514#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200515#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100516
517#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
518#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
519#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
520#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
521#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
522#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
523#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
524#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
525#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
526#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100527#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 +0100528 cases of choice. This information is important for refines, since it is prohibited to make leafs
529 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100530 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
531 between own default or the default values taken from the type. */
532#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 +0100533#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 +0100534
Radek Krejcid3ca0632019-04-16 16:54:54 +0200535#define LYS_SINGLEQUOTED 0x100 /**< flag for single-quoted argument of an extension instance's substatement */
536#define LYS_DOUBLEQUOTED 0x200 /**< flag for double-quoted argument of an extension instance's substatement */
537
David Sedlákae4b4512019-08-14 10:45:56 +0200538#define LYS_YIN_ATTR 0x400 /**< flag to identify YIN attribute */
David Sedlákbbd06ca2019-06-27 14:15:38 +0200539
Radek Krejci693262f2019-04-29 15:23:20 +0200540#define LYS_ISENUM 0x200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
541
Radek Krejcife909632019-02-12 15:34:42 +0100542#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100543/** @} */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200544
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200545/**
546 * @brief Generic YANG data node
547 */
548struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100549 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200550 uint16_t nodetype; /**< type of the node (mandatory) */
551 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100552 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200553 const char *name; /**< node name (mandatory) */
554 const char *dsc; /**< description statement */
555 const char *ref; /**< reference statement */
556 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200557 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200558 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200559};
560
561/**
562 * @brief Extension structure of the lysp_node for YANG container
563 */
564struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100565 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200566 uint16_t nodetype; /**< LYS_CONTAINER */
567 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
568 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
569 const char *name; /**< node name (mandatory) */
570 const char *dsc; /**< description statement */
571 const char *ref; /**< reference statement */
572 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200573 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200574 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200575
576 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200577 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200578 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200579 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
580 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200581 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200582 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
583 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200584};
585
586struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100587 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200588 uint16_t nodetype; /**< LYS_LEAF */
589 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
590 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
591 const char *name; /**< node name (mandatory) */
592 const char *dsc; /**< description statement */
593 const char *ref; /**< reference statement */
594 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200595 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200596 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200597
598 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200599 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200600 struct lysp_type type; /**< type of the leaf node (mandatory) */
601 const char *units; /**< units of the leaf's type */
602 const char *dflt; /**< default value */
603};
604
605struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100606 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200607 uint16_t nodetype; /**< LYS_LEAFLIST */
608 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
609 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
610 const char *name; /**< node name (mandatory) */
611 const char *dsc; /**< description statement */
612 const char *ref; /**< reference statement */
613 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200614 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200615 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200616
617 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200618 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200619 struct lysp_type type; /**< type of the leaf node (mandatory) */
620 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200621 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200622 uint32_t min; /**< min-elements constraint */
623 uint32_t max; /**< max-elements constraint, 0 means unbounded */
624};
625
626struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100627 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200628 uint16_t nodetype; /**< LYS_LIST */
629 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
630 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
631 const char *name; /**< node name (mandatory) */
632 const char *dsc; /**< description statement */
633 const char *ref; /**< reference statement */
634 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200635 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200636 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200637
638 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200639 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200640 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200641 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
642 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200643 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200644 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
645 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200646 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200647 uint32_t min; /**< min-elements constraint */
648 uint32_t max; /**< max-elements constraint, 0 means unbounded */
649};
650
651struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100652 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200653 uint16_t nodetype; /**< LYS_CHOICE */
654 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
655 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
656 const char *name; /**< node name (mandatory) */
657 const char *dsc; /**< description statement */
658 const char *ref; /**< reference statement */
659 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200660 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200661 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200662
663 /* choice */
664 struct lysp_node *child; /**< list of data nodes (linked list) */
665 const char* dflt; /**< default case */
666};
667
668struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100669 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200670 uint16_t nodetype; /**< LYS_CASE */
671 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
672 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
673 const char *name; /**< node name (mandatory) */
674 const char *dsc; /**< description statement */
675 const char *ref; /**< reference statement */
676 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200677 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200678 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200679
680 /* case */
681 struct lysp_node *child; /**< list of data nodes (linked list) */
682};
683
684struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100685 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200686 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
687 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
688 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
689 const char *name; /**< node name (mandatory) */
690 const char *dsc; /**< description statement */
691 const char *ref; /**< reference statement */
692 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200693 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200694 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200695
696 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200697 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200698};
699
700struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100701 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200702 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200703 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
704 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
705 const char *name; /**< grouping name reference (mandatory) */
706 const char *dsc; /**< description statement */
707 const char *ref; /**< reference statement */
708 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200709 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200710 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200711
712 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200713 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
714 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200715};
716
717/**
718 * @brief YANG input-stmt and output-stmt
719 */
720struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100721 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
722 uint16_t nodetype; /**< LYS_INOUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200723 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
724 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
725 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200726 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200727 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200728};
729
730/**
731 * @brief YANG rpc-stmt and action-stmt
732 */
733struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100734 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
735 uint16_t nodetype; /**< LYS_ACTION */
736 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200737 const char *name; /**< grouping name reference (mandatory) */
738 const char *dsc; /**< description statement */
739 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200740 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200741 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
742 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100743 struct lysp_action_inout input; /**< RPC's/Action's input */
744 struct lysp_action_inout output; /**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200745 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200746};
747
748/**
749 * @brief YANG notification-stmt
750 */
751struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100752 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
753 uint16_t nodetype; /**< LYS_NOTIF */
754 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200755 const char *name; /**< grouping name reference (mandatory) */
756 const char *dsc; /**< description statement */
757 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200758 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200759 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
760 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
761 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200762 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200763 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200764};
765
766/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200767 * @brief supported YANG schema version values
768 */
769typedef enum LYS_VERSION {
770 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
771 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
772 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
773} LYS_VERSION;
774
775/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200776 * @brief Printable YANG schema tree structure representing YANG module.
777 *
778 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
779 */
780struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100781 struct lys_module *mod; /**< covering module structure */
782
Radek Krejcib7db73a2018-10-24 14:18:40 +0200783 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
784 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200785 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
786 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200787 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
788 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
789 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
790 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
791 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200792 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200793 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
794 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
795 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
796 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
797 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200798
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100799 uint8_t parsing:1; /**< flag for circular check */
800};
801
802struct lysp_submodule {
803 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
804
805 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
806 in the list is always the last (newest) revision of the module */
807 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
808 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
809 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
810 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
811 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
812 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
813 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
814 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
815 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
816 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
817 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
818 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
819 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
820
821 uint8_t parsing:1; /**< flag for circular check */
822
Radek Krejci086c7132018-10-26 15:29:04 +0200823 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
824 1 - the latest revision in searchdirs was not searched yet and this is the
825 latest revision in the current context
826 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100827 const char *name; /**< name of the module (mandatory) */
828 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
829 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
830 const char *org; /**< party/company responsible for the module */
831 const char *contact; /**< contact information for the module */
832 const char *dsc; /**< description of the module */
833 const char *ref; /**< cross-reference for the module */
Radek Krejci086c7132018-10-26 15:29:04 +0200834 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200835};
836
837/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200838 * @brief Free the printable YANG schema tree structure.
839 *
840 * @param[in] module Printable YANG schema tree structure to free.
841 */
842void lysp_module_free(struct lysp_module *module);
843
844/**
Radek Krejcice8c1592018-10-29 15:35:51 +0100845 * @brief YANG extension instance
846 */
847struct lysc_ext_instance {
848 struct lyext_plugin *plugin; /**< pointer to the plugin implementing the extension (if present) */
849 void *parent; /**< pointer to the parent element holding the extension instance(s), use
850 ::lysc_ext_instance#parent_type to access the schema element */
851 const char *argument; /**< optional value of the extension's argument */
852 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
853 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
854 this identifies the index of the substatement for this extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +0100855 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejcice8c1592018-10-29 15:35:51 +0100856#if 0
Radek Krejcice8c1592018-10-29 15:35:51 +0100857 uint8_t ext_type; /**< extension type (#LYEXT_TYPE) */
858 uint8_t padding; /**< 32b padding */
Radek Krejcice8c1592018-10-29 15:35:51 +0100859 struct lys_module *module; /**< pointer to the extension instance's module (mandatory) */
860 LYS_NODE nodetype; /**< LYS_EXT */
861#endif
Radek Krejci2a408df2018-10-29 16:32:26 +0100862 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
863 void *priv; /**< private caller's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +0100864};
865
866/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +0100867 * @brief Compiled YANG if-feature-stmt
868 */
869struct lysc_iffeature {
870 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
871 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
872};
873
874/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200875 * @brief YANG import-stmt
876 */
877struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100878 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +0200879 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejcice8c1592018-10-29 15:35:51 +0100880 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200881};
882
883/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200884 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200885 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200886struct lysc_when {
887 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +0100888 const char *dsc; /**< description */
889 const char *ref; /**< reference */
Radek Krejci00b874b2019-02-12 10:54:50 +0100890 struct lysc_node *context; /**< context node for evaluating the expression */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200891 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +0100892 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200893};
894
895/**
Radek Krejci2a408df2018-10-29 16:32:26 +0100896 * @brief YANG identity-stmt
897 */
898struct lysc_ident {
899 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +0100900 const char *dsc; /**< description */
901 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +0200902 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +0100903 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
904 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +0200905 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +0100906 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
907};
908
909/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200910 * @brief YANG feature-stmt
911 */
912struct lysc_feature {
913 const char *name; /**< feature name (mandatory) */
Radek Krejcic8b31002019-01-08 10:24:45 +0100914 const char *dsc; /**< description */
915 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +0200916 struct lys_module *module; /**< module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +0200917 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 +0100918 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +0200919 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200920 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
921 #LYS_FENABLED values allowed */
922};
923
Radek Krejci151a5b72018-10-19 14:21:44 +0200924/**
925 * @defgroup ifftokens if-feature expression tokens
926 * Tokens of if-feature expression used in ::lysc_iffeature#expr
927 *
928 * @{
929 */
930#define LYS_IFF_NOT 0x00 /**< operand "not" */
931#define LYS_IFF_AND 0x01 /**< operand "and" */
932#define LYS_IFF_OR 0x02 /**< operand "or" */
933#define LYS_IFF_F 0x03 /**< feature */
934/**
935 * @}
936 */
937
938/**
Radek Krejcib7db73a2018-10-24 14:18:40 +0200939 * @brief Compiled YANG revision statement
940 */
941struct lysc_revision {
942 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
943 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
944};
945
Radek Krejci2167ee12018-11-02 16:09:07 +0100946struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +0100947 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +0200948 union { /**< min boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +0200949 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
950 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100951 };
Radek Krejci693262f2019-04-29 15:23:20 +0200952 union { /**< max boundary */
Radek Krejcie7b95092019-05-15 11:03:07 +0200953 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 ( >= LY_TYPE_DEC64) */
954 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary ( < LY_TYPE_DEC64) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100955 };
Radek Krejci4f28eda2018-11-12 11:46:16 +0100956 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +0100957 const char *dsc; /**< description */
958 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +0100959 const char *emsg; /**< error-message */
960 const char *eapptag; /**< error-app-tag value */
961 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
962};
963
964struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +0200965 const char *expr; /**< original, not compiled, regular expression */
966 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +0100967 const char *dsc; /**< description */
968 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +0100969 const char *emsg; /**< error-message */
970 const char *eapptag; /**< error-app-tag value */
971 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4586a022018-11-13 11:29:26 +0100972 uint32_t inverted:1; /**< invert-match flag */
973 uint32_t refcount:31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +0100974};
975
976struct lysc_must {
977 struct lys_module *module; /**< module where the must was defined */
978 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +0100979 const char *dsc; /**< description */
980 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +0100981 const char *emsg; /**< error-message */
982 const char *eapptag; /**< error-app-tag value */
983 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
984};
985
986struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +0100987 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +0200988 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200989 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 +0200990 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 +0100991 LY_DATA_TYPE basetype; /**< Base type of the type */
992 uint32_t refcount; /**< reference counter for type sharing */
993};
994
995struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +0100996 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +0200997 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200998 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 +0200999 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 +01001000 LY_DATA_TYPE basetype; /**< Base type of the type */
1001 uint32_t refcount; /**< reference counter for type sharing */
1002 struct lysc_range *range; /**< Optional range limitation */
1003};
1004
1005struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001006 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001007 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001008 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 +02001009 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 +01001010 LY_DATA_TYPE basetype; /**< Base type of the type */
1011 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001012 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001013 struct lysc_range *range; /**< Optional range limitation */
1014};
1015
1016struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001017 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcia1911222019-07-22 17:24:50 +02001018 struct lyd_value *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001019 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 +02001020 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 +01001021 LY_DATA_TYPE basetype; /**< Base type of the type */
1022 uint32_t refcount; /**< reference counter for type sharing */
1023 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001024 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001025};
1026
Radek Krejci693262f2019-04-29 15:23:20 +02001027struct lysc_type_bitenum_item {
1028 const char *name; /**< enumeration identifier */
1029 const char *dsc; /**< description */
1030 const char *ref; /**< reference */
1031 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1032 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1033 union {
1034 int32_t value; /**< integer value associated with the enumeration */
1035 uint32_t position; /**< non-negative integer value associated with the bit */
1036 };
1037 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1038 values are allowed */
1039};
1040
Radek Krejci2167ee12018-11-02 16:09:07 +01001041struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001042 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001043 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001044 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 +02001045 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 +01001046 LY_DATA_TYPE basetype; /**< Base type of the type */
1047 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001048 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1049};
1050
1051struct lysc_type_bits {
1052 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1053 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001054 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 +02001055 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 +02001056 LY_DATA_TYPE basetype; /**< Base type of the type */
1057 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci849a62a2019-05-22 15:29:05 +02001058 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
1059 the items are ordered by their position value. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001060};
1061
1062struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001063 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001064 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001065 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 +02001066 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 +01001067 LY_DATA_TYPE basetype; /**< Base type of the type */
1068 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejcia3045382018-11-22 14:30:31 +01001069 const char* path; /**< target path */
Radek Krejci96a0bfd2018-11-22 15:25:06 +01001070 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 +01001071 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001072 uint8_t require_instance; /**< require-instance flag */
1073};
1074
1075struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001076 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001077 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001078 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 +02001079 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 +01001080 LY_DATA_TYPE basetype; /**< Base type of the type */
1081 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001082 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001083 mandatory (at least 1 item) */
1084};
1085
1086struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001087 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001088 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001089 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 +02001090 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 +01001091 LY_DATA_TYPE basetype; /**< Base type of the type */
1092 uint32_t refcount; /**< reference counter for type sharing */
1093 uint8_t require_instance; /**< require-instance flag */
1094};
1095
Radek Krejci2167ee12018-11-02 16:09:07 +01001096struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001097 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001098 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001099 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 +02001100 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 +01001101 LY_DATA_TYPE basetype; /**< Base type of the type */
1102 uint32_t refcount; /**< reference counter for type sharing */
1103 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1104};
1105
1106struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001107 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001108 const char *dflt; /**< type's default value if any */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001109 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 +02001110 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 +01001111 LY_DATA_TYPE basetype; /**< Base type of the type */
1112 uint32_t refcount; /**< reference counter for type sharing */
1113 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001114};
1115
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001116struct lysc_action_inout {
1117 struct lysc_node *data; /**< first child node (linked list) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001118 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1119};
1120
Radek Krejci056d0a82018-12-06 16:57:25 +01001121struct lysc_action {
1122 uint16_t nodetype; /**< LYS_ACTION */
1123 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001124 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001125 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. */
1126 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1127
Radek Krejcifc11bd72019-04-11 16:00:05 +02001128 struct lysc_ext_instance *input_exts; /**< list of the extension instances of input ([sized array](@ref sizedarrays)) */
1129 struct lysc_ext_instance *output_exts; /**< list of the extension instances of outpu ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001130
Radek Krejci056d0a82018-12-06 16:57:25 +01001131 const char *name; /**< action/RPC name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001132 const char *dsc; /**< description */
1133 const char *ref; /**< reference */
1134
Radek Krejcifc11bd72019-04-11 16:00:05 +02001135 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1136 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1137
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001138 struct lysc_action_inout input; /**< RPC's/action's input */
1139 struct lysc_action_inout output; /**< RPC's/action's output */
1140
Radek Krejci056d0a82018-12-06 16:57:25 +01001141};
1142
1143struct lysc_notif {
1144 uint16_t nodetype; /**< LYS_NOTIF */
1145 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001146 struct lys_module *module; /**< module structure */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001147 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 +01001148 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1149
Radek Krejcifc11bd72019-04-11 16:00:05 +02001150 struct lysc_node *data; /**< first child node (linked list) */
1151 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1152
Radek Krejci056d0a82018-12-06 16:57:25 +01001153 const char *name; /**< Notification name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001154 const char *dsc; /**< description */
1155 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001156
1157 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1158 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001159};
1160
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001161/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001162 * @brief Compiled YANG data node
1163 */
1164struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001165 uint16_t nodetype; /**< type of the node (mandatory) */
1166 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001167 struct lys_module *module; /**< module structure */
1168 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. */
1169 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1170 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1171 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1172 never NULL. If there is no sibling node, pointer points to the node
1173 itself. In case of the first node, this pointer points to the last
1174 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001175 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001176 const char *dsc; /**< description */
1177 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001178 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001179 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001180 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001181};
1182
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001183struct lysc_node_container {
1184 uint16_t nodetype; /**< LYS_CONTAINER */
1185 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1186 struct lys_module *module; /**< module structure */
1187 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. */
1188 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1189 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1190 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1191 never NULL. If there is no sibling node, pointer points to the node
1192 itself. In case of the first node, this pointer points to the last
1193 node in the list. */
1194 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001195 const char *dsc; /**< description */
1196 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001197 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001198 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001199 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001200
1201 struct lysc_node *child; /**< first child node (linked list) */
1202 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1203 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1204 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001205};
1206
Radek Krejcia3045382018-11-22 14:30:31 +01001207struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001208 uint16_t nodetype; /**< LYS_CASE */
1209 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1210 struct lys_module *module; /**< module structure */
1211 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. */
1212 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1213 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1214 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1215 never NULL. If there is no sibling node, pointer points to the node
1216 itself. In case of the first node, this pointer points to the last
1217 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001218 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001219 const char *dsc; /**< description */
1220 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001221 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001222 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001223 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001224
Radek Krejcia3045382018-11-22 14:30:31 +01001225 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 +01001226 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001227};
1228
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001229struct lysc_node_choice {
1230 uint16_t nodetype; /**< LYS_CHOICE */
1231 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1232 struct lys_module *module; /**< module structure */
1233 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. */
1234 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1235 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1236 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1237 never NULL. If there is no sibling node, pointer points to the node
1238 itself. In case of the first node, this pointer points to the last
1239 node in the list. */
1240 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001241 const char *dsc; /**< description */
1242 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001243 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001244 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001245 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001246
Radek Krejcia9026eb2018-12-12 16:04:47 +01001247 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1248 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1249 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001250 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001251};
1252
1253struct lysc_node_leaf {
1254 uint16_t nodetype; /**< LYS_LEAF */
1255 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1256 struct lys_module *module; /**< module structure */
1257 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. */
1258 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1259 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1260 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1261 never NULL. If there is no sibling node, pointer points to the node
1262 itself. In case of the first node, this pointer points to the last
1263 node in the list. */
1264 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001265 const char *dsc; /**< description */
1266 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001267 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001268 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001269 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001270
1271 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1272 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001273
Radek Krejci4f28eda2018-11-12 11:46:16 +01001274 const char *units; /**< units of the leaf's type */
Radek Krejcia1911222019-07-22 17:24:50 +02001275 struct lyd_value *dflt; /**< default value */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001276 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 +01001277};
1278
1279struct lysc_node_leaflist {
1280 uint16_t nodetype; /**< LYS_LEAFLIST */
1281 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1282 struct lys_module *module; /**< module structure */
1283 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. */
1284 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1285 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1286 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1287 never NULL. If there is no sibling node, pointer points to the node
1288 itself. In case of the first node, this pointer points to the last
1289 node in the list. */
1290 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001291 const char *dsc; /**< description */
1292 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001293 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001294 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001295 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001296
1297 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1298 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1299
Radek Krejci0e5d8382018-11-28 16:37:53 +01001300 const char *units; /**< units of the leaf's type */
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001301 struct lyd_value **dflts; /**< list ([sized array](@ref sizedarrays)) of default values */
1302 struct lys_module **dflts_mods; /**< list ([sized array](@ref sizedarrays)) of modules where the lysc_node_leaflist::dflts values were defined
1303 (needed to correctly map prefixes). */
Radek Krejci0e5d8382018-11-28 16:37:53 +01001304 uint32_t min; /**< min-elements constraint */
1305 uint32_t max; /**< max-elements constraint */
1306
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001307};
1308
1309struct lysc_node_list {
1310 uint16_t nodetype; /**< LYS_LIST */
1311 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1312 struct lys_module *module; /**< module structure */
1313 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. */
1314 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1315 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1316 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1317 never NULL. If there is no sibling node, pointer points to the node
1318 itself. In case of the first node, this pointer points to the last
1319 node in the list. */
1320 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001321 const char *dsc; /**< description */
1322 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001323 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001324 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001325 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001326
1327 struct lysc_node *child; /**< first child node (linked list) */
1328 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1329 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1330 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1331
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001332 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1333 uint32_t min; /**< min-elements constraint */
1334 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001335};
1336
1337struct lysc_node_anydata {
1338 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1339 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1340 struct lys_module *module; /**< module structure */
1341 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. */
1342 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1343 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1344 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1345 never NULL. If there is no sibling node, pointer points to the node
1346 itself. In case of the first node, this pointer points to the last
1347 node in the list. */
1348 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001349 const char *dsc; /**< description */
1350 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001351 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001352 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001353 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9800fb82018-12-13 14:26:23 +01001354
1355 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001356};
1357
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001358/**
1359 * @brief Compiled YANG schema tree structure representing YANG module.
1360 *
1361 * Semantically validated YANG schema tree for data tree parsing.
1362 * Contains only the necessary information for the data validation.
1363 */
1364struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001365 struct lys_module *mod; /**< covering module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001366 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001367
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001368 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001369 struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1370 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1371 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1372 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001373 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001374};
1375
1376/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001377 * @brief Get the groupings sized array of the given (parsed) schema node.
1378 * Decides the node's type and in case it has a groupings array, returns it.
1379 * @param[in] node Node to examine.
1380 * @return The node's groupings sized array if any, NULL otherwise.
1381 */
1382const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1383
1384/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001385 * @brief Get the typedefs sized array of the given (parsed) schema node.
1386 * Decides the node's type and in case it has a typedefs array, returns it.
1387 * @param[in] node Node to examine.
1388 * @return The node's typedefs sized array if any, NULL otherwise.
1389 */
1390const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1391
1392/**
1393 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1394 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1395 * @param[in] node Node to examine.
1396 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1397 */
1398const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1399
1400/**
1401 * @brief Get the Notifications sized array of the given (parsed) schema node.
1402 * Decides the node's type and in case it has a Notifications array, returns it.
1403 * @param[in] node Node to examine.
1404 * @return The node's Notifications sized array if any, NULL otherwise.
1405 */
1406const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1407
1408/**
1409 * @brief Get the children linked list of the given (parsed) schema node.
1410 * Decides the node's type and in case it has a children list, returns it.
1411 * @param[in] node Node to examine.
1412 * @return The node's children linked list if any, NULL otherwise.
1413 */
1414const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1415
1416/**
1417 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1418 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1419 * @param[in] node Node to examine.
1420 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1421 */
1422const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1423
1424/**
1425 * @brief Get the Notifications sized array of the given (compiled) schema node.
1426 * Decides the node's type and in case it has a Notifications array, returns it.
1427 * @param[in] node Node to examine.
1428 * @return The node's Notifications sized array if any, NULL otherwise.
1429 */
1430const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1431
1432/**
1433 * @brief Get the children linked list of the given (compiled) schema node.
1434 * Decides the node's type and in case it has a children list, returns it.
1435 * @param[in] node Node to examine.
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001436 * @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 +01001437 * @return The node's children linked list if any, NULL otherwise.
1438 */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001439const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Radek Krejci056d0a82018-12-06 16:57:25 +01001440
1441/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001442 * @brief Get how the if-feature statement currently evaluates.
1443 *
1444 * @param[in] iff Compiled if-feature statement to evaluate.
1445 * @return If the statement evaluates to true, 1 is returned. 0 is returned when the statement evaluates to false.
1446 */
1447int lysc_iffeature_value(const struct lysc_iffeature *iff);
1448
1449/**
1450 * @brief Get the current status of the provided feature.
1451 *
1452 * @param[in] feature Compiled feature statement to examine.
1453 * @return
1454 * - 1 if feature is enabled,
1455 * - 0 if feature is disabled,
1456 * - -1 in case of error (invalid argument)
1457 */
1458int lysc_feature_value(const struct lysc_feature *feature);
1459
1460/**
Radek Krejci327de162019-06-14 12:52:07 +02001461 * @brief Generate path of the given node in the requested format.
1462 *
1463 * @param[in] node Schema path of this node will be generated.
1464 * @param[in] pathtype Format of the path to generate.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001465 * @param[in,out] buffer Prepared buffer of the @p buflen length to store the generated path.
1466 * If NULL, memory for the complete path is allocated.
1467 * @param[in] buflen Size of the provided @p buffer.
Radek Krejci327de162019-06-14 12:52:07 +02001468 * @return NULL in case of memory allocation error, path of the node otherwise.
Radek Krejci1c0c3442019-07-23 16:08:47 +02001469 * 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 +02001470 */
Radek Krejci1c0c3442019-07-23 16:08:47 +02001471char *lysc_path(struct lysc_node *node, LY_PATH_TYPE pathtype, char *buffer, size_t buflen);
Radek Krejci327de162019-06-14 12:52:07 +02001472
1473/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001474 * @brief Available YANG schema tree structures representing YANG module.
1475 */
1476struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001477 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
1478 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01001479 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001480 const char *ns; /**< namespace of the module (module - mandatory) */
1481 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
1482 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1483 const char *org; /**< party/company responsible for the module */
1484 const char *contact; /**< contact information for the module */
1485 const char *dsc; /**< description of the module */
1486 const char *ref; /**< cross-reference for the module */
1487
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001488 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01001489 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
1490 Available only for implemented modules. */
1491 struct lysc_feature *off_features;/**< List of pre-compiled features of the module in non implemented modules ([sized array](@ref sizedarrays)).
1492 These features are always disabled and cannot be enabled until the module
1493 become implemented. The features are present in this form to allow their linkage
1494 from if-feature statements of the compiled schemas and their proper use in case
1495 the module became implemented in future (no matter if implicitly via augment/deviate
1496 or explicitly via ly_ctx_module_implement()). */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001497
Radek Krejci95710c92019-02-11 15:49:55 +01001498 uint8_t implemented; /**< flag if the module is implemented, not just imported. The module is implemented if
1499 the flag has non-zero value. Specific values are used internally:
1500 1 - implemented module
1501 2 - recently implemented module by dependency, it can be reverted in rollback procedure */
1502 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001503 1 - the latest revision in searchdirs was not searched yet and this is the
1504 latest revision in the current context
1505 2 - searchdirs were searched and this is the latest available revision */
1506 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001507};
1508
Radek Krejci151a5b72018-10-19 14:21:44 +02001509/**
1510 * @brief Enable specified feature in the module
1511 *
1512 * By default, when the module is loaded by libyang parser, all features are disabled.
1513 *
Radek Krejcica3db002018-11-01 10:31:01 +01001514 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
1515 * enabling all features on the following feature set will fail since it is not possible to enable both features
1516 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
1517 * is untouched.
1518 *
1519 * feature f1;
1520 * feature f2 { if-feature 'not f1';}
1521 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001522 * @param[in] module Module where the feature will be enabled.
1523 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
1524 * @return LY_ERR value.
1525 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001526LY_ERR lys_feature_enable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001527
1528/**
1529 * @brief Disable specified feature in the module
1530 *
1531 * By default, when the module is loaded by libyang parser, all features are disabled.
1532 *
1533 * @param[in] module Module where the feature will be disabled.
1534 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
1535 * @return LY_ERR value
1536 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001537LY_ERR lys_feature_disable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001538
1539/**
1540 * @brief Get the current status of the specified feature in the module.
1541 *
1542 * @param[in] module Module where the feature is defined.
1543 * @param[in] feature Name of the feature to inspect.
1544 * @return
1545 * - 1 if feature is enabled,
1546 * - 0 if feature is disabled,
1547 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
1548 */
1549int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001550
1551/**
Radek Krejci86d106e2018-10-18 09:53:19 +02001552 * @brief Load a schema into the specified context.
1553 *
1554 * @param[in] ctx libyang context where to process the data model.
1555 * @param[in] data The string containing the dumped data model in the specified
1556 * format.
1557 * @param[in] format Format of the input data (YANG or YIN).
1558 * @return Pointer to the data model structure or NULL on error.
1559 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001560struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001561
1562/**
1563 * @brief Read a schema from file descriptor into the specified context.
1564 *
1565 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
1566 *
1567 * @param[in] ctx libyang context where to process the data model.
1568 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
1569 * in the specified format.
1570 * @param[in] format Format of the input data (YANG or YIN).
1571 * @return Pointer to the data model structure or NULL on error.
1572 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001573struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001574
1575/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001576 * @brief Read a schema into the specified context from a file.
Radek Krejci86d106e2018-10-18 09:53:19 +02001577 *
1578 * @param[in] ctx libyang context where to process the data model.
1579 * @param[in] path Path to the file with the model in the specified format.
1580 * @param[in] format Format of the input data (YANG or YIN).
1581 * @return Pointer to the data model structure or NULL on error.
1582 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001583struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001584
1585/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001586 * @brief Search for the schema file in the specified searchpaths.
1587 *
1588 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
1589 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
1590 * result of the ly_ctx_get_searchdirs().
1591 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
1592 * @param[in] name Name of the schema to find.
1593 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
1594 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
1595 * complying the provided restriction is found, NULL is set.
1596 * @param[out] format Optional output variable containing expected format of the schema document according to the
1597 * file suffix.
1598 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
1599 */
1600LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
1601
1602/**
Radek Krejcia3045382018-11-22 14:30:31 +01001603 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
1604 * be from an augment.
1605 *
1606 * lys_getnext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
1607 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
1608 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
1609 * \p parent and \p module parameters.
1610 *
1611 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
1612 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
1613 * all the schema nodes are iteratively returned.
1614 *
1615 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
1616 * @param[in] parent Parent of the subtree where the function starts processing.
1617 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
1618 * module must be specified.
1619 * @param[in] options [ORed options](@ref sgetnextflags).
1620 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
1621 */
1622const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
1623 const struct lysc_module *module, int options);
1624
1625/**
1626 * @defgroup sgetnextflags lys_getnext() flags
1627 * @ingroup schematree
1628 *
1629 * @{
1630 */
1631#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 +01001632#define LYS_GETNEXT_NOCHOICE 0x02 /**< lys_getnext() option to ignore (kind of conditional) nodes within choice node */
Radek Krejci056d0a82018-12-06 16:57:25 +01001633#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 +01001634#define LYS_GETNEXT_INTONPCONT 0x40 /**< lys_getnext() option to look into non-presence container, instead of returning container itself */
1635#define LYS_GETNEXT_NOSTATECHECK 0x100 /**< lys_getnext() option to skip checking module validity (import-only, disabled) and
1636 relevant if-feature conditions state */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001637#define LYS_GETNEXT_OUTPUT 0x200 /**< lys_getnext() option to provide RPC's/action's output schema nodes instead of input schema nodes
1638 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01001639/** @} sgetnextflags */
1640
1641/**
1642 * @brief Get child node according to the specified criteria.
1643 *
1644 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
1645 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
1646 * @param[in] name Name of the node to find.
1647 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
1648 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
1649 * Used as a bitmask, so multiple nodetypes can be specified.
1650 * @param[in] options [ORed options](@ref sgetnextflags).
1651 * @return Found node if any.
1652 */
1653const struct lysc_node *lys_child(const struct lysc_node *parent, const struct lys_module *module,
1654 const char *name, size_t name_len, uint16_t nodetype, int options);
1655
1656/**
1657 * @brief Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statement
1658 * affecting the node.
1659 *
1660 * @param[in] node Schema node to check.
1661 * @param[in] recursive - 0 to check if-feature only in the \p node schema node,
1662 * - 1 to check if-feature in all ascendant schema nodes until there is a node possibly having an instance in a data tree
1663 * @return - NULL if enabled,
1664 * - pointer to the node with the unsatisfied (disabling) if-feature expression.
1665 */
1666const struct lysc_iffeature *lys_is_disabled(const struct lysc_node *node, int recursive);
1667
Radek Krejci084289f2019-07-09 17:35:30 +02001668/**
1669 * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
1670 *
1671 * This function check just the type's restriction, if you want to check also the data tree context (e.g. in case of
1672 * require-instance restriction), use lyd_value_validate().
1673 *
1674 * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
1675 * @param[in] node Schema node for the @p value.
1676 * @param[in] value String value to be checked.
1677 * @param[in] value_len Length of the given @p value (mandatory).
1678 * @param[in] get_prefix Callback function to resolve prefixes used in the @p value string.
1679 * @param[in] get_prefix_data Private data for the @p get_prefix callback.
1680 * @param[in] format Input format of the @p value.
1681 * @return LY_SUCCESS on success
1682 * @return LY_ERR value if an error occurred.
1683 */
1684LY_ERR lys_value_validate(struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len,
1685 ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format);
1686
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001687/** @} */
1688
Radek Krejci70853c52018-10-15 14:46:16 +02001689#ifdef __cplusplus
1690}
1691#endif
1692
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001693#endif /* LY_TREE_SCHEMA_H_ */