blob: 5952a0d2186068faa427f67fccdbed07f6a26e6d [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 Krejci2167ee12018-11-02 16:09:07 +010018#include <pcre.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020019#include <stdint.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020020#include <stdio.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020021
Radek Krejcice8c1592018-10-29 15:35:51 +010022#include "extensions.h"
23
Radek Krejci70853c52018-10-15 14:46:16 +020024#ifdef __cplusplus
25extern "C" {
26#endif
27
Radek Krejci5aeea3a2018-09-05 13:29:36 +020028/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +020029 * @brief XPath representation.
30 */
31struct lyxp_expr;
32
33/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020034 * @brief Macro selector for other LY_ARRAY_* macros, do not use directly!
35 */
36#define LY_ARRAY_SELECT(_1, _2, NAME, ...) NAME
37
38/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020039 * @brief Helper macro to go through sized-arrays with a pointer iterator.
40 *
41 * Use with opening curly bracket (`{`).
42 *
43 * @param[in] ARRAY Array to go through
44 * @param[in] TYPE Type of the records in the ARRAY
45 * @param[out] ITER Iterating pointer to the item being processed in each loop
46 */
47#define LY_ARRAY_FOR_ITER(ARRAY, TYPE, ITER) \
Radek Krejci2c4e7172018-10-19 15:56:26 +020048 for (ITER = ARRAY; \
49 (ARRAY) && ((void*)ITER - (void*)ARRAY)/(sizeof(TYPE)) < (*((uint32_t*)(ARRAY) - 1)); \
Radek Krejcie53a8dc2018-10-17 12:52:40 +020050 ITER = (void*)((TYPE*)ITER + 1))
51
52/**
53 * @brief Helper macro to go through sized-arrays with a numeric iterator.
54 *
55 * Use with opening curly bracket (`{`).
56 *
57 * To access an item with the INDEX value, use always LY_ARRAY_INDEX macro!
58 *
59 * @param[in] ARRAY Array to go through
60 * @param[out] INDEX Iterating index of the item being processed in each loop
61 */
62#define LY_ARRAY_FOR_INDEX(ARRAY, INDEX) \
63 for (INDEX = 0; \
Radek Krejci2c4e7172018-10-19 15:56:26 +020064 ARRAY && INDEX < (*((uint32_t*)(ARRAY) - 1)); \
Radek Krejcie53a8dc2018-10-17 12:52:40 +020065 ++INDEX)
66
67/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +020068 * @defgroup schematree Schema Tree
69 * @{
70 *
71 * Data structures and functions to manipulate and access schema tree.
72 */
73
Radek Krejci0af5f5d2018-09-07 15:00:30 +020074/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020075 * @brief Get a number of records in the ARRAY.
Radek Krejci86d106e2018-10-18 09:53:19 +020076 *
77 * Does not check if array exists!
Radek Krejcie53a8dc2018-10-17 12:52:40 +020078 */
Radek Krejci2c4e7172018-10-19 15:56:26 +020079#define LY_ARRAY_SIZE(ARRAY) (*((uint32_t*)(ARRAY) - 1))
Radek Krejcie53a8dc2018-10-17 12:52:40 +020080
81/**
82 * @brief Sized-array iterator (for-loop).
83 *
84 * Use with opening curly bracket (`{`).
85 *
86 * There are 2 variants:
87 *
88 * LY_ARRAY_FOR(ARRAY, TYPE, ITER)
89 *
90 * Where ARRAY is a sized-array to go through, TYPE is the type of the items in the ARRAY and ITER is a pointer variable
91 * providing the items of the ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_ITER macro
92 *
93 * LY_ARRAY_FOR(ARRAY, INDEX)
94 *
95 * The ARRAY is again a sized-array to go through, the INDEX is a variable (unsigned integer) for storing iterating ARRAY's index
Radek Krejci2c4e7172018-10-19 15:56:26 +020096 * to access the items of ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_INDEX macro.
Radek Krejcie53a8dc2018-10-17 12:52:40 +020097 */
98#define LY_ARRAY_FOR(ARRAY, ...) LY_ARRAY_SELECT(__VA_ARGS__, LY_ARRAY_FOR_ITER, LY_ARRAY_FOR_INDEX)(ARRAY, __VA_ARGS__)
Radek Krejci5fac3592018-10-12 15:23:45 +020099
100/**
101 * @brief Macro to iterate via all sibling elements without affecting the list itself
102 *
103 * Works for all types of nodes despite it is data or schema tree, but all the
104 * parameters must be pointers to the same type.
105 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200106 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200107 *
108 * @param START Pointer to the starting element.
109 * @param ELEM Iterator.
110 */
111#define LY_LIST_FOR(START, ELEM) \
112 for ((ELEM) = (START); \
113 (ELEM); \
114 (ELEM) = (ELEM)->next)
115
116/**
Radek Krejci5fac3592018-10-12 15:23:45 +0200117 * @brief Macro to iterate via all sibling elements allowing to modify the list itself (e.g. removing elements)
118 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200119 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200120 *
121 * @param START Pointer to the starting element.
122 * @param NEXT Temporary storage to allow removing of the current iterator content.
123 * @param ELEM Iterator.
124 */
125#define LY_LIST_FOR_SAFE(START, NEXT, ELEM) \
126 for ((ELEM) = (START); \
127 (ELEM) ? (NEXT = (ELEM)->next, 1) : 0; \
128 (ELEM) = (NEXT))
129
130/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200131 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
132 */
133typedef enum {
134 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
135 LYS_IN_YANG = 1, /**< YANG schema input format */
136 LYS_IN_YIN = 2 /**< YIN schema input format */
137} LYS_INFORMAT;
138
139/**
140 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
141 */
142typedef enum {
143 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
144 LYS_OUT_YANG = 1, /**< YANG schema output format */
145 LYS_OUT_YIN = 2, /**< YIN schema output format */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200146 LYS_OUT_YANG_COMPILED, /**< YANG schema output format of the compiled schema tree */
147
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200148 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
149 LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
150 LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */
151} LYS_OUTFORMAT;
152
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200153#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
154
Michal Vaskob55f6c12018-09-12 11:13:15 +0200155#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
156#define LYS_CONTAINER 0x0001 /**< container statement node */
157#define LYS_CHOICE 0x0002 /**< choice statement node */
158#define LYS_LEAF 0x0004 /**< leaf statement node */
159#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
160#define LYS_LIST 0x0010 /**< list statement node */
161#define LYS_ANYXML 0x0020 /**< anyxml statement node */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200162#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 +0200163
Radek Krejcia3045382018-11-22 14:30:31 +0100164#define LYS_CASE 0x0040 /**< case statement node */
165#define LYS_USES 0x0080 /**< uses statement node */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200166#define LYS_INPUT 0x100
167#define LYS_OUTPUT 0x200
168#define LYS_INOUT 0x300
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100169#define LYS_ACTION 0x400 /**< RPC or action */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100170#define LYS_NOTIF 0x800
171#define LYS_GROUPING 0x1000
172#define LYS_AUGMENT 0x2000
173
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200174/**
Radek Krejci2167ee12018-11-02 16:09:07 +0100175 * @brief YANG built-in types
176 */
177typedef enum {
178 LY_TYPE_UNKNOWN = 0, /**< Unknown type */
179 LY_TYPE_BINARY, /**< Any binary data ([RFC 6020 sec 9.8](http://tools.ietf.org/html/rfc6020#section-9.8)) */
Radek Krejci5969f272018-11-23 10:03:58 +0100180 LY_TYPE_UINT8, /**< 8-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
181 LY_TYPE_UINT16, /**< 16-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
182 LY_TYPE_UINT32, /**< 32-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
183 LY_TYPE_UINT64, /**< 64-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
184 LY_TYPE_STRING, /**< Human-readable string ([RFC 6020 sec 9.4](http://tools.ietf.org/html/rfc6020#section-9.4)) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100185 LY_TYPE_BITS, /**< A set of bits or flags ([RFC 6020 sec 9.7](http://tools.ietf.org/html/rfc6020#section-9.7)) */
186 LY_TYPE_BOOL, /**< "true" or "false" ([RFC 6020 sec 9.5](http://tools.ietf.org/html/rfc6020#section-9.5)) */
187 LY_TYPE_DEC64, /**< 64-bit signed decimal number ([RFC 6020 sec 9.3](http://tools.ietf.org/html/rfc6020#section-9.3))*/
188 LY_TYPE_EMPTY, /**< A leaf that does not have any value ([RFC 6020 sec 9.11](http://tools.ietf.org/html/rfc6020#section-9.11)) */
189 LY_TYPE_ENUM, /**< Enumerated strings ([RFC 6020 sec 9.6](http://tools.ietf.org/html/rfc6020#section-9.6)) */
190 LY_TYPE_IDENT, /**< A reference to an abstract identity ([RFC 6020 sec 9.10](http://tools.ietf.org/html/rfc6020#section-9.10)) */
191 LY_TYPE_INST, /**< References a data tree node ([RFC 6020 sec 9.13](http://tools.ietf.org/html/rfc6020#section-9.13)) */
192 LY_TYPE_LEAFREF, /**< A reference to a leaf instance ([RFC 6020 sec 9.9](http://tools.ietf.org/html/rfc6020#section-9.9))*/
Radek Krejci2167ee12018-11-02 16:09:07 +0100193 LY_TYPE_UNION, /**< Choice of member types ([RFC 6020 sec 9.12](http://tools.ietf.org/html/rfc6020#section-9.12)) */
194 LY_TYPE_INT8, /**< 8-bit signed integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100195 LY_TYPE_INT16, /**< 16-bit signed integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100196 LY_TYPE_INT32, /**< 32-bit signed integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100197 LY_TYPE_INT64, /**< 64-bit signed integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100198} LY_DATA_TYPE;
199#define LY_DATA_TYPE_COUNT 20 /**< Number of different types */
200
Radek Krejci5969f272018-11-23 10:03:58 +0100201/**
202 * @brief Stringified YANG built-in data types
203 */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100204extern const char* ly_data_type2str[LY_DATA_TYPE_COUNT];
205
Radek Krejci2167ee12018-11-02 16:09:07 +0100206/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200207 * @brief YANG import-stmt
208 */
209struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200210 struct lys_module *module; /**< pointer to the imported module
211 (mandatory, but resolved when the referring module is completely parsed) */
212 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200213 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200214 const char *dsc; /**< description */
215 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200216 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200217 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
218};
219
220/**
221 * @brief YANG include-stmt
222 */
223struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100224 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200225 (mandatory, but resolved when the referring module is completely parsed) */
226 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200227 const char *dsc; /**< description */
228 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200229 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200230 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
231};
232
233/**
234 * @brief YANG extension-stmt
235 */
236struct lysp_ext {
237 const char *name; /**< extension name */
238 const char *argument; /**< argument name, NULL if not specified */
239 const char *dsc; /**< description statement */
240 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200241 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200242 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
243};
244
245/**
246 * @brief Helper structure for generic storage of the extension instances content.
247 */
248struct lysp_stmt {
249 const char *stmt; /**< identifier of the statement */
250 const char *arg; /**< statement's argument */
251 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200252 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200253 uint16_t flags;
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200254};
255
256/**
257 * @brief YANG extension instance
258 */
259struct lysp_ext_instance {
260 const char *name; /**< extension identifier, including possible prefix */
261 const char *argument; /**< optional value of the extension's argument */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200262 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
263 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
264 the index of that substatement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200265 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200266};
267
268/**
269 * @brief YANG feature-stmt
270 */
271struct lysp_feature {
272 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200273 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200274 const char *dsc; /**< description statement */
275 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200276 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200277 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
278};
279
280/**
281 * @brief YANG identity-stmt
282 */
283struct lysp_ident {
284 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200285 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
286 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200287 const char *dsc; /**< description statement */
288 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200289 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200290 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
291};
292
Michal Vasko71e64ca2018-09-07 16:30:29 +0200293/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200294 * @brief Covers restrictions: range, length, pattern, must
295 */
296struct lysp_restr {
297 const char *arg; /**< The restriction expression/value (mandatory);
298 in case of pattern restriction, the first byte has a special meaning:
299 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
300 const char *emsg; /**< error-message */
301 const char *eapptag; /**< error-app-tag value */
302 const char *dsc; /**< description */
303 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200304 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200305};
306
307/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200308 * @brief YANG revision-stmt
309 */
310struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200311 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200312 const char *dsc; /**< description statement */
313 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200314 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200315};
316
317/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200318 * @brief Enumeration/Bit value definition
319 */
320struct lysp_type_enum {
321 const char *name; /**< name (mandatory) */
322 const char *dsc; /**< description statement */
323 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200324 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200325 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200326 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200327 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
328 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200329};
330
331/**
332 * @brief YANG type-stmt
333 *
334 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
335 */
336struct lysp_type {
337 const char *name; /**< name of the type (mandatory) */
338 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
339 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200340 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
341 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
342 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200343 const char *path; /**< path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200344 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200345 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
346 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200347
Radek Krejci2167ee12018-11-02 16:09:07 +0100348 struct lysc_type *compiled; /**< pointer to the compiled type */
349
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200350 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
351 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100352 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200353};
354
355/**
356 * @brief YANG typedef-stmt
357 */
358struct lysp_tpdf {
359 const char *name; /**< name of the newly defined type (mandatory) */
360 const char *units; /**< units of the newly defined type */
361 const char *dflt; /**< default value of the newly defined type */
362 const char *dsc; /**< description statement */
363 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200364 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200365 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100366 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200367};
368
369/**
370 * @brief YANG grouping-stmt
371 */
372struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100373 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
374 uint16_t nodetype; /**< LYS_GROUPING */
375 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200376 const char *name; /**< grouping name (mandatory) */
377 const char *dsc; /**< description statement */
378 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200379 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
380 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200381 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200382 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
383 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
384 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200385};
386
387/**
388 * @brief YANG when-stmt
389 */
390struct lysp_when {
391 const char *cond; /**< specified condition (mandatory) */
392 const char *dsc; /**< description statement */
393 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200394 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200395};
396
397/**
398 * @brief YANG refine-stmt
399 */
400struct lysp_refine {
401 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
402 const char *dsc; /**< description statement */
403 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200404 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200405 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200406 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200407 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200408 uint32_t min; /**< min-elements constraint */
409 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200410 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200411 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
412};
413
414/**
415 * @brief YANG uses-augment-stmt and augment-stmt
416 */
417struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100418 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
419 uint16_t nodetype; /**< LYS_AUGMENT */
420 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200421 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
422 const char *dsc; /**< description statement */
423 const char *ref; /**< reference statement */
424 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200425 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200426 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200427 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
428 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
429 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200430};
431
432/**
433 * @defgroup deviatetypes Deviate types
434 * @{
435 */
436#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
437#define LYS_DEV_ADD 2 /**< deviate type add */
438#define LYS_DEV_DELETE 3 /**< deviate type delete */
439#define LYS_DEV_REPLACE 4 /**< deviate type replace */
440/** @} */
441
442/**
443 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
444 */
445struct lysp_deviate {
446 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
447 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200448 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200449};
450
451struct lysp_deviate_add {
452 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
453 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200454 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200455 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200456 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200457 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
458 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200459 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
460 uint32_t min; /**< min-elements constraint */
461 uint32_t max; /**< max-elements constraint, 0 means unbounded */
462};
463
464struct lysp_deviate_del {
465 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
466 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200467 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200468 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200469 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200470 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
471 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200472 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200473};
474
475struct lysp_deviate_rpl {
476 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
477 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200478 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200479 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200480 const char *units; /**< units of the values */
481 const char *dflt; /**< default value */
482 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
483 uint32_t min; /**< min-elements constraint */
484 uint32_t max; /**< max-elements constraint, 0 means unbounded */
485};
486
487struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200488 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200489 const char *dsc; /**< description statement */
490 const char *ref; /**< reference statement */
491 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200492 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200493};
494
Radek Krejci4f28eda2018-11-12 11:46:16 +0100495/**
496 * @defgroup spnodeflags Parsed schema nodes flags
497 * @ingroup snodeflags
498 *
499 * Various flags for parsed schema nodes.
500 *
501 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
502 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200503 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100504 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
505 * 5 - list 10 - input 15 - typedef 20 - deviate
506 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200507 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
508 * 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
509 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
510 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
511 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
512 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
513 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
514 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
515 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
516 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
517 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
518 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
519 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
520 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
521 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
522 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
523 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
524 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
525 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
526 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
527 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
528 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
529 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
530 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
531 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
532 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
533 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
534 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
535 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
536 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
537 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
538 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
539 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
540 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
541 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
542 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
543 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
544 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
545 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
546 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100547 *
548 */
549
550/**
551 * @defgroup scnodeflags Compiled schema nodes flags
552 * @ingroup snodeflags
553 *
554 * Various flags for compiled schema nodes.
555 *
556 * 1 - container 6 - anydata/anyxml 11 - output
557 * 2 - choice 7 - case 12 - feature
558 * 3 - leaf 8 - notification 13 - identity
559 * 4 - leaflist 9 - rpc 14 - extension
560 * 5 - list 10 - input
561 *
562 * 1 1 1 1 1
563 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
564 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100565 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | |
Radek Krejci4f28eda2018-11-12 11:46:16 +0100566 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100567 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | |
Radek Krejci4f28eda2018-11-12 11:46:16 +0100568 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100569 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100570 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100571 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100572 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100573 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100574 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejcife909632019-02-12 15:34:42 +0100575 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
Radek Krejci4f28eda2018-11-12 11:46:16 +0100576 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
577 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
Radek Krejcif1421c22019-02-19 13:05:20 +0100578 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | |
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100579 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejcife909632019-02-12 15:34:42 +0100580 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
581 * LYS_PRESENCE |x| | | | | | | | | | | | | |
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100582 * LYS_UNIQUE | | |x| | | | | | | | | | | |
583 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
584 * 9 LYS_KEY | | |x| | | | | | | | | | | |
585 * LYS_FENABLED | | | | | | | | | | | |x| | |
Radek Krejci76b3e962018-12-14 17:01:25 +0100586 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejciccd20f12019-02-15 14:12:27 +0100587 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
588 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
589 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
Radek Krejci93dcc392019-02-19 10:43:38 +0100590 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
591 * 11 LYS_SET_CONFIG |x|x|x|x|x|x|x| | |x|x| | | |
Radek Krejci4f28eda2018-11-12 11:46:16 +0100592 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
593 *
594 */
595
596/**
597 * @defgroup snodeflags Schema nodes flags
598 * @ingroup schematree
599 * @{
600 */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200601#define LYS_CONFIG_W 0x01 /**< config true; */
602#define LYS_CONFIG_R 0x02 /**< config false; */
603#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100604#define LYS_STATUS_CURR 0x04 /**< status current; */
605#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
606#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
607#define LYS_STATUS_MASK 0x1C /**< mask for status value */
608#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100609 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
610 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
611 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
612 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100613#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
614 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
615 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100616#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100617#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, applicable only to ::lysc_node_container */
618#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
619#define LYS_KEY 0x100 /**< flag for leafs being a key of a list, applicable only to ::lysc_node_leaf */
620#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysc_feature */
Radek Krejcife909632019-02-12 15:34:42 +0100621#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 +0100622 ::lysc_node_list/::lysp_node_list */
623#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
624 ::lysc_node_list/::lysp_node_list */
625#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
626#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
627#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
628#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
629#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100630#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200631#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100632
633#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
634#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
635#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
636#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
637#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
638#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
639#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
640#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
641#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
642#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100643#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 +0100644 cases of choice. This information is important for refines, since it is prohibited to make leafs
645 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100646 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
647 between own default or the default values taken from the type. */
648#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 +0100649#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 +0100650
Radek Krejcid3ca0632019-04-16 16:54:54 +0200651#define LYS_SINGLEQUOTED 0x100 /**< flag for single-quoted argument of an extension instance's substatement */
652#define LYS_DOUBLEQUOTED 0x200 /**< flag for double-quoted argument of an extension instance's substatement */
653
Radek Krejcife909632019-02-12 15:34:42 +0100654#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100655/** @} */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200656
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200657/**
658 * @brief Generic YANG data node
659 */
660struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100661 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200662 uint16_t nodetype; /**< type of the node (mandatory) */
663 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100664 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200665 const char *name; /**< node name (mandatory) */
666 const char *dsc; /**< description statement */
667 const char *ref; /**< reference statement */
668 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200669 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200670 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200671};
672
673/**
674 * @brief Extension structure of the lysp_node for YANG container
675 */
676struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100677 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200678 uint16_t nodetype; /**< LYS_CONTAINER */
679 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
680 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
681 const char *name; /**< node name (mandatory) */
682 const char *dsc; /**< description statement */
683 const char *ref; /**< reference statement */
684 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200685 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200686 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200687
688 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200689 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200690 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200691 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
692 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200693 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200694 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
695 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200696};
697
698struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100699 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200700 uint16_t nodetype; /**< LYS_LEAF */
701 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
702 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
703 const char *name; /**< node name (mandatory) */
704 const char *dsc; /**< description statement */
705 const char *ref; /**< reference statement */
706 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200707 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200708 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200709
710 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200711 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200712 struct lysp_type type; /**< type of the leaf node (mandatory) */
713 const char *units; /**< units of the leaf's type */
714 const char *dflt; /**< default value */
715};
716
717struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100718 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200719 uint16_t nodetype; /**< LYS_LEAFLIST */
720 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
721 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
722 const char *name; /**< node name (mandatory) */
723 const char *dsc; /**< description statement */
724 const char *ref; /**< reference statement */
725 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200726 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200727 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200728
729 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200730 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200731 struct lysp_type type; /**< type of the leaf node (mandatory) */
732 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200733 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200734 uint32_t min; /**< min-elements constraint */
735 uint32_t max; /**< max-elements constraint, 0 means unbounded */
736};
737
738struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100739 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200740 uint16_t nodetype; /**< LYS_LIST */
741 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
742 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
743 const char *name; /**< node name (mandatory) */
744 const char *dsc; /**< description statement */
745 const char *ref; /**< reference statement */
746 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200747 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200748 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200749
750 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200751 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200752 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200753 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
754 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200755 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200756 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
757 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200758 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200759 uint32_t min; /**< min-elements constraint */
760 uint32_t max; /**< max-elements constraint, 0 means unbounded */
761};
762
763struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100764 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200765 uint16_t nodetype; /**< LYS_CHOICE */
766 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
767 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
768 const char *name; /**< node name (mandatory) */
769 const char *dsc; /**< description statement */
770 const char *ref; /**< reference statement */
771 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200772 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200773 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200774
775 /* choice */
776 struct lysp_node *child; /**< list of data nodes (linked list) */
777 const char* dflt; /**< default case */
778};
779
780struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100781 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200782 uint16_t nodetype; /**< LYS_CASE */
783 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
784 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
785 const char *name; /**< node name (mandatory) */
786 const char *dsc; /**< description statement */
787 const char *ref; /**< reference statement */
788 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200789 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200790 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200791
792 /* case */
793 struct lysp_node *child; /**< list of data nodes (linked list) */
794};
795
796struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100797 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200798 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
799 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
800 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
801 const char *name; /**< node name (mandatory) */
802 const char *dsc; /**< description statement */
803 const char *ref; /**< reference statement */
804 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200805 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200806 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200807
808 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200809 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200810};
811
812struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100813 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200814 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200815 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
816 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
817 const char *name; /**< grouping name reference (mandatory) */
818 const char *dsc; /**< description statement */
819 const char *ref; /**< reference statement */
820 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200821 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200822 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200823
824 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200825 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
826 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200827};
828
829/**
830 * @brief YANG input-stmt and output-stmt
831 */
832struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100833 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
834 uint16_t nodetype; /**< LYS_INOUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200835 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
836 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
837 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200838 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200839 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200840};
841
842/**
843 * @brief YANG rpc-stmt and action-stmt
844 */
845struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100846 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
847 uint16_t nodetype; /**< LYS_ACTION */
848 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200849 const char *name; /**< grouping name reference (mandatory) */
850 const char *dsc; /**< description statement */
851 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200852 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200853 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
854 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100855 struct lysp_action_inout input; /**< RPC's/Action's input */
856 struct lysp_action_inout output; /**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200857 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200858};
859
860/**
861 * @brief YANG notification-stmt
862 */
863struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100864 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
865 uint16_t nodetype; /**< LYS_NOTIF */
866 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200867 const char *name; /**< grouping name reference (mandatory) */
868 const char *dsc; /**< description statement */
869 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200870 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200871 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
872 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
873 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200874 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200875 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200876};
877
878/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200879 * @brief supported YANG schema version values
880 */
881typedef enum LYS_VERSION {
882 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
883 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
884 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
885} LYS_VERSION;
886
887/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200888 * @brief Printable YANG schema tree structure representing YANG module.
889 *
890 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
891 */
892struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100893 struct lys_module *mod; /**< covering module structure */
894
Radek Krejcib7db73a2018-10-24 14:18:40 +0200895 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
896 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200897 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
898 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200899 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
900 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
901 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
902 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
903 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200904 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200905 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
906 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
907 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
908 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
909 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200910
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100911 uint8_t parsing:1; /**< flag for circular check */
912};
913
914struct lysp_submodule {
915 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
916
917 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
918 in the list is always the last (newest) revision of the module */
919 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
920 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
921 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
922 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
923 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
924 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
925 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
926 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
927 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
928 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
929 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
930 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
931 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
932
933 uint8_t parsing:1; /**< flag for circular check */
934
Radek Krejci086c7132018-10-26 15:29:04 +0200935 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
936 1 - the latest revision in searchdirs was not searched yet and this is the
937 latest revision in the current context
938 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100939 const char *name; /**< name of the module (mandatory) */
940 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
941 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
942 const char *org; /**< party/company responsible for the module */
943 const char *contact; /**< contact information for the module */
944 const char *dsc; /**< description of the module */
945 const char *ref; /**< cross-reference for the module */
Radek Krejci086c7132018-10-26 15:29:04 +0200946 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200947};
948
949/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200950 * @brief Free the printable YANG schema tree structure.
951 *
952 * @param[in] module Printable YANG schema tree structure to free.
953 */
954void lysp_module_free(struct lysp_module *module);
955
956/**
Radek Krejcice8c1592018-10-29 15:35:51 +0100957 * @brief YANG extension instance
958 */
959struct lysc_ext_instance {
960 struct lyext_plugin *plugin; /**< pointer to the plugin implementing the extension (if present) */
961 void *parent; /**< pointer to the parent element holding the extension instance(s), use
962 ::lysc_ext_instance#parent_type to access the schema element */
963 const char *argument; /**< optional value of the extension's argument */
964 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
965 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
966 this identifies the index of the substatement for this extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +0100967 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejcice8c1592018-10-29 15:35:51 +0100968#if 0
Radek Krejcice8c1592018-10-29 15:35:51 +0100969 uint8_t ext_type; /**< extension type (#LYEXT_TYPE) */
970 uint8_t padding; /**< 32b padding */
Radek Krejcice8c1592018-10-29 15:35:51 +0100971 struct lys_module *module; /**< pointer to the extension instance's module (mandatory) */
972 LYS_NODE nodetype; /**< LYS_EXT */
973#endif
Radek Krejci2a408df2018-10-29 16:32:26 +0100974 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
975 void *priv; /**< private caller's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +0100976};
977
978/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +0100979 * @brief Compiled YANG if-feature-stmt
980 */
981struct lysc_iffeature {
982 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
983 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
984};
985
986/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200987 * @brief YANG import-stmt
988 */
989struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100990 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +0200991 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejcice8c1592018-10-29 15:35:51 +0100992 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200993};
994
995/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200996 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200997 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200998struct lysc_when {
999 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001000 const char *dsc; /**< description */
1001 const char *ref; /**< reference */
Radek Krejci00b874b2019-02-12 10:54:50 +01001002 struct lysc_node *context; /**< context node for evaluating the expression */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001003 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001004 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001005};
1006
1007/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001008 * @brief YANG identity-stmt
1009 */
1010struct lysc_ident {
1011 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +01001012 const char *dsc; /**< description */
1013 const char *ref; /**< reference */
Radek Krejci2a408df2018-10-29 16:32:26 +01001014 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
1015 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001016 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001017 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1018};
1019
1020/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001021 * @brief YANG feature-stmt
1022 */
1023struct lysc_feature {
1024 const char *name; /**< feature name (mandatory) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001025 const char *dsc; /**< description */
1026 const char *ref; /**< reference */
Radek Krejci151a5b72018-10-19 14:21:44 +02001027 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 +01001028 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001029 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001030 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
1031 #LYS_FENABLED values allowed */
1032};
1033
Radek Krejci151a5b72018-10-19 14:21:44 +02001034/**
1035 * @defgroup ifftokens if-feature expression tokens
1036 * Tokens of if-feature expression used in ::lysc_iffeature#expr
1037 *
1038 * @{
1039 */
1040#define LYS_IFF_NOT 0x00 /**< operand "not" */
1041#define LYS_IFF_AND 0x01 /**< operand "and" */
1042#define LYS_IFF_OR 0x02 /**< operand "or" */
1043#define LYS_IFF_F 0x03 /**< feature */
1044/**
1045 * @}
1046 */
1047
1048/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001049 * @brief Compiled YANG revision statement
1050 */
1051struct lysc_revision {
1052 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1053 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1054};
1055
Radek Krejci2167ee12018-11-02 16:09:07 +01001056struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001057 struct lysc_range_part {
Radek Krejci2167ee12018-11-02 16:09:07 +01001058 union { /**< min boundary TODO decimal */
1059 int64_t min_64; /**< for int8, int16, int32 and int64 */
1060 uint64_t min_u64; /**< for uint8, uint16, uint32 and uint64 */
1061 };
1062 union { /**< max boundary TODO decimal */
1063 int64_t max_64; /**< for int8, int16, int32 and int64 */
1064 uint64_t max_u64; /**< for uint8, uint16, uint32 and uint64 */
1065 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001066 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001067 const char *dsc; /**< description */
1068 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001069 const char *emsg; /**< error-message */
1070 const char *eapptag; /**< error-app-tag value */
1071 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1072};
1073
1074struct lysc_pattern {
1075 pcre *expr; /**< compiled regular expression */
1076 pcre_extra *expr_extra; /**< additional information to speed up matching */
Radek Krejcic8b31002019-01-08 10:24:45 +01001077 const char *dsc; /**< description */
1078 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001079 const char *emsg; /**< error-message */
1080 const char *eapptag; /**< error-app-tag value */
1081 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4586a022018-11-13 11:29:26 +01001082 uint32_t inverted:1; /**< invert-match flag */
1083 uint32_t refcount:31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001084};
1085
1086struct lysc_must {
1087 struct lys_module *module; /**< module where the must was defined */
1088 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001089 const char *dsc; /**< description */
1090 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001091 const char *emsg; /**< error-message */
1092 const char *eapptag; /**< error-app-tag value */
1093 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1094};
1095
1096struct lysc_type {
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 Krejci2167ee12018-11-02 16:09:07 +01001099 LY_DATA_TYPE basetype; /**< Base type of the type */
1100 uint32_t refcount; /**< reference counter for type sharing */
1101};
1102
1103struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001104 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001105 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001106 LY_DATA_TYPE basetype; /**< Base type of the type */
1107 uint32_t refcount; /**< reference counter for type sharing */
1108 struct lysc_range *range; /**< Optional range limitation */
1109};
1110
1111struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001112 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001113 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001114 LY_DATA_TYPE basetype; /**< Base type of the type */
1115 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001116 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001117 struct lysc_range *range; /**< Optional range limitation */
1118};
1119
1120struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001121 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001122 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001123 LY_DATA_TYPE basetype; /**< Base type of the type */
1124 uint32_t refcount; /**< reference counter for type sharing */
1125 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001126 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001127};
1128
1129struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001130 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001131 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001132 LY_DATA_TYPE basetype; /**< Base type of the type */
1133 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci8b764662018-11-14 14:15:13 +01001134 struct lysc_type_enum_item {
Radek Krejci2167ee12018-11-02 16:09:07 +01001135 const char *name; /**< enumeration identifier */
Radek Krejcic8b31002019-01-08 10:24:45 +01001136 const char *dsc; /**< description */
1137 const char *ref; /**< reference */
Radek Krejci8b764662018-11-14 14:15:13 +01001138 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001139 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001140 int32_t value; /**< integer value associated with the enumeration */
1141 } *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1142};
1143
1144struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001145 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001146 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001147 LY_DATA_TYPE basetype; /**< Base type of the type */
1148 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejcia3045382018-11-22 14:30:31 +01001149 const char* path; /**< target path */
Radek Krejci96a0bfd2018-11-22 15:25:06 +01001150 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 +01001151 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001152 uint8_t require_instance; /**< require-instance flag */
1153};
1154
1155struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001156 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001157 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001158 LY_DATA_TYPE basetype; /**< Base type of the type */
1159 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001160 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001161 mandatory (at least 1 item) */
1162};
1163
1164struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001165 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001166 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001167 LY_DATA_TYPE basetype; /**< Base type of the type */
1168 uint32_t refcount; /**< reference counter for type sharing */
1169 uint8_t require_instance; /**< require-instance flag */
1170};
1171
1172struct lysc_type_bits {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001173 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001174 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001175 LY_DATA_TYPE basetype; /**< Base type of the type */
1176 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci8b764662018-11-14 14:15:13 +01001177 struct lysc_type_bits_item {
Radek Krejci2167ee12018-11-02 16:09:07 +01001178 const char *name; /**< bit identifier */
Radek Krejcic8b31002019-01-08 10:24:45 +01001179 const char *dsc; /**< description */
1180 const char *ref; /**< reference */
Radek Krejci8b764662018-11-14 14:15:13 +01001181 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001182 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001183 uint32_t position; /**< non-negative integer value associated with the bit */
1184 } *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1185};
1186
1187struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001188 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001189 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001190 LY_DATA_TYPE basetype; /**< Base type of the type */
1191 uint32_t refcount; /**< reference counter for type sharing */
1192 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1193};
1194
1195struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001196 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001197 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001198 LY_DATA_TYPE basetype; /**< Base type of the type */
1199 uint32_t refcount; /**< reference counter for type sharing */
1200 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001201};
1202
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001203struct lysc_action_inout {
1204 struct lysc_node *data; /**< first child node (linked list) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001205 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1206};
1207
Radek Krejci056d0a82018-12-06 16:57:25 +01001208struct lysc_action {
1209 uint16_t nodetype; /**< LYS_ACTION */
1210 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001211 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001212 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. */
1213 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1214
Radek Krejcifc11bd72019-04-11 16:00:05 +02001215 struct lysc_ext_instance *input_exts; /**< list of the extension instances of input ([sized array](@ref sizedarrays)) */
1216 struct lysc_ext_instance *output_exts; /**< list of the extension instances of outpu ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001217
Radek Krejci056d0a82018-12-06 16:57:25 +01001218 const char *name; /**< action/RPC name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001219 const char *dsc; /**< description */
1220 const char *ref; /**< reference */
1221
Radek Krejcifc11bd72019-04-11 16:00:05 +02001222 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1223 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1224
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001225 struct lysc_action_inout input; /**< RPC's/action's input */
1226 struct lysc_action_inout output; /**< RPC's/action's output */
1227
Radek Krejci056d0a82018-12-06 16:57:25 +01001228};
1229
1230struct lysc_notif {
1231 uint16_t nodetype; /**< LYS_NOTIF */
1232 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001233 struct lys_module *module; /**< module structure */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001234 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 +01001235 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1236
Radek Krejcifc11bd72019-04-11 16:00:05 +02001237 struct lysc_node *data; /**< first child node (linked list) */
1238 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1239
Radek Krejci056d0a82018-12-06 16:57:25 +01001240 const char *name; /**< Notification name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001241 const char *dsc; /**< description */
1242 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001243
1244 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1245 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001246};
1247
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001248/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001249 * @brief Compiled YANG data node
1250 */
1251struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001252 uint16_t nodetype; /**< type of the node (mandatory) */
1253 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001254 struct lys_module *module; /**< module structure */
1255 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. */
1256 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1257 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1258 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1259 never NULL. If there is no sibling node, pointer points to the node
1260 itself. In case of the first node, this pointer points to the last
1261 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001262 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001263 const char *dsc; /**< description */
1264 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001265 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001266 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001267 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001268};
1269
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001270struct lysc_node_container {
1271 uint16_t nodetype; /**< LYS_CONTAINER */
1272 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1273 struct lys_module *module; /**< module structure */
1274 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. */
1275 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1276 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1277 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1278 never NULL. If there is no sibling node, pointer points to the node
1279 itself. In case of the first node, this pointer points to the last
1280 node in the list. */
1281 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001282 const char *dsc; /**< description */
1283 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001284 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001285 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001286 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001287
1288 struct lysc_node *child; /**< first child node (linked list) */
1289 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1290 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1291 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001292};
1293
Radek Krejcia3045382018-11-22 14:30:31 +01001294struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001295 uint16_t nodetype; /**< LYS_CASE */
1296 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1297 struct lys_module *module; /**< module structure */
1298 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. */
1299 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1300 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1301 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1302 never NULL. If there is no sibling node, pointer points to the node
1303 itself. In case of the first node, this pointer points to the last
1304 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001305 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001306 const char *dsc; /**< description */
1307 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001308 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001309 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001310 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001311
Radek Krejcia3045382018-11-22 14:30:31 +01001312 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 +01001313 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001314};
1315
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001316struct lysc_node_choice {
1317 uint16_t nodetype; /**< LYS_CHOICE */
1318 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1319 struct lys_module *module; /**< module structure */
1320 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. */
1321 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1322 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1323 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1324 never NULL. If there is no sibling node, pointer points to the node
1325 itself. In case of the first node, this pointer points to the last
1326 node in the list. */
1327 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001328 const char *dsc; /**< description */
1329 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001330 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001331 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001332 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001333
Radek Krejcia9026eb2018-12-12 16:04:47 +01001334 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1335 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1336 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001337 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001338};
1339
1340struct lysc_node_leaf {
1341 uint16_t nodetype; /**< LYS_LEAF */
1342 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1343 struct lys_module *module; /**< module structure */
1344 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. */
1345 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1346 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1347 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1348 never NULL. If there is no sibling node, pointer points to the node
1349 itself. In case of the first node, this pointer points to the last
1350 node in the list. */
1351 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001352 const char *dsc; /**< description */
1353 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001354 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001355 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001356 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001357
1358 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1359 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001360
Radek Krejci4f28eda2018-11-12 11:46:16 +01001361 const char *units; /**< units of the leaf's type */
1362 const char *dflt; /**< default value */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001363};
1364
1365struct lysc_node_leaflist {
1366 uint16_t nodetype; /**< LYS_LEAFLIST */
1367 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1368 struct lys_module *module; /**< module structure */
1369 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. */
1370 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1371 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1372 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1373 never NULL. If there is no sibling node, pointer points to the node
1374 itself. In case of the first node, this pointer points to the last
1375 node in the list. */
1376 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001377 const char *dsc; /**< description */
1378 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001379 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001380 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001381 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001382
1383 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1384 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1385
Radek Krejci0e5d8382018-11-28 16:37:53 +01001386 const char *units; /**< units of the leaf's type */
1387 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
1388 uint32_t min; /**< min-elements constraint */
1389 uint32_t max; /**< max-elements constraint */
1390
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001391};
1392
1393struct lysc_node_list {
1394 uint16_t nodetype; /**< LYS_LIST */
1395 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1396 struct lys_module *module; /**< module structure */
1397 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. */
1398 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1399 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1400 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1401 never NULL. If there is no sibling node, pointer points to the node
1402 itself. In case of the first node, this pointer points to the last
1403 node in the list. */
1404 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001405 const char *dsc; /**< description */
1406 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001407 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001408 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001409 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001410
1411 struct lysc_node *child; /**< first child node (linked list) */
1412 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1413 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1414 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1415
1416 struct lysc_node_leaf **keys; /**< list of pointers to the keys ([sized array](@ref sizedarrays)) */
1417 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1418 uint32_t min; /**< min-elements constraint */
1419 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001420};
1421
1422struct lysc_node_anydata {
1423 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1424 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1425 struct lys_module *module; /**< module structure */
1426 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. */
1427 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1428 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1429 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1430 never NULL. If there is no sibling node, pointer points to the node
1431 itself. In case of the first node, this pointer points to the last
1432 node in the list. */
1433 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001434 const char *dsc; /**< description */
1435 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001436 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001437 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001438 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9800fb82018-12-13 14:26:23 +01001439
1440 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001441};
1442
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001443/**
1444 * @brief Compiled YANG schema tree structure representing YANG module.
1445 *
1446 * Semantically validated YANG schema tree for data tree parsing.
1447 * Contains only the necessary information for the data validation.
1448 */
1449struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001450 struct lys_module *mod; /**< covering module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001451 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001452
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001453 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001454 struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1455 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1456 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1457 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001458 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001459};
1460
1461/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001462 * @brief Get the groupings sized array of the given (parsed) schema node.
1463 * Decides the node's type and in case it has a groupings array, returns it.
1464 * @param[in] node Node to examine.
1465 * @return The node's groupings sized array if any, NULL otherwise.
1466 */
1467const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1468
1469/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001470 * @brief Get the typedefs sized array of the given (parsed) schema node.
1471 * Decides the node's type and in case it has a typedefs array, returns it.
1472 * @param[in] node Node to examine.
1473 * @return The node's typedefs sized array if any, NULL otherwise.
1474 */
1475const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1476
1477/**
1478 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1479 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1480 * @param[in] node Node to examine.
1481 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1482 */
1483const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1484
1485/**
1486 * @brief Get the Notifications sized array of the given (parsed) schema node.
1487 * Decides the node's type and in case it has a Notifications array, returns it.
1488 * @param[in] node Node to examine.
1489 * @return The node's Notifications sized array if any, NULL otherwise.
1490 */
1491const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1492
1493/**
1494 * @brief Get the children linked list of the given (parsed) schema node.
1495 * Decides the node's type and in case it has a children list, returns it.
1496 * @param[in] node Node to examine.
1497 * @return The node's children linked list if any, NULL otherwise.
1498 */
1499const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1500
1501/**
1502 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1503 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1504 * @param[in] node Node to examine.
1505 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1506 */
1507const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1508
1509/**
1510 * @brief Get the Notifications sized array of the given (compiled) schema node.
1511 * Decides the node's type and in case it has a Notifications array, returns it.
1512 * @param[in] node Node to examine.
1513 * @return The node's Notifications sized array if any, NULL otherwise.
1514 */
1515const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1516
1517/**
1518 * @brief Get the children linked list of the given (compiled) schema node.
1519 * Decides the node's type and in case it has a children list, returns it.
1520 * @param[in] node Node to examine.
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001521 * @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 +01001522 * @return The node's children linked list if any, NULL otherwise.
1523 */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001524const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Radek Krejci056d0a82018-12-06 16:57:25 +01001525
1526/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001527 * @brief Get how the if-feature statement currently evaluates.
1528 *
1529 * @param[in] iff Compiled if-feature statement to evaluate.
1530 * @return If the statement evaluates to true, 1 is returned. 0 is returned when the statement evaluates to false.
1531 */
1532int lysc_iffeature_value(const struct lysc_iffeature *iff);
1533
1534/**
1535 * @brief Get the current status of the provided feature.
1536 *
1537 * @param[in] feature Compiled feature statement to examine.
1538 * @return
1539 * - 1 if feature is enabled,
1540 * - 0 if feature is disabled,
1541 * - -1 in case of error (invalid argument)
1542 */
1543int lysc_feature_value(const struct lysc_feature *feature);
1544
1545/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001546 * @brief Available YANG schema tree structures representing YANG module.
1547 */
1548struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001549 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
1550 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01001551 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001552 const char *ns; /**< namespace of the module (module - mandatory) */
1553 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
1554 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1555 const char *org; /**< party/company responsible for the module */
1556 const char *contact; /**< contact information for the module */
1557 const char *dsc; /**< description of the module */
1558 const char *ref; /**< cross-reference for the module */
1559
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001560 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01001561 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
1562 Available only for implemented modules. */
1563 struct lysc_feature *off_features;/**< List of pre-compiled features of the module in non implemented modules ([sized array](@ref sizedarrays)).
1564 These features are always disabled and cannot be enabled until the module
1565 become implemented. The features are present in this form to allow their linkage
1566 from if-feature statements of the compiled schemas and their proper use in case
1567 the module became implemented in future (no matter if implicitly via augment/deviate
1568 or explicitly via ly_ctx_module_implement()). */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001569
Radek Krejci95710c92019-02-11 15:49:55 +01001570 uint8_t implemented; /**< flag if the module is implemented, not just imported. The module is implemented if
1571 the flag has non-zero value. Specific values are used internally:
1572 1 - implemented module
1573 2 - recently implemented module by dependency, it can be reverted in rollback procedure */
1574 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001575 1 - the latest revision in searchdirs was not searched yet and this is the
1576 latest revision in the current context
1577 2 - searchdirs were searched and this is the latest available revision */
1578 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001579};
1580
Radek Krejci151a5b72018-10-19 14:21:44 +02001581/**
1582 * @brief Enable specified feature in the module
1583 *
1584 * By default, when the module is loaded by libyang parser, all features are disabled.
1585 *
Radek Krejcica3db002018-11-01 10:31:01 +01001586 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
1587 * enabling all features on the following feature set will fail since it is not possible to enable both features
1588 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
1589 * is untouched.
1590 *
1591 * feature f1;
1592 * feature f2 { if-feature 'not f1';}
1593 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001594 * @param[in] module Module where the feature will be enabled.
1595 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
1596 * @return LY_ERR value.
1597 */
1598LY_ERR lys_feature_enable(struct lys_module *module, const char *feature);
1599
1600/**
1601 * @brief Disable specified feature in the module
1602 *
1603 * By default, when the module is loaded by libyang parser, all features are disabled.
1604 *
1605 * @param[in] module Module where the feature will be disabled.
1606 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
1607 * @return LY_ERR value
1608 */
1609LY_ERR lys_feature_disable(struct lys_module *module, const char *feature);
1610
1611/**
1612 * @brief Get the current status of the specified feature in the module.
1613 *
1614 * @param[in] module Module where the feature is defined.
1615 * @param[in] feature Name of the feature to inspect.
1616 * @return
1617 * - 1 if feature is enabled,
1618 * - 0 if feature is disabled,
1619 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
1620 */
1621int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001622
1623/**
Radek Krejci86d106e2018-10-18 09:53:19 +02001624 * @brief Load a schema into the specified context.
1625 *
1626 * @param[in] ctx libyang context where to process the data model.
1627 * @param[in] data The string containing the dumped data model in the specified
1628 * format.
1629 * @param[in] format Format of the input data (YANG or YIN).
1630 * @return Pointer to the data model structure or NULL on error.
1631 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001632struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001633
1634/**
1635 * @brief Read a schema from file descriptor into the specified context.
1636 *
1637 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
1638 *
1639 * @param[in] ctx libyang context where to process the data model.
1640 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
1641 * in the specified format.
1642 * @param[in] format Format of the input data (YANG or YIN).
1643 * @return Pointer to the data model structure or NULL on error.
1644 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001645struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001646
1647/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001648 * @brief Read a schema into the specified context from a file.
Radek Krejci86d106e2018-10-18 09:53:19 +02001649 *
1650 * @param[in] ctx libyang context where to process the data model.
1651 * @param[in] path Path to the file with the model in the specified format.
1652 * @param[in] format Format of the input data (YANG or YIN).
1653 * @return Pointer to the data model structure or NULL on error.
1654 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001655struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001656
1657/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001658 * @brief Search for the schema file in the specified searchpaths.
1659 *
1660 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
1661 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
1662 * result of the ly_ctx_get_searchdirs().
1663 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
1664 * @param[in] name Name of the schema to find.
1665 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
1666 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
1667 * complying the provided restriction is found, NULL is set.
1668 * @param[out] format Optional output variable containing expected format of the schema document according to the
1669 * file suffix.
1670 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
1671 */
1672LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
1673
1674/**
Radek Krejcia3045382018-11-22 14:30:31 +01001675 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
1676 * be from an augment.
1677 *
1678 * lys_getnext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
1679 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
1680 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
1681 * \p parent and \p module parameters.
1682 *
1683 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
1684 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
1685 * all the schema nodes are iteratively returned.
1686 *
1687 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
1688 * @param[in] parent Parent of the subtree where the function starts processing.
1689 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
1690 * module must be specified.
1691 * @param[in] options [ORed options](@ref sgetnextflags).
1692 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
1693 */
1694const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
1695 const struct lysc_module *module, int options);
1696
1697/**
1698 * @defgroup sgetnextflags lys_getnext() flags
1699 * @ingroup schematree
1700 *
1701 * @{
1702 */
1703#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 +01001704#define LYS_GETNEXT_NOCHOICE 0x02 /**< lys_getnext() option to ignore (kind of conditional) nodes within choice node */
Radek Krejci056d0a82018-12-06 16:57:25 +01001705#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 +01001706#define LYS_GETNEXT_INTONPCONT 0x40 /**< lys_getnext() option to look into non-presence container, instead of returning container itself */
1707#define LYS_GETNEXT_NOSTATECHECK 0x100 /**< lys_getnext() option to skip checking module validity (import-only, disabled) and
1708 relevant if-feature conditions state */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001709#define LYS_GETNEXT_OUTPUT 0x200 /**< lys_getnext() option to provide RPC's/action's output schema nodes instead of input schema nodes
1710 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01001711/** @} sgetnextflags */
1712
1713/**
1714 * @brief Get child node according to the specified criteria.
1715 *
1716 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
1717 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
1718 * @param[in] name Name of the node to find.
1719 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
1720 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
1721 * Used as a bitmask, so multiple nodetypes can be specified.
1722 * @param[in] options [ORed options](@ref sgetnextflags).
1723 * @return Found node if any.
1724 */
1725const struct lysc_node *lys_child(const struct lysc_node *parent, const struct lys_module *module,
1726 const char *name, size_t name_len, uint16_t nodetype, int options);
1727
1728/**
1729 * @brief Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statement
1730 * affecting the node.
1731 *
1732 * @param[in] node Schema node to check.
1733 * @param[in] recursive - 0 to check if-feature only in the \p node schema node,
1734 * - 1 to check if-feature in all ascendant schema nodes until there is a node possibly having an instance in a data tree
1735 * @return - NULL if enabled,
1736 * - pointer to the node with the unsatisfied (disabling) if-feature expression.
1737 */
1738const struct lysc_iffeature *lys_is_disabled(const struct lysc_node *node, int recursive);
1739
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001740/** @} */
1741
Radek Krejci70853c52018-10-15 14:46:16 +02001742#ifdef __cplusplus
1743}
1744#endif
1745
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001746#endif /* LY_TREE_SCHEMA_H_ */