blob: b2d619d2816fe39a0050256c7679200406ab38d0 [file] [log] [blame]
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001/**
2 * @file tree_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief libyang representation of YANG schema trees.
5 *
6 * Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_TREE_SCHEMA_H_
16#define LY_TREE_SCHEMA_H_
17
Radek Krejci54579462019-04-30 12:47:06 +020018#define PCRE2_CODE_UNIT_WIDTH 8
19
20#include <pcre2.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020021#include <stdint.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020022#include <stdio.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020023
Radek Krejcice8c1592018-10-29 15:35:51 +010024#include "extensions.h"
25
Radek Krejci70853c52018-10-15 14:46:16 +020026#ifdef __cplusplus
27extern "C" {
28#endif
29
Radek Krejci5aeea3a2018-09-05 13:29:36 +020030/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +020031 * @brief XPath representation.
32 */
33struct lyxp_expr;
34
35/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020036 * @brief Macro selector for other LY_ARRAY_* macros, do not use directly!
37 */
38#define LY_ARRAY_SELECT(_1, _2, NAME, ...) NAME
39
40/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020041 * @brief Helper macro to go through sized-arrays with a pointer iterator.
42 *
43 * Use with opening curly bracket (`{`).
44 *
45 * @param[in] ARRAY Array to go through
46 * @param[in] TYPE Type of the records in the ARRAY
47 * @param[out] ITER Iterating pointer to the item being processed in each loop
48 */
49#define LY_ARRAY_FOR_ITER(ARRAY, TYPE, ITER) \
Radek Krejci2c4e7172018-10-19 15:56:26 +020050 for (ITER = ARRAY; \
51 (ARRAY) && ((void*)ITER - (void*)ARRAY)/(sizeof(TYPE)) < (*((uint32_t*)(ARRAY) - 1)); \
Radek Krejcie53a8dc2018-10-17 12:52:40 +020052 ITER = (void*)((TYPE*)ITER + 1))
53
54/**
55 * @brief Helper macro to go through sized-arrays with a numeric iterator.
56 *
57 * Use with opening curly bracket (`{`).
58 *
59 * To access an item with the INDEX value, use always LY_ARRAY_INDEX macro!
60 *
61 * @param[in] ARRAY Array to go through
62 * @param[out] INDEX Iterating index of the item being processed in each loop
63 */
64#define LY_ARRAY_FOR_INDEX(ARRAY, INDEX) \
65 for (INDEX = 0; \
Radek Krejci2c4e7172018-10-19 15:56:26 +020066 ARRAY && INDEX < (*((uint32_t*)(ARRAY) - 1)); \
Radek Krejcie53a8dc2018-10-17 12:52:40 +020067 ++INDEX)
68
69/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +020070 * @defgroup schematree Schema Tree
71 * @{
72 *
73 * Data structures and functions to manipulate and access schema tree.
74 */
75
Radek Krejci0af5f5d2018-09-07 15:00:30 +020076/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020077 * @brief Get a number of records in the ARRAY.
Radek Krejci86d106e2018-10-18 09:53:19 +020078 *
79 * Does not check if array exists!
Radek Krejcie53a8dc2018-10-17 12:52:40 +020080 */
Radek Krejci2c4e7172018-10-19 15:56:26 +020081#define LY_ARRAY_SIZE(ARRAY) (*((uint32_t*)(ARRAY) - 1))
Radek Krejcie53a8dc2018-10-17 12:52:40 +020082
83/**
84 * @brief Sized-array iterator (for-loop).
85 *
86 * Use with opening curly bracket (`{`).
87 *
88 * There are 2 variants:
89 *
90 * LY_ARRAY_FOR(ARRAY, TYPE, ITER)
91 *
92 * 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
93 * providing the items of the ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_ITER macro
94 *
95 * LY_ARRAY_FOR(ARRAY, INDEX)
96 *
97 * 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 +020098 * 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 +020099 */
100#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 +0200101
102/**
103 * @brief Macro to iterate via all sibling elements without affecting the list itself
104 *
105 * Works for all types of nodes despite it is data or schema tree, but all the
106 * parameters must be pointers to the same type.
107 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200108 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200109 *
110 * @param START Pointer to the starting element.
111 * @param ELEM Iterator.
112 */
113#define LY_LIST_FOR(START, ELEM) \
114 for ((ELEM) = (START); \
115 (ELEM); \
116 (ELEM) = (ELEM)->next)
117
118/**
Radek Krejci5fac3592018-10-12 15:23:45 +0200119 * @brief Macro to iterate via all sibling elements allowing to modify the list itself (e.g. removing elements)
120 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200121 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200122 *
123 * @param START Pointer to the starting element.
124 * @param NEXT Temporary storage to allow removing of the current iterator content.
125 * @param ELEM Iterator.
126 */
127#define LY_LIST_FOR_SAFE(START, NEXT, ELEM) \
128 for ((ELEM) = (START); \
129 (ELEM) ? (NEXT = (ELEM)->next, 1) : 0; \
130 (ELEM) = (NEXT))
131
132/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200133 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
134 */
135typedef enum {
136 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
137 LYS_IN_YANG = 1, /**< YANG schema input format */
Radek Krejci693262f2019-04-29 15:23:20 +0200138 LYS_IN_YIN = 3 /**< YIN schema input format */
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200139} LYS_INFORMAT;
140
141/**
142 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
143 */
144typedef enum {
145 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
146 LYS_OUT_YANG = 1, /**< YANG schema output format */
Radek Krejci693262f2019-04-29 15:23:20 +0200147 LYS_OUT_YIN = 3, /**< YIN schema output format */
148 LYS_OUT_YANG_COMPILED = 2, /**< YANG schema output format of the compiled schema tree */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200149
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200150 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
151 LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
152 LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */
153} LYS_OUTFORMAT;
154
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200155#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
156
Michal Vaskob55f6c12018-09-12 11:13:15 +0200157#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
158#define LYS_CONTAINER 0x0001 /**< container statement node */
159#define LYS_CHOICE 0x0002 /**< choice statement node */
160#define LYS_LEAF 0x0004 /**< leaf statement node */
161#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
162#define LYS_LIST 0x0010 /**< list statement node */
163#define LYS_ANYXML 0x0020 /**< anyxml statement node */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200164#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 +0200165
Radek Krejcia3045382018-11-22 14:30:31 +0100166#define LYS_CASE 0x0040 /**< case statement node */
167#define LYS_USES 0x0080 /**< uses statement node */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200168#define LYS_INPUT 0x100
169#define LYS_OUTPUT 0x200
170#define LYS_INOUT 0x300
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100171#define LYS_ACTION 0x400 /**< RPC or action */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100172#define LYS_NOTIF 0x800
173#define LYS_GROUPING 0x1000
174#define LYS_AUGMENT 0x2000
175
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200176/**
Radek Krejci2167ee12018-11-02 16:09:07 +0100177 * @brief YANG built-in types
178 */
179typedef enum {
180 LY_TYPE_UNKNOWN = 0, /**< Unknown type */
181 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 +0100182 LY_TYPE_UINT8, /**< 8-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
183 LY_TYPE_UINT16, /**< 16-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
184 LY_TYPE_UINT32, /**< 32-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
185 LY_TYPE_UINT64, /**< 64-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
186 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 +0100187 LY_TYPE_BITS, /**< A set of bits or flags ([RFC 6020 sec 9.7](http://tools.ietf.org/html/rfc6020#section-9.7)) */
188 LY_TYPE_BOOL, /**< "true" or "false" ([RFC 6020 sec 9.5](http://tools.ietf.org/html/rfc6020#section-9.5)) */
189 LY_TYPE_DEC64, /**< 64-bit signed decimal number ([RFC 6020 sec 9.3](http://tools.ietf.org/html/rfc6020#section-9.3))*/
190 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)) */
191 LY_TYPE_ENUM, /**< Enumerated strings ([RFC 6020 sec 9.6](http://tools.ietf.org/html/rfc6020#section-9.6)) */
192 LY_TYPE_IDENT, /**< A reference to an abstract identity ([RFC 6020 sec 9.10](http://tools.ietf.org/html/rfc6020#section-9.10)) */
193 LY_TYPE_INST, /**< References a data tree node ([RFC 6020 sec 9.13](http://tools.ietf.org/html/rfc6020#section-9.13)) */
194 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 +0100195 LY_TYPE_UNION, /**< Choice of member types ([RFC 6020 sec 9.12](http://tools.ietf.org/html/rfc6020#section-9.12)) */
196 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 +0100197 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 +0100198 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 +0100199 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 +0100200} LY_DATA_TYPE;
201#define LY_DATA_TYPE_COUNT 20 /**< Number of different types */
202
Radek Krejci5969f272018-11-23 10:03:58 +0100203/**
204 * @brief Stringified YANG built-in data types
205 */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100206extern const char* ly_data_type2str[LY_DATA_TYPE_COUNT];
207
Radek Krejci2167ee12018-11-02 16:09:07 +0100208/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200209 * @brief YANG import-stmt
210 */
211struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200212 struct lys_module *module; /**< pointer to the imported module
213 (mandatory, but resolved when the referring module is completely parsed) */
214 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200215 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200216 const char *dsc; /**< description */
217 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200218 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200219 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
220};
221
222/**
223 * @brief YANG include-stmt
224 */
225struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100226 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200227 (mandatory, but resolved when the referring module is completely parsed) */
228 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200229 const char *dsc; /**< description */
230 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200231 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200232 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
233};
234
235/**
236 * @brief YANG extension-stmt
237 */
238struct lysp_ext {
239 const char *name; /**< extension name */
240 const char *argument; /**< argument name, NULL if not specified */
241 const char *dsc; /**< description statement */
242 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200243 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200244 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
245};
246
247/**
248 * @brief Helper structure for generic storage of the extension instances content.
249 */
250struct lysp_stmt {
251 const char *stmt; /**< identifier of the statement */
252 const char *arg; /**< statement's argument */
253 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200254 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200255 uint16_t flags;
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200256};
257
258/**
259 * @brief YANG extension instance
260 */
261struct lysp_ext_instance {
262 const char *name; /**< extension identifier, including possible prefix */
263 const char *argument; /**< optional value of the extension's argument */
Radek Krejci693262f2019-04-29 15:23:20 +0200264 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200265 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
266 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
267 the index of that substatement */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200268};
269
270/**
271 * @brief YANG feature-stmt
272 */
273struct lysp_feature {
274 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200275 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200276 const char *dsc; /**< description statement */
277 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200278 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200279 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
280};
281
282/**
283 * @brief YANG identity-stmt
284 */
285struct lysp_ident {
286 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200287 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
288 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200289 const char *dsc; /**< description statement */
290 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200291 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200292 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
293};
294
Michal Vasko71e64ca2018-09-07 16:30:29 +0200295/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200296 * @brief Covers restrictions: range, length, pattern, must
297 */
298struct lysp_restr {
299 const char *arg; /**< The restriction expression/value (mandatory);
300 in case of pattern restriction, the first byte has a special meaning:
301 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
302 const char *emsg; /**< error-message */
303 const char *eapptag; /**< error-app-tag value */
304 const char *dsc; /**< description */
305 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200306 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200307};
308
309/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200310 * @brief YANG revision-stmt
311 */
312struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200313 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200314 const char *dsc; /**< description statement */
315 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200316 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200317};
318
319/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200320 * @brief Enumeration/Bit value definition
321 */
322struct lysp_type_enum {
323 const char *name; /**< name (mandatory) */
324 const char *dsc; /**< description statement */
325 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200326 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200327 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200328 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200329 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
330 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200331};
332
333/**
334 * @brief YANG type-stmt
335 *
336 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
337 */
338struct lysp_type {
339 const char *name; /**< name of the type (mandatory) */
340 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
341 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200342 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
343 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
344 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200345 const char *path; /**< path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200346 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200347 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
348 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200349
Radek Krejci2167ee12018-11-02 16:09:07 +0100350 struct lysc_type *compiled; /**< pointer to the compiled type */
351
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200352 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
353 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100354 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200355};
356
357/**
358 * @brief YANG typedef-stmt
359 */
360struct lysp_tpdf {
361 const char *name; /**< name of the newly defined type (mandatory) */
362 const char *units; /**< units of the newly defined type */
363 const char *dflt; /**< default value of the newly defined type */
364 const char *dsc; /**< description statement */
365 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200366 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200367 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100368 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200369};
370
371/**
372 * @brief YANG grouping-stmt
373 */
374struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100375 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
376 uint16_t nodetype; /**< LYS_GROUPING */
377 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200378 const char *name; /**< grouping name (mandatory) */
379 const char *dsc; /**< description statement */
380 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200381 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
382 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200383 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200384 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
385 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
386 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200387};
388
389/**
390 * @brief YANG when-stmt
391 */
392struct lysp_when {
393 const char *cond; /**< specified condition (mandatory) */
394 const char *dsc; /**< description statement */
395 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200396 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200397};
398
399/**
400 * @brief YANG refine-stmt
401 */
402struct lysp_refine {
403 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
404 const char *dsc; /**< description statement */
405 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200406 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200407 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200408 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200409 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200410 uint32_t min; /**< min-elements constraint */
411 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200412 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200413 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
414};
415
416/**
417 * @brief YANG uses-augment-stmt and augment-stmt
418 */
419struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100420 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
421 uint16_t nodetype; /**< LYS_AUGMENT */
422 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200423 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
424 const char *dsc; /**< description statement */
425 const char *ref; /**< reference statement */
426 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200427 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200428 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200429 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
430 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
431 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200432};
433
434/**
435 * @defgroup deviatetypes Deviate types
436 * @{
437 */
438#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
439#define LYS_DEV_ADD 2 /**< deviate type add */
440#define LYS_DEV_DELETE 3 /**< deviate type delete */
441#define LYS_DEV_REPLACE 4 /**< deviate type replace */
442/** @} */
443
444/**
445 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
446 */
447struct lysp_deviate {
448 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
449 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200450 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200451};
452
453struct lysp_deviate_add {
454 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
455 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200456 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200457 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200458 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200459 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
460 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200461 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
462 uint32_t min; /**< min-elements constraint */
463 uint32_t max; /**< max-elements constraint, 0 means unbounded */
464};
465
466struct lysp_deviate_del {
467 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
468 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200469 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200470 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200471 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200472 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
473 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200474 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200475};
476
477struct lysp_deviate_rpl {
478 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
479 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200480 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200481 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200482 const char *units; /**< units of the values */
483 const char *dflt; /**< default value */
484 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
485 uint32_t min; /**< min-elements constraint */
486 uint32_t max; /**< max-elements constraint, 0 means unbounded */
487};
488
489struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200490 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200491 const char *dsc; /**< description statement */
492 const char *ref; /**< reference statement */
493 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200494 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200495};
496
Radek Krejci4f28eda2018-11-12 11:46:16 +0100497/**
498 * @defgroup spnodeflags Parsed schema nodes flags
499 * @ingroup snodeflags
500 *
501 * Various flags for parsed schema nodes.
502 *
503 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
504 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
Radek Krejcid3ca0632019-04-16 16:54:54 +0200505 * 3 - leaf 8 - notification 13 - identity 18 - refine 23 - stmt
Radek Krejci4f28eda2018-11-12 11:46:16 +0100506 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
507 * 5 - list 10 - input 15 - typedef 20 - deviate
508 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200509 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2
510 * 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
511 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
512 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
513 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x| |
514 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
515 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | | |
516 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x| |
517 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
518 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
519 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x| |
520 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
521 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
522 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x| |
523 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
524 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| | |
525 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x| |
526 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
527 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
528 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x| |
529 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
530 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | | |
531 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | | |
532 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x| |
533 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
534 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | | |
535 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | | |
536 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x| |
537 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
538 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | | |
539 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x| |
540 * LYS_SINGLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
541 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
542 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| | |
543 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x| |
544 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | | |
545 * LYS_DOUBLEQUOTED | | | | | | | | | | | | | | | | | | | | | | |x|
546 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
547 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | | |
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200548 * LYS_USED_GRP | | | | | | | | | | | | | | | |x| | | | | | | |
Radek Krejcid3ca0632019-04-16 16:54:54 +0200549 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100550 *
551 */
552
553/**
554 * @defgroup scnodeflags Compiled schema nodes flags
555 * @ingroup snodeflags
556 *
557 * Various flags for compiled schema nodes.
558 *
559 * 1 - container 6 - anydata/anyxml 11 - output
560 * 2 - choice 7 - case 12 - feature
561 * 3 - leaf 8 - notification 13 - identity
562 * 4 - leaflist 9 - rpc 14 - extension
Radek Krejci693262f2019-04-29 15:23:20 +0200563 * 5 - list 10 - input 15 - bitenum
Radek Krejci4f28eda2018-11-12 11:46:16 +0100564 *
Radek Krejci693262f2019-04-29 15:23:20 +0200565 * 1 1 1 1 1 1
566 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
567 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
568 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | |
569 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
570 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | |
571 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
572 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x| |
573 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
574 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x| |
575 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
576 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x| |
577 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
578 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | | |
579 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
580 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | | |
581 * LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | |
582 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
583 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | |
584 * LYS_PRESENCE |x| | | | | | | | | | | | | | |
585 * LYS_UNIQUE | | |x| | | | | | | | | | | | |
586 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
587 * 9 LYS_KEY | | |x| | | | | | | | | | | | |
588 * LYS_FENABLED | | | | | | | | | | | |x| | | |
589 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
590 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | | |
591 * LYS_ISENUM | | | | | | | | | | | | | | |x|
592 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
593 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | | |
594 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
595 * 11 LYS_SET_CONFIG |x|x|x|x|x|x|x| | |x|x| | | | |
596 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci4f28eda2018-11-12 11:46:16 +0100597 *
598 */
599
600/**
601 * @defgroup snodeflags Schema nodes flags
602 * @ingroup schematree
603 * @{
604 */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200605#define LYS_CONFIG_W 0x01 /**< config true; */
606#define LYS_CONFIG_R 0x02 /**< config false; */
607#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100608#define LYS_STATUS_CURR 0x04 /**< status current; */
609#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
610#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
611#define LYS_STATUS_MASK 0x1C /**< mask for status value */
612#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100613 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
614 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
615 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
616 child with LYS_MAND_TRUE. */
Radek Krejcif1421c22019-02-19 13:05:20 +0100617#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice/::lysc_node_choice,
618 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
619 This flag is present only in case the mandatory false statement was explicitly specified. */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100620#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100621#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, applicable only to ::lysc_node_container */
622#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
623#define LYS_KEY 0x100 /**< flag for leafs being a key of a list, applicable only to ::lysc_node_leaf */
624#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysc_feature */
Radek Krejcife909632019-02-12 15:34:42 +0100625#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 +0100626 ::lysc_node_list/::lysp_node_list */
627#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
628 ::lysc_node_list/::lysp_node_list */
629#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
630#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
631#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
632#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200633#define LYS_USED_GRP 0x400 /**< internal flag for validating not-instantiated groupings
634 (resp. do not validate again the instantiated groupings). */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100635#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100636#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200637#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100638
639#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
640#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
641#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
642#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
643#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
644#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
645#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
646#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
647#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
648#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100649#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 +0100650 cases of choice. This information is important for refines, since it is prohibited to make leafs
651 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100652 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
653 between own default or the default values taken from the type. */
654#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 +0100655#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 +0100656
Radek Krejcid3ca0632019-04-16 16:54:54 +0200657#define LYS_SINGLEQUOTED 0x100 /**< flag for single-quoted argument of an extension instance's substatement */
658#define LYS_DOUBLEQUOTED 0x200 /**< flag for double-quoted argument of an extension instance's substatement */
659
Radek Krejci693262f2019-04-29 15:23:20 +0200660#define LYS_ISENUM 0x200 /**< flag to simply distinguish type in struct lysc_type_bitenum_item */
661
Radek Krejcife909632019-02-12 15:34:42 +0100662#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100663/** @} */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200664
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200665/**
666 * @brief Generic YANG data node
667 */
668struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100669 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200670 uint16_t nodetype; /**< type of the node (mandatory) */
671 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100672 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200673 const char *name; /**< node name (mandatory) */
674 const char *dsc; /**< description statement */
675 const char *ref; /**< reference statement */
676 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200677 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200678 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200679};
680
681/**
682 * @brief Extension structure of the lysp_node for YANG container
683 */
684struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100685 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200686 uint16_t nodetype; /**< LYS_CONTAINER */
687 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
688 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
689 const char *name; /**< node name (mandatory) */
690 const char *dsc; /**< description statement */
691 const char *ref; /**< reference statement */
692 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200693 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200694 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200695
696 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200697 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200698 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200699 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
700 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200701 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200702 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
703 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200704};
705
706struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100707 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200708 uint16_t nodetype; /**< LYS_LEAF */
709 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
710 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
711 const char *name; /**< node name (mandatory) */
712 const char *dsc; /**< description statement */
713 const char *ref; /**< reference statement */
714 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200715 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200716 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200717
718 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200719 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200720 struct lysp_type type; /**< type of the leaf node (mandatory) */
721 const char *units; /**< units of the leaf's type */
722 const char *dflt; /**< default value */
723};
724
725struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100726 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200727 uint16_t nodetype; /**< LYS_LEAFLIST */
728 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
729 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
730 const char *name; /**< node name (mandatory) */
731 const char *dsc; /**< description statement */
732 const char *ref; /**< reference statement */
733 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200734 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200735 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200736
737 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200738 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200739 struct lysp_type type; /**< type of the leaf node (mandatory) */
740 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200741 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200742 uint32_t min; /**< min-elements constraint */
743 uint32_t max; /**< max-elements constraint, 0 means unbounded */
744};
745
746struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100747 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200748 uint16_t nodetype; /**< LYS_LIST */
749 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
750 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
751 const char *name; /**< node name (mandatory) */
752 const char *dsc; /**< description statement */
753 const char *ref; /**< reference statement */
754 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200755 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200756 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200757
758 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200759 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200760 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200761 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
762 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200763 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200764 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
765 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200766 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200767 uint32_t min; /**< min-elements constraint */
768 uint32_t max; /**< max-elements constraint, 0 means unbounded */
769};
770
771struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100772 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200773 uint16_t nodetype; /**< LYS_CHOICE */
774 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
775 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
776 const char *name; /**< node name (mandatory) */
777 const char *dsc; /**< description statement */
778 const char *ref; /**< reference statement */
779 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200780 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200781 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200782
783 /* choice */
784 struct lysp_node *child; /**< list of data nodes (linked list) */
785 const char* dflt; /**< default case */
786};
787
788struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100789 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200790 uint16_t nodetype; /**< LYS_CASE */
791 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
792 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
793 const char *name; /**< node name (mandatory) */
794 const char *dsc; /**< description statement */
795 const char *ref; /**< reference statement */
796 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200797 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200798 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200799
800 /* case */
801 struct lysp_node *child; /**< list of data nodes (linked list) */
802};
803
804struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100805 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200806 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
807 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
808 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
809 const char *name; /**< node name (mandatory) */
810 const char *dsc; /**< description statement */
811 const char *ref; /**< reference statement */
812 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200813 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200814 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200815
816 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200817 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200818};
819
820struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100821 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200822 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200823 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
824 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
825 const char *name; /**< grouping name reference (mandatory) */
826 const char *dsc; /**< description statement */
827 const char *ref; /**< reference statement */
828 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200829 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200830 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200831
832 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200833 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
834 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200835};
836
837/**
838 * @brief YANG input-stmt and output-stmt
839 */
840struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100841 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
842 uint16_t nodetype; /**< LYS_INOUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200843 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
844 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
845 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200846 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200847 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200848};
849
850/**
851 * @brief YANG rpc-stmt and action-stmt
852 */
853struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100854 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
855 uint16_t nodetype; /**< LYS_ACTION */
856 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200857 const char *name; /**< grouping name reference (mandatory) */
858 const char *dsc; /**< description statement */
859 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200860 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200861 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
862 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100863 struct lysp_action_inout input; /**< RPC's/Action's input */
864 struct lysp_action_inout output; /**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200865 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200866};
867
868/**
869 * @brief YANG notification-stmt
870 */
871struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100872 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
873 uint16_t nodetype; /**< LYS_NOTIF */
874 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200875 const char *name; /**< grouping name reference (mandatory) */
876 const char *dsc; /**< description statement */
877 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200878 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200879 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
880 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
881 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200882 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200883 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200884};
885
886/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200887 * @brief supported YANG schema version values
888 */
889typedef enum LYS_VERSION {
890 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
891 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
892 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
893} LYS_VERSION;
894
895/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200896 * @brief Printable YANG schema tree structure representing YANG module.
897 *
898 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
899 */
900struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100901 struct lys_module *mod; /**< covering module structure */
902
Radek Krejcib7db73a2018-10-24 14:18:40 +0200903 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
904 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200905 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
906 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200907 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
908 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
909 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
910 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
911 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200912 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200913 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
914 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
915 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
916 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
917 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200918
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100919 uint8_t parsing:1; /**< flag for circular check */
920};
921
922struct lysp_submodule {
923 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
924
925 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
926 in the list is always the last (newest) revision of the module */
927 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
928 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
929 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
930 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
931 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
932 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
933 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
934 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
935 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
936 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
937 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
938 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
939 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
940
941 uint8_t parsing:1; /**< flag for circular check */
942
Radek Krejci086c7132018-10-26 15:29:04 +0200943 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
944 1 - the latest revision in searchdirs was not searched yet and this is the
945 latest revision in the current context
946 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100947 const char *name; /**< name of the module (mandatory) */
948 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
949 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
950 const char *org; /**< party/company responsible for the module */
951 const char *contact; /**< contact information for the module */
952 const char *dsc; /**< description of the module */
953 const char *ref; /**< cross-reference for the module */
Radek Krejci086c7132018-10-26 15:29:04 +0200954 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200955};
956
957/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200958 * @brief Free the printable YANG schema tree structure.
959 *
960 * @param[in] module Printable YANG schema tree structure to free.
961 */
962void lysp_module_free(struct lysp_module *module);
963
964/**
Radek Krejcice8c1592018-10-29 15:35:51 +0100965 * @brief YANG extension instance
966 */
967struct lysc_ext_instance {
968 struct lyext_plugin *plugin; /**< pointer to the plugin implementing the extension (if present) */
969 void *parent; /**< pointer to the parent element holding the extension instance(s), use
970 ::lysc_ext_instance#parent_type to access the schema element */
971 const char *argument; /**< optional value of the extension's argument */
972 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
973 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
974 this identifies the index of the substatement for this extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +0100975 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejcice8c1592018-10-29 15:35:51 +0100976#if 0
Radek Krejcice8c1592018-10-29 15:35:51 +0100977 uint8_t ext_type; /**< extension type (#LYEXT_TYPE) */
978 uint8_t padding; /**< 32b padding */
Radek Krejcice8c1592018-10-29 15:35:51 +0100979 struct lys_module *module; /**< pointer to the extension instance's module (mandatory) */
980 LYS_NODE nodetype; /**< LYS_EXT */
981#endif
Radek Krejci2a408df2018-10-29 16:32:26 +0100982 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
983 void *priv; /**< private caller's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +0100984};
985
986/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +0100987 * @brief Compiled YANG if-feature-stmt
988 */
989struct lysc_iffeature {
990 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
991 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
992};
993
994/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200995 * @brief YANG import-stmt
996 */
997struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100998 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +0200999 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001000 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +02001001};
1002
1003/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001004 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001005 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001006struct lysc_when {
1007 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001008 const char *dsc; /**< description */
1009 const char *ref; /**< reference */
Radek Krejci00b874b2019-02-12 10:54:50 +01001010 struct lysc_node *context; /**< context node for evaluating the expression */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001011 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001012 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001013};
1014
1015/**
Radek Krejci2a408df2018-10-29 16:32:26 +01001016 * @brief YANG identity-stmt
1017 */
1018struct lysc_ident {
1019 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +01001020 const char *dsc; /**< description */
1021 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001022 struct lys_module *module; /**< module structure */
Radek Krejci2a408df2018-10-29 16:32:26 +01001023 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
1024 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001025 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001026 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1027};
1028
1029/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001030 * @brief YANG feature-stmt
1031 */
1032struct lysc_feature {
1033 const char *name; /**< feature name (mandatory) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001034 const char *dsc; /**< description */
1035 const char *ref; /**< reference */
Radek Krejci693262f2019-04-29 15:23:20 +02001036 struct lys_module *module; /**< module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001037 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 +01001038 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001039 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001040 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
1041 #LYS_FENABLED values allowed */
1042};
1043
Radek Krejci151a5b72018-10-19 14:21:44 +02001044/**
1045 * @defgroup ifftokens if-feature expression tokens
1046 * Tokens of if-feature expression used in ::lysc_iffeature#expr
1047 *
1048 * @{
1049 */
1050#define LYS_IFF_NOT 0x00 /**< operand "not" */
1051#define LYS_IFF_AND 0x01 /**< operand "and" */
1052#define LYS_IFF_OR 0x02 /**< operand "or" */
1053#define LYS_IFF_F 0x03 /**< feature */
1054/**
1055 * @}
1056 */
1057
1058/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001059 * @brief Compiled YANG revision statement
1060 */
1061struct lysc_revision {
1062 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1063 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1064};
1065
Radek Krejci2167ee12018-11-02 16:09:07 +01001066struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001067 struct lysc_range_part {
Radek Krejci693262f2019-04-29 15:23:20 +02001068 union { /**< min boundary */
1069 int64_t min_64; /**< for int8, int16, int32, int64 and decimal64 */
1070 uint64_t min_u64; /**< for uint8, uint16, uint32, uint64, string and binary */
Radek Krejci2167ee12018-11-02 16:09:07 +01001071 };
Radek Krejci693262f2019-04-29 15:23:20 +02001072 union { /**< max boundary */
1073 int64_t max_64; /**< for int8, int16, int32, int64 and decimal64 */
1074 uint64_t max_u64; /**< for uint8, uint16, uint32, uint64, string and binary */
Radek Krejci2167ee12018-11-02 16:09:07 +01001075 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001076 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
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)) */
1082};
1083
1084struct lysc_pattern {
Radek Krejci54579462019-04-30 12:47:06 +02001085 const char *expr; /**< original, not compiled, regular expression */
1086 pcre2_code *code; /**< compiled regular expression */
Radek Krejcic8b31002019-01-08 10:24:45 +01001087 const char *dsc; /**< description */
1088 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001089 const char *emsg; /**< error-message */
1090 const char *eapptag; /**< error-app-tag value */
1091 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4586a022018-11-13 11:29:26 +01001092 uint32_t inverted:1; /**< invert-match flag */
1093 uint32_t refcount:31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001094};
1095
1096struct lysc_must {
1097 struct lys_module *module; /**< module where the must was defined */
1098 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001099 const char *dsc; /**< description */
1100 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001101 const char *emsg; /**< error-message */
1102 const char *eapptag; /**< error-app-tag value */
1103 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1104};
1105
1106struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001107 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001108 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001109 LY_DATA_TYPE basetype; /**< Base type of the type */
1110 uint32_t refcount; /**< reference counter for type sharing */
1111};
1112
1113struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001114 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001115 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001116 LY_DATA_TYPE basetype; /**< Base type of the type */
1117 uint32_t refcount; /**< reference counter for type sharing */
1118 struct lysc_range *range; /**< Optional range limitation */
1119};
1120
1121struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001122 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001123 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001124 LY_DATA_TYPE basetype; /**< Base type of the type */
1125 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001126 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001127 struct lysc_range *range; /**< Optional range limitation */
1128};
1129
1130struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001131 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001132 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001133 LY_DATA_TYPE basetype; /**< Base type of the type */
1134 uint32_t refcount; /**< reference counter for type sharing */
1135 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001136 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001137};
1138
Radek Krejci693262f2019-04-29 15:23:20 +02001139struct lysc_type_bitenum_item {
1140 const char *name; /**< enumeration identifier */
1141 const char *dsc; /**< description */
1142 const char *ref; /**< reference */
1143 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1144 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1145 union {
1146 int32_t value; /**< integer value associated with the enumeration */
1147 uint32_t position; /**< non-negative integer value associated with the bit */
1148 };
1149 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
1150 values are allowed */
1151};
1152
Radek Krejci2167ee12018-11-02 16:09:07 +01001153struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001154 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001155 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001156 LY_DATA_TYPE basetype; /**< Base type of the type */
1157 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci693262f2019-04-29 15:23:20 +02001158 struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1159};
1160
1161struct lysc_type_bits {
1162 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1163 const char *dflt; /**< type's default value if any */
1164 LY_DATA_TYPE basetype; /**< Base type of the type */
1165 uint32_t refcount; /**< reference counter for type sharing */
1166 struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001167};
1168
1169struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001170 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001171 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001172 LY_DATA_TYPE basetype; /**< Base type of the type */
1173 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejcia3045382018-11-22 14:30:31 +01001174 const char* path; /**< target path */
Radek Krejci96a0bfd2018-11-22 15:25:06 +01001175 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 +01001176 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001177 uint8_t require_instance; /**< require-instance flag */
1178};
1179
1180struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001181 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001182 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001183 LY_DATA_TYPE basetype; /**< Base type of the type */
1184 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001185 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001186 mandatory (at least 1 item) */
1187};
1188
1189struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001190 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001191 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001192 LY_DATA_TYPE basetype; /**< Base type of the type */
1193 uint32_t refcount; /**< reference counter for type sharing */
1194 uint8_t require_instance; /**< require-instance flag */
1195};
1196
Radek Krejci2167ee12018-11-02 16:09:07 +01001197struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001198 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001199 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001200 LY_DATA_TYPE basetype; /**< Base type of the type */
1201 uint32_t refcount; /**< reference counter for type sharing */
1202 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1203};
1204
1205struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001206 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001207 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001208 LY_DATA_TYPE basetype; /**< Base type of the type */
1209 uint32_t refcount; /**< reference counter for type sharing */
1210 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001211};
1212
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001213struct lysc_action_inout {
1214 struct lysc_node *data; /**< first child node (linked list) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001215 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1216};
1217
Radek Krejci056d0a82018-12-06 16:57:25 +01001218struct lysc_action {
1219 uint16_t nodetype; /**< LYS_ACTION */
1220 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001221 struct lys_module *module; /**< module structure */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001222 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. */
1223 struct lysc_node *parent; /**< parent node (NULL in case of top level node - RPC) */
1224
Radek Krejcifc11bd72019-04-11 16:00:05 +02001225 struct lysc_ext_instance *input_exts; /**< list of the extension instances of input ([sized array](@ref sizedarrays)) */
1226 struct lysc_ext_instance *output_exts; /**< list of the extension instances of outpu ([sized array](@ref sizedarrays)) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001227
Radek Krejci056d0a82018-12-06 16:57:25 +01001228 const char *name; /**< action/RPC name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001229 const char *dsc; /**< description */
1230 const char *ref; /**< reference */
1231
Radek Krejcifc11bd72019-04-11 16:00:05 +02001232 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1233 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1234
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001235 struct lysc_action_inout input; /**< RPC's/action's input */
1236 struct lysc_action_inout output; /**< RPC's/action's output */
1237
Radek Krejci056d0a82018-12-06 16:57:25 +01001238};
1239
1240struct lysc_notif {
1241 uint16_t nodetype; /**< LYS_NOTIF */
1242 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001243 struct lys_module *module; /**< module structure */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001244 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 +01001245 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1246
Radek Krejcifc11bd72019-04-11 16:00:05 +02001247 struct lysc_node *data; /**< first child node (linked list) */
1248 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1249
Radek Krejci056d0a82018-12-06 16:57:25 +01001250 const char *name; /**< Notification name (mandatory) */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001251 const char *dsc; /**< description */
1252 const char *ref; /**< reference */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001253
1254 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1255 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001256};
1257
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001258/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001259 * @brief Compiled YANG data node
1260 */
1261struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001262 uint16_t nodetype; /**< type of the node (mandatory) */
1263 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001264 struct lys_module *module; /**< module structure */
1265 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. */
1266 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1267 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1268 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1269 never NULL. If there is no sibling node, pointer points to the node
1270 itself. In case of the first node, this pointer points to the last
1271 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001272 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001273 const char *dsc; /**< description */
1274 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001275 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001276 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001277 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001278};
1279
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001280struct lysc_node_container {
1281 uint16_t nodetype; /**< LYS_CONTAINER */
1282 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1283 struct lys_module *module; /**< module structure */
1284 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. */
1285 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1286 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1287 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1288 never NULL. If there is no sibling node, pointer points to the node
1289 itself. In case of the first node, this pointer points to the last
1290 node in the list. */
1291 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001292 const char *dsc; /**< description */
1293 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001294 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001295 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001296 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001297
1298 struct lysc_node *child; /**< first child node (linked list) */
1299 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1300 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1301 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001302};
1303
Radek Krejcia3045382018-11-22 14:30:31 +01001304struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001305 uint16_t nodetype; /**< LYS_CASE */
1306 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1307 struct lys_module *module; /**< module structure */
1308 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1309 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1310 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1311 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1312 never NULL. If there is no sibling node, pointer points to the node
1313 itself. In case of the first node, this pointer points to the last
1314 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001315 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001316 const char *dsc; /**< description */
1317 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001318 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001319 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001320 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001321
Radek Krejcia3045382018-11-22 14:30:31 +01001322 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 +01001323 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001324};
1325
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001326struct lysc_node_choice {
1327 uint16_t nodetype; /**< LYS_CHOICE */
1328 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1329 struct lys_module *module; /**< module structure */
1330 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. */
1331 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1332 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1333 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1334 never NULL. If there is no sibling node, pointer points to the node
1335 itself. In case of the first node, this pointer points to the last
1336 node in the list. */
1337 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001338 const char *dsc; /**< description */
1339 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001340 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001341 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001342 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001343
Radek Krejcia9026eb2018-12-12 16:04:47 +01001344 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1345 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1346 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001347 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001348};
1349
1350struct lysc_node_leaf {
1351 uint16_t nodetype; /**< LYS_LEAF */
1352 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1353 struct lys_module *module; /**< module structure */
1354 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. */
1355 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1356 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1357 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1358 never NULL. If there is no sibling node, pointer points to the node
1359 itself. In case of the first node, this pointer points to the last
1360 node in the list. */
1361 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001362 const char *dsc; /**< description */
1363 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001364 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001365 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001366 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001367
1368 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1369 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001370
Radek Krejci4f28eda2018-11-12 11:46:16 +01001371 const char *units; /**< units of the leaf's type */
1372 const char *dflt; /**< default value */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001373};
1374
1375struct lysc_node_leaflist {
1376 uint16_t nodetype; /**< LYS_LEAFLIST */
1377 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1378 struct lys_module *module; /**< module structure */
1379 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. */
1380 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1381 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1382 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1383 never NULL. If there is no sibling node, pointer points to the node
1384 itself. In case of the first node, this pointer points to the last
1385 node in the list. */
1386 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001387 const char *dsc; /**< description */
1388 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001389 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001390 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001391 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001392
1393 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1394 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1395
Radek Krejci0e5d8382018-11-28 16:37:53 +01001396 const char *units; /**< units of the leaf's type */
1397 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
1398 uint32_t min; /**< min-elements constraint */
1399 uint32_t max; /**< max-elements constraint */
1400
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001401};
1402
1403struct lysc_node_list {
1404 uint16_t nodetype; /**< LYS_LIST */
1405 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1406 struct lys_module *module; /**< module structure */
1407 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. */
1408 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1409 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1410 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1411 never NULL. If there is no sibling node, pointer points to the node
1412 itself. In case of the first node, this pointer points to the last
1413 node in the list. */
1414 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001415 const char *dsc; /**< description */
1416 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001417 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001418 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001419 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001420
1421 struct lysc_node *child; /**< first child node (linked list) */
1422 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1423 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1424 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1425
1426 struct lysc_node_leaf **keys; /**< list of pointers to the keys ([sized array](@ref sizedarrays)) */
1427 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1428 uint32_t min; /**< min-elements constraint */
1429 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001430};
1431
1432struct lysc_node_anydata {
1433 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1434 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1435 struct lys_module *module; /**< module structure */
1436 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. */
1437 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1438 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1439 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1440 never NULL. If there is no sibling node, pointer points to the node
1441 itself. In case of the first node, this pointer points to the last
1442 node in the list. */
1443 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001444 const char *dsc; /**< description */
1445 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001446 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001447 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcifc11bd72019-04-11 16:00:05 +02001448 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9800fb82018-12-13 14:26:23 +01001449
1450 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001451};
1452
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001453/**
1454 * @brief Compiled YANG schema tree structure representing YANG module.
1455 *
1456 * Semantically validated YANG schema tree for data tree parsing.
1457 * Contains only the necessary information for the data validation.
1458 */
1459struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001460 struct lys_module *mod; /**< covering module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001461 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001462
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001463 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001464 struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1465 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1466 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1467 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001468 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001469};
1470
1471/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001472 * @brief Get the groupings sized array of the given (parsed) schema node.
1473 * Decides the node's type and in case it has a groupings array, returns it.
1474 * @param[in] node Node to examine.
1475 * @return The node's groupings sized array if any, NULL otherwise.
1476 */
1477const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1478
1479/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001480 * @brief Get the typedefs sized array of the given (parsed) schema node.
1481 * Decides the node's type and in case it has a typedefs array, returns it.
1482 * @param[in] node Node to examine.
1483 * @return The node's typedefs sized array if any, NULL otherwise.
1484 */
1485const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1486
1487/**
1488 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1489 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1490 * @param[in] node Node to examine.
1491 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1492 */
1493const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1494
1495/**
1496 * @brief Get the Notifications sized array of the given (parsed) schema node.
1497 * Decides the node's type and in case it has a Notifications array, returns it.
1498 * @param[in] node Node to examine.
1499 * @return The node's Notifications sized array if any, NULL otherwise.
1500 */
1501const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1502
1503/**
1504 * @brief Get the children linked list of the given (parsed) schema node.
1505 * Decides the node's type and in case it has a children list, returns it.
1506 * @param[in] node Node to examine.
1507 * @return The node's children linked list if any, NULL otherwise.
1508 */
1509const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1510
1511/**
1512 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1513 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1514 * @param[in] node Node to examine.
1515 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1516 */
1517const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1518
1519/**
1520 * @brief Get the Notifications sized array of the given (compiled) schema node.
1521 * Decides the node's type and in case it has a Notifications array, returns it.
1522 * @param[in] node Node to examine.
1523 * @return The node's Notifications sized array if any, NULL otherwise.
1524 */
1525const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1526
1527/**
1528 * @brief Get the children linked list of the given (compiled) schema node.
1529 * Decides the node's type and in case it has a children list, returns it.
1530 * @param[in] node Node to examine.
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001531 * @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 +01001532 * @return The node's children linked list if any, NULL otherwise.
1533 */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001534const struct lysc_node *lysc_node_children(const struct lysc_node *node, uint16_t flags);
Radek Krejci056d0a82018-12-06 16:57:25 +01001535
1536/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001537 * @brief Get how the if-feature statement currently evaluates.
1538 *
1539 * @param[in] iff Compiled if-feature statement to evaluate.
1540 * @return If the statement evaluates to true, 1 is returned. 0 is returned when the statement evaluates to false.
1541 */
1542int lysc_iffeature_value(const struct lysc_iffeature *iff);
1543
1544/**
1545 * @brief Get the current status of the provided feature.
1546 *
1547 * @param[in] feature Compiled feature statement to examine.
1548 * @return
1549 * - 1 if feature is enabled,
1550 * - 0 if feature is disabled,
1551 * - -1 in case of error (invalid argument)
1552 */
1553int lysc_feature_value(const struct lysc_feature *feature);
1554
1555/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001556 * @brief Available YANG schema tree structures representing YANG module.
1557 */
1558struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001559 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
1560 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01001561 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001562 const char *ns; /**< namespace of the module (module - mandatory) */
1563 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
1564 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1565 const char *org; /**< party/company responsible for the module */
1566 const char *contact; /**< contact information for the module */
1567 const char *dsc; /**< description of the module */
1568 const char *ref; /**< cross-reference for the module */
1569
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001570 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01001571 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
1572 Available only for implemented modules. */
1573 struct lysc_feature *off_features;/**< List of pre-compiled features of the module in non implemented modules ([sized array](@ref sizedarrays)).
1574 These features are always disabled and cannot be enabled until the module
1575 become implemented. The features are present in this form to allow their linkage
1576 from if-feature statements of the compiled schemas and their proper use in case
1577 the module became implemented in future (no matter if implicitly via augment/deviate
1578 or explicitly via ly_ctx_module_implement()). */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001579
Radek Krejci95710c92019-02-11 15:49:55 +01001580 uint8_t implemented; /**< flag if the module is implemented, not just imported. The module is implemented if
1581 the flag has non-zero value. Specific values are used internally:
1582 1 - implemented module
1583 2 - recently implemented module by dependency, it can be reverted in rollback procedure */
1584 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001585 1 - the latest revision in searchdirs was not searched yet and this is the
1586 latest revision in the current context
1587 2 - searchdirs were searched and this is the latest available revision */
1588 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001589};
1590
Radek Krejci151a5b72018-10-19 14:21:44 +02001591/**
1592 * @brief Enable specified feature in the module
1593 *
1594 * By default, when the module is loaded by libyang parser, all features are disabled.
1595 *
Radek Krejcica3db002018-11-01 10:31:01 +01001596 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
1597 * enabling all features on the following feature set will fail since it is not possible to enable both features
1598 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
1599 * is untouched.
1600 *
1601 * feature f1;
1602 * feature f2 { if-feature 'not f1';}
1603 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001604 * @param[in] module Module where the feature will be enabled.
1605 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
1606 * @return LY_ERR value.
1607 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001608LY_ERR lys_feature_enable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001609
1610/**
1611 * @brief Disable specified feature in the module
1612 *
1613 * By default, when the module is loaded by libyang parser, all features are disabled.
1614 *
1615 * @param[in] module Module where the feature will be disabled.
1616 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
1617 * @return LY_ERR value
1618 */
Radek Krejcied5acc52019-04-25 15:57:04 +02001619LY_ERR lys_feature_disable(const struct lys_module *module, const char *feature);
Radek Krejci151a5b72018-10-19 14:21:44 +02001620
1621/**
1622 * @brief Get the current status of the specified feature in the module.
1623 *
1624 * @param[in] module Module where the feature is defined.
1625 * @param[in] feature Name of the feature to inspect.
1626 * @return
1627 * - 1 if feature is enabled,
1628 * - 0 if feature is disabled,
1629 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
1630 */
1631int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001632
1633/**
Radek Krejci86d106e2018-10-18 09:53:19 +02001634 * @brief Load a schema into the specified context.
1635 *
1636 * @param[in] ctx libyang context where to process the data model.
1637 * @param[in] data The string containing the dumped data model in the specified
1638 * format.
1639 * @param[in] format Format of the input data (YANG or YIN).
1640 * @return Pointer to the data model structure or NULL on error.
1641 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001642struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001643
1644/**
1645 * @brief Read a schema from file descriptor into the specified context.
1646 *
1647 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
1648 *
1649 * @param[in] ctx libyang context where to process the data model.
1650 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
1651 * 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_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001656
1657/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001658 * @brief Read a schema into the specified context from a file.
Radek Krejci86d106e2018-10-18 09:53:19 +02001659 *
1660 * @param[in] ctx libyang context where to process the data model.
1661 * @param[in] path Path to the file with the model in the specified format.
1662 * @param[in] format Format of the input data (YANG or YIN).
1663 * @return Pointer to the data model structure or NULL on error.
1664 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001665struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001666
1667/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001668 * @brief Search for the schema file in the specified searchpaths.
1669 *
1670 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
1671 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
1672 * result of the ly_ctx_get_searchdirs().
1673 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
1674 * @param[in] name Name of the schema to find.
1675 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
1676 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
1677 * complying the provided restriction is found, NULL is set.
1678 * @param[out] format Optional output variable containing expected format of the schema document according to the
1679 * file suffix.
1680 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
1681 */
1682LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
1683
1684/**
Radek Krejcia3045382018-11-22 14:30:31 +01001685 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
1686 * be from an augment.
1687 *
1688 * lys_getnext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
1689 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
1690 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
1691 * \p parent and \p module parameters.
1692 *
1693 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
1694 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
1695 * all the schema nodes are iteratively returned.
1696 *
1697 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
1698 * @param[in] parent Parent of the subtree where the function starts processing.
1699 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
1700 * module must be specified.
1701 * @param[in] options [ORed options](@ref sgetnextflags).
1702 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
1703 */
1704const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
1705 const struct lysc_module *module, int options);
1706
1707/**
1708 * @defgroup sgetnextflags lys_getnext() flags
1709 * @ingroup schematree
1710 *
1711 * @{
1712 */
1713#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 +01001714#define LYS_GETNEXT_NOCHOICE 0x02 /**< lys_getnext() option to ignore (kind of conditional) nodes within choice node */
Radek Krejci056d0a82018-12-06 16:57:25 +01001715#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 +01001716#define LYS_GETNEXT_INTONPCONT 0x40 /**< lys_getnext() option to look into non-presence container, instead of returning container itself */
1717#define LYS_GETNEXT_NOSTATECHECK 0x100 /**< lys_getnext() option to skip checking module validity (import-only, disabled) and
1718 relevant if-feature conditions state */
Radek Krejci6eeb58f2019-02-22 16:29:37 +01001719#define LYS_GETNEXT_OUTPUT 0x200 /**< lys_getnext() option to provide RPC's/action's output schema nodes instead of input schema nodes
1720 provided by default */
Radek Krejcia3045382018-11-22 14:30:31 +01001721/** @} sgetnextflags */
1722
1723/**
1724 * @brief Get child node according to the specified criteria.
1725 *
1726 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
1727 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
1728 * @param[in] name Name of the node to find.
1729 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
1730 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
1731 * Used as a bitmask, so multiple nodetypes can be specified.
1732 * @param[in] options [ORed options](@ref sgetnextflags).
1733 * @return Found node if any.
1734 */
1735const struct lysc_node *lys_child(const struct lysc_node *parent, const struct lys_module *module,
1736 const char *name, size_t name_len, uint16_t nodetype, int options);
1737
1738/**
1739 * @brief Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statement
1740 * affecting the node.
1741 *
1742 * @param[in] node Schema node to check.
1743 * @param[in] recursive - 0 to check if-feature only in the \p node schema node,
1744 * - 1 to check if-feature in all ascendant schema nodes until there is a node possibly having an instance in a data tree
1745 * @return - NULL if enabled,
1746 * - pointer to the node with the unsatisfied (disabling) if-feature expression.
1747 */
1748const struct lysc_iffeature *lys_is_disabled(const struct lysc_node *node, int recursive);
1749
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001750/** @} */
1751
Radek Krejci70853c52018-10-15 14:46:16 +02001752#ifdef __cplusplus
1753}
1754#endif
1755
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001756#endif /* LY_TREE_SCHEMA_H_ */