blob: 32d91687aac8b467d9cac26a95c0fb1545e94cc4 [file] [log] [blame]
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001/**
2 * @file tree_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief libyang representation of YANG schema trees.
5 *
6 * Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_TREE_SCHEMA_H_
16#define LY_TREE_SCHEMA_H_
17
Radek Krejci2167ee12018-11-02 16:09:07 +010018#include <pcre.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020019#include <stdint.h>
20
Radek Krejcice8c1592018-10-29 15:35:51 +010021#include "extensions.h"
22
Radek Krejci70853c52018-10-15 14:46:16 +020023#ifdef __cplusplus
24extern "C" {
25#endif
26
Radek Krejci5aeea3a2018-09-05 13:29:36 +020027/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +020028 * @brief XPath representation.
29 */
30struct lyxp_expr;
31
32/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020033 * @brief Macro selector for other LY_ARRAY_* macros, do not use directly!
34 */
35#define LY_ARRAY_SELECT(_1, _2, NAME, ...) NAME
36
37/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020038 * @brief Helper macro to go through sized-arrays with a pointer iterator.
39 *
40 * Use with opening curly bracket (`{`).
41 *
42 * @param[in] ARRAY Array to go through
43 * @param[in] TYPE Type of the records in the ARRAY
44 * @param[out] ITER Iterating pointer to the item being processed in each loop
45 */
46#define LY_ARRAY_FOR_ITER(ARRAY, TYPE, ITER) \
Radek Krejci2c4e7172018-10-19 15:56:26 +020047 for (ITER = ARRAY; \
48 (ARRAY) && ((void*)ITER - (void*)ARRAY)/(sizeof(TYPE)) < (*((uint32_t*)(ARRAY) - 1)); \
Radek Krejcie53a8dc2018-10-17 12:52:40 +020049 ITER = (void*)((TYPE*)ITER + 1))
50
51/**
52 * @brief Helper macro to go through sized-arrays with a numeric iterator.
53 *
54 * Use with opening curly bracket (`{`).
55 *
56 * To access an item with the INDEX value, use always LY_ARRAY_INDEX macro!
57 *
58 * @param[in] ARRAY Array to go through
59 * @param[out] INDEX Iterating index of the item being processed in each loop
60 */
61#define LY_ARRAY_FOR_INDEX(ARRAY, INDEX) \
62 for (INDEX = 0; \
Radek Krejci2c4e7172018-10-19 15:56:26 +020063 ARRAY && INDEX < (*((uint32_t*)(ARRAY) - 1)); \
Radek Krejcie53a8dc2018-10-17 12:52:40 +020064 ++INDEX)
65
66/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +020067 * @defgroup schematree Schema Tree
68 * @{
69 *
70 * Data structures and functions to manipulate and access schema tree.
71 */
72
Radek Krejci0af5f5d2018-09-07 15:00:30 +020073/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020074 * @brief Get a number of records in the ARRAY.
Radek Krejci86d106e2018-10-18 09:53:19 +020075 *
76 * Does not check if array exists!
Radek Krejcie53a8dc2018-10-17 12:52:40 +020077 */
Radek Krejci2c4e7172018-10-19 15:56:26 +020078#define LY_ARRAY_SIZE(ARRAY) (*((uint32_t*)(ARRAY) - 1))
Radek Krejcie53a8dc2018-10-17 12:52:40 +020079
80/**
81 * @brief Sized-array iterator (for-loop).
82 *
83 * Use with opening curly bracket (`{`).
84 *
85 * There are 2 variants:
86 *
87 * LY_ARRAY_FOR(ARRAY, TYPE, ITER)
88 *
89 * 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
90 * providing the items of the ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_ITER macro
91 *
92 * LY_ARRAY_FOR(ARRAY, INDEX)
93 *
94 * 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 +020095 * 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 +020096 */
97#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 +020098
99/**
100 * @brief Macro to iterate via all sibling elements without affecting the list itself
101 *
102 * Works for all types of nodes despite it is data or schema tree, but all the
103 * parameters must be pointers to the same type.
104 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200105 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200106 *
107 * @param START Pointer to the starting element.
108 * @param ELEM Iterator.
109 */
110#define LY_LIST_FOR(START, ELEM) \
111 for ((ELEM) = (START); \
112 (ELEM); \
113 (ELEM) = (ELEM)->next)
114
115/**
Radek Krejci5fac3592018-10-12 15:23:45 +0200116 * @brief Macro to iterate via all sibling elements allowing to modify the list itself (e.g. removing elements)
117 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200118 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200119 *
120 * @param START Pointer to the starting element.
121 * @param NEXT Temporary storage to allow removing of the current iterator content.
122 * @param ELEM Iterator.
123 */
124#define LY_LIST_FOR_SAFE(START, NEXT, ELEM) \
125 for ((ELEM) = (START); \
126 (ELEM) ? (NEXT = (ELEM)->next, 1) : 0; \
127 (ELEM) = (NEXT))
128
129/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200130 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
131 */
132typedef enum {
133 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
134 LYS_IN_YANG = 1, /**< YANG schema input format */
135 LYS_IN_YIN = 2 /**< YIN schema input format */
136} LYS_INFORMAT;
137
138/**
139 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
140 */
141typedef enum {
142 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
143 LYS_OUT_YANG = 1, /**< YANG schema output format */
144 LYS_OUT_YIN = 2, /**< YIN schema output format */
145 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
146 LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
147 LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */
148} LYS_OUTFORMAT;
149
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200150#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
151
Michal Vaskob55f6c12018-09-12 11:13:15 +0200152#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
153#define LYS_CONTAINER 0x0001 /**< container statement node */
154#define LYS_CHOICE 0x0002 /**< choice statement node */
155#define LYS_LEAF 0x0004 /**< leaf statement node */
156#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
157#define LYS_LIST 0x0010 /**< list statement node */
158#define LYS_ANYXML 0x0020 /**< anyxml statement node */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200159#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 +0200160
Radek Krejcia3045382018-11-22 14:30:31 +0100161#define LYS_CASE 0x0040 /**< case statement node */
162#define LYS_USES 0x0080 /**< uses statement node */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100163#define LYS_INOUT 0x200
164#define LYS_ACTION 0x400
165#define LYS_NOTIF 0x800
166#define LYS_GROUPING 0x1000
167#define LYS_AUGMENT 0x2000
168
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200169/**
Radek Krejci2167ee12018-11-02 16:09:07 +0100170 * @brief YANG built-in types
171 */
172typedef enum {
173 LY_TYPE_UNKNOWN = 0, /**< Unknown type */
174 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 +0100175 LY_TYPE_UINT8, /**< 8-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
176 LY_TYPE_UINT16, /**< 16-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
177 LY_TYPE_UINT32, /**< 32-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
178 LY_TYPE_UINT64, /**< 64-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
179 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 +0100180 LY_TYPE_BITS, /**< A set of bits or flags ([RFC 6020 sec 9.7](http://tools.ietf.org/html/rfc6020#section-9.7)) */
181 LY_TYPE_BOOL, /**< "true" or "false" ([RFC 6020 sec 9.5](http://tools.ietf.org/html/rfc6020#section-9.5)) */
182 LY_TYPE_DEC64, /**< 64-bit signed decimal number ([RFC 6020 sec 9.3](http://tools.ietf.org/html/rfc6020#section-9.3))*/
183 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)) */
184 LY_TYPE_ENUM, /**< Enumerated strings ([RFC 6020 sec 9.6](http://tools.ietf.org/html/rfc6020#section-9.6)) */
185 LY_TYPE_IDENT, /**< A reference to an abstract identity ([RFC 6020 sec 9.10](http://tools.ietf.org/html/rfc6020#section-9.10)) */
186 LY_TYPE_INST, /**< References a data tree node ([RFC 6020 sec 9.13](http://tools.ietf.org/html/rfc6020#section-9.13)) */
187 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 +0100188 LY_TYPE_UNION, /**< Choice of member types ([RFC 6020 sec 9.12](http://tools.ietf.org/html/rfc6020#section-9.12)) */
189 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 +0100190 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 +0100191 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 +0100192 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 +0100193} LY_DATA_TYPE;
194#define LY_DATA_TYPE_COUNT 20 /**< Number of different types */
195
Radek Krejci5969f272018-11-23 10:03:58 +0100196/**
197 * @brief Stringified YANG built-in data types
198 */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100199extern const char* ly_data_type2str[LY_DATA_TYPE_COUNT];
200
Radek Krejci2167ee12018-11-02 16:09:07 +0100201/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200202 * @brief YANG import-stmt
203 */
204struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200205 struct lys_module *module; /**< pointer to the imported module
206 (mandatory, but resolved when the referring module is completely parsed) */
207 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200208 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200209 const char *dsc; /**< description */
210 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200211 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200212 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
213};
214
215/**
216 * @brief YANG include-stmt
217 */
218struct lysp_include {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100219 struct lysp_submodule *submodule;/**< pointer to the parsed submodule structure
Radek Krejci086c7132018-10-26 15:29:04 +0200220 (mandatory, but resolved when the referring module is completely parsed) */
221 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200222 const char *dsc; /**< description */
223 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200224 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200225 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
226};
227
228/**
229 * @brief YANG extension-stmt
230 */
231struct lysp_ext {
232 const char *name; /**< extension name */
233 const char *argument; /**< argument name, NULL if not specified */
234 const char *dsc; /**< description statement */
235 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200236 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200237 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
238};
239
240/**
241 * @brief Helper structure for generic storage of the extension instances content.
242 */
243struct lysp_stmt {
244 const char *stmt; /**< identifier of the statement */
245 const char *arg; /**< statement's argument */
246 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200247 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200248};
249
250/**
251 * @brief YANG extension instance
252 */
253struct lysp_ext_instance {
254 const char *name; /**< extension identifier, including possible prefix */
255 const char *argument; /**< optional value of the extension's argument */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200256 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
257 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
258 the index of that substatement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200259 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200260};
261
262/**
263 * @brief YANG feature-stmt
264 */
265struct lysp_feature {
266 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200267 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200268 const char *dsc; /**< description statement */
269 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200270 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200271 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
272};
273
274/**
275 * @brief YANG identity-stmt
276 */
277struct lysp_ident {
278 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200279 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
280 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200281 const char *dsc; /**< description statement */
282 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200283 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200284 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
285};
286
Michal Vasko71e64ca2018-09-07 16:30:29 +0200287/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200288 * @brief Covers restrictions: range, length, pattern, must
289 */
290struct lysp_restr {
291 const char *arg; /**< The restriction expression/value (mandatory);
292 in case of pattern restriction, the first byte has a special meaning:
293 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
294 const char *emsg; /**< error-message */
295 const char *eapptag; /**< error-app-tag value */
296 const char *dsc; /**< description */
297 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200298 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200299};
300
301/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200302 * @brief YANG revision-stmt
303 */
304struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200305 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200306 const char *dsc; /**< description statement */
307 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200308 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200309};
310
311/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200312 * @brief Enumeration/Bit value definition
313 */
314struct lysp_type_enum {
315 const char *name; /**< name (mandatory) */
316 const char *dsc; /**< description statement */
317 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200318 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200319 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200320 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200321 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
322 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200323};
324
325/**
326 * @brief YANG type-stmt
327 *
328 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
329 */
330struct lysp_type {
331 const char *name; /**< name of the type (mandatory) */
332 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
333 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200334 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
335 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
336 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200337 const char *path; /**< path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200338 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200339 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
340 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200341
Radek Krejci2167ee12018-11-02 16:09:07 +0100342 struct lysc_type *compiled; /**< pointer to the compiled type */
343
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200344 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
345 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100346 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200347};
348
349/**
350 * @brief YANG typedef-stmt
351 */
352struct lysp_tpdf {
353 const char *name; /**< name of the newly defined type (mandatory) */
354 const char *units; /**< units of the newly defined type */
355 const char *dflt; /**< default value of the newly defined type */
356 const char *dsc; /**< description statement */
357 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200358 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200359 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100360 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200361};
362
363/**
364 * @brief YANG grouping-stmt
365 */
366struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100367 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
368 uint16_t nodetype; /**< LYS_GROUPING */
369 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200370 const char *name; /**< grouping name (mandatory) */
371 const char *dsc; /**< description statement */
372 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200373 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
374 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200375 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200376 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
377 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
378 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200379};
380
381/**
382 * @brief YANG when-stmt
383 */
384struct lysp_when {
385 const char *cond; /**< specified condition (mandatory) */
386 const char *dsc; /**< description statement */
387 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200388 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200389};
390
391/**
392 * @brief YANG refine-stmt
393 */
394struct lysp_refine {
395 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
396 const char *dsc; /**< description statement */
397 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200398 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200399 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200400 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200401 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200402 uint32_t min; /**< min-elements constraint */
403 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200404 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200405 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
406};
407
408/**
409 * @brief YANG uses-augment-stmt and augment-stmt
410 */
411struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100412 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
413 uint16_t nodetype; /**< LYS_AUGMENT */
414 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200415 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
416 const char *dsc; /**< description statement */
417 const char *ref; /**< reference statement */
418 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200419 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200420 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200421 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
422 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
423 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200424};
425
426/**
427 * @defgroup deviatetypes Deviate types
428 * @{
429 */
430#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
431#define LYS_DEV_ADD 2 /**< deviate type add */
432#define LYS_DEV_DELETE 3 /**< deviate type delete */
433#define LYS_DEV_REPLACE 4 /**< deviate type replace */
434/** @} */
435
436/**
437 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
438 */
439struct lysp_deviate {
440 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
441 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200442 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200443};
444
445struct lysp_deviate_add {
446 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
447 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200448 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200449 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200450 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200451 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
452 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200453 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
454 uint32_t min; /**< min-elements constraint */
455 uint32_t max; /**< max-elements constraint, 0 means unbounded */
456};
457
458struct lysp_deviate_del {
459 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
460 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200461 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200462 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200463 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200464 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
465 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200466 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200467};
468
469struct lysp_deviate_rpl {
470 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
471 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200472 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200473 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200474 const char *units; /**< units of the values */
475 const char *dflt; /**< default value */
476 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
477 uint32_t min; /**< min-elements constraint */
478 uint32_t max; /**< max-elements constraint, 0 means unbounded */
479};
480
481struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200482 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200483 const char *dsc; /**< description statement */
484 const char *ref; /**< reference statement */
485 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200486 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200487};
488
Radek Krejci4f28eda2018-11-12 11:46:16 +0100489/**
490 * @defgroup spnodeflags Parsed schema nodes flags
491 * @ingroup snodeflags
492 *
493 * Various flags for parsed schema nodes.
494 *
495 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
496 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
497 * 3 - leaf 8 - notification 13 - identity 18 - refine
498 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
499 * 5 - list 10 - input 15 - typedef 20 - deviate
500 *
501 * 1 1 1 1 1 1 1 1 1 1 2 2 2
502 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
503 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
504 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | |
Radek Krejcid505e3d2018-11-13 09:04:17 +0100505 * LYS_SET_BASE | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100506 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
507 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | |
Radek Krejcid505e3d2018-11-13 09:04:17 +0100508 * LYS_SET_BIT | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100509 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
510 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| |
Radek Krejcid505e3d2018-11-13 09:04:17 +0100511 * LYS_SET_ENUM | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100512 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
513 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| |
Radek Krejcid505e3d2018-11-13 09:04:17 +0100514 * LYS_SET_FRDIGITS | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100515 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
516 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| |
Radek Krejcid505e3d2018-11-13 09:04:17 +0100517 * LYS_SET_LENGTH | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100518 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
519 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | |
Radek Krejcid505e3d2018-11-13 09:04:17 +0100520 * LYS_SET_PATH | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100521 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
522 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | |
523 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | |
Radek Krejcid505e3d2018-11-13 09:04:17 +0100524 * LYS_SET_PATTERN | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100525 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejcife909632019-02-12 15:34:42 +0100526 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | |
527 * LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | |
Radek Krejcid505e3d2018-11-13 09:04:17 +0100528 * LYS_SET_RANGE | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100529 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
530 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | |
Radek Krejcid505e3d2018-11-13 09:04:17 +0100531 * LYS_SET_TYPE | | | | | | | | | | | | | | | | | | | | | |x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100532 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
533 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| |
534 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x|
535 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | |
536 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
537 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | |
Radek Krejci4f28eda2018-11-12 11:46:16 +0100538 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
539 *
540 */
541
542/**
543 * @defgroup scnodeflags Compiled schema nodes flags
544 * @ingroup snodeflags
545 *
546 * Various flags for compiled schema nodes.
547 *
548 * 1 - container 6 - anydata/anyxml 11 - output
549 * 2 - choice 7 - case 12 - feature
550 * 3 - leaf 8 - notification 13 - identity
551 * 4 - leaflist 9 - rpc 14 - extension
552 * 5 - list 10 - input
553 *
554 * 1 1 1 1 1
555 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
556 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
557 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | |x| | | | |
558 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
559 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | |x| | | |
560 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100561 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100562 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100563 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100564 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100565 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|
Radek Krejci4f28eda2018-11-12 11:46:16 +0100566 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejcife909632019-02-12 15:34:42 +0100567 * 6 LYS_MAND_TRUE |x|x|x|x|x|x| | | | | | | | |
Radek Krejci4f28eda2018-11-12 11:46:16 +0100568 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
569 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100570 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejcife909632019-02-12 15:34:42 +0100571 * 8 LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | |
572 * LYS_PRESENCE |x| | | | | | | | | | | | | |
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100573 * LYS_UNIQUE | | |x| | | | | | | | | | | |
574 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
575 * 9 LYS_KEY | | |x| | | | | | | | | | | |
576 * LYS_FENABLED | | | | | | | | | | | |x| | |
Radek Krejci76b3e962018-12-14 17:01:25 +0100577 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Radek Krejciccd20f12019-02-15 14:12:27 +0100578 * 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
579 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
580 * 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
Radek Krejci4f28eda2018-11-12 11:46:16 +0100581 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
582 *
583 */
584
585/**
586 * @defgroup snodeflags Schema nodes flags
587 * @ingroup schematree
588 * @{
589 */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200590#define LYS_CONFIG_W 0x01 /**< config true; */
591#define LYS_CONFIG_R 0x02 /**< config false; */
592#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100593#define LYS_STATUS_CURR 0x04 /**< status current; */
594#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
595#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
596#define LYS_STATUS_MASK 0x1C /**< mask for status value */
597#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
Radek Krejcife909632019-02-12 15:34:42 +0100598 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata.
599 The ::lysc_node_leaflist and ::lysc_node_leaflist have this flag in case that min-elements > 0.
600 The ::lysc_node_container has this flag if it is not a presence container and it has at least one
601 child with LYS_MAND_TRUE. */
Radek Krejci01342af2019-01-03 15:18:08 +0100602#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to ::lysp_node_choice, ::lysp_node_leaf and ::lysp_node_anydata */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100603#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
Radek Krejci7adf4ff2018-12-05 08:55:00 +0100604#define LYS_PRESENCE 0x80 /**< flag for presence property of a container, applicable only to ::lysc_node_container */
605#define LYS_UNIQUE 0x80 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
606#define LYS_KEY 0x100 /**< flag for leafs being a key of a list, applicable only to ::lysc_node_leaf */
607#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysc_feature */
Radek Krejcife909632019-02-12 15:34:42 +0100608#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 +0100609 ::lysc_node_list/::lysp_node_list */
610#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
611 ::lysc_node_list/::lysp_node_list */
612#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
613#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
614#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
615#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
616#define LYS_SET_VALUE 0x200 /**< value attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100617#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200618#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejcid505e3d2018-11-13 09:04:17 +0100619
620#define LYS_SET_BASE 0x0001 /**< type's flag for present base substatement */
621#define LYS_SET_BIT 0x0002 /**< type's flag for present bit substatement */
622#define LYS_SET_ENUM 0x0004 /**< type's flag for present enum substatement */
623#define LYS_SET_FRDIGITS 0x0008 /**< type's flag for present fraction-digits substatement */
624#define LYS_SET_LENGTH 0x0010 /**< type's flag for present length substatement */
625#define LYS_SET_PATH 0x0020 /**< type's flag for present path substatement */
626#define LYS_SET_PATTERN 0x0040 /**< type's flag for present pattern substatement */
627#define LYS_SET_RANGE 0x0080 /**< type's flag for present range substatement */
628#define LYS_SET_TYPE 0x0100 /**< type's flag for present type substatement */
629#define LYS_SET_REQINST 0x0200 /**< type's flag for present require-instance substatement */
Radek Krejciccd20f12019-02-15 14:12:27 +0100630#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 +0100631 cases of choice. This information is important for refines, since it is prohibited to make leafs
632 with default statement mandatory. In case the default leaf value is taken from type, it is thrown
Radek Krejciccd20f12019-02-15 14:12:27 +0100633 away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
634 between own default or the default values taken from the type. */
635#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 Krejci0e5d8382018-11-28 16:37:53 +0100636
Radek Krejcife909632019-02-12 15:34:42 +0100637#define LYS_FLAGS_COMPILED_MASK 0xff /**< mask for flags that maps to the compiled structures */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100638/** @} */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200639
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200640/**
641 * @brief Generic YANG data node
642 */
643struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100644 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200645 uint16_t nodetype; /**< type of the node (mandatory) */
646 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100647 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200648 const char *name; /**< node name (mandatory) */
649 const char *dsc; /**< description statement */
650 const char *ref; /**< reference statement */
651 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200652 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200653 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200654};
655
656/**
657 * @brief Extension structure of the lysp_node for YANG container
658 */
659struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100660 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200661 uint16_t nodetype; /**< LYS_CONTAINER */
662 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
663 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
664 const char *name; /**< node name (mandatory) */
665 const char *dsc; /**< description statement */
666 const char *ref; /**< reference statement */
667 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200668 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200669 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200670
671 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200672 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200673 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200674 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
675 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200676 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200677 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
678 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200679};
680
681struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100682 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200683 uint16_t nodetype; /**< LYS_LEAF */
684 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
685 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
686 const char *name; /**< node name (mandatory) */
687 const char *dsc; /**< description statement */
688 const char *ref; /**< reference statement */
689 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200690 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200691 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200692
693 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200694 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200695 struct lysp_type type; /**< type of the leaf node (mandatory) */
696 const char *units; /**< units of the leaf's type */
697 const char *dflt; /**< default value */
698};
699
700struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100701 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200702 uint16_t nodetype; /**< LYS_LEAFLIST */
703 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
704 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
705 const char *name; /**< node name (mandatory) */
706 const char *dsc; /**< description statement */
707 const char *ref; /**< reference statement */
708 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200709 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200710 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200711
712 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200713 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200714 struct lysp_type type; /**< type of the leaf node (mandatory) */
715 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200716 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200717 uint32_t min; /**< min-elements constraint */
718 uint32_t max; /**< max-elements constraint, 0 means unbounded */
719};
720
721struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100722 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200723 uint16_t nodetype; /**< LYS_LIST */
724 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
725 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
726 const char *name; /**< node name (mandatory) */
727 const char *dsc; /**< description statement */
728 const char *ref; /**< reference statement */
729 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200730 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200731 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200732
733 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200734 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200735 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200736 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
737 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200738 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200739 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
740 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200741 const char **uniques; /**< list of unique specifications ([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_choice {
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_CHOICE */
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 /* choice */
759 struct lysp_node *child; /**< list of data nodes (linked list) */
760 const char* dflt; /**< default case */
761};
762
763struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100764 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200765 uint16_t nodetype; /**< LYS_CASE */
766 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
767 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
768 const char *name; /**< node name (mandatory) */
769 const char *dsc; /**< description statement */
770 const char *ref; /**< reference statement */
771 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200772 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200773 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200774
775 /* case */
776 struct lysp_node *child; /**< list of data nodes (linked list) */
777};
778
779struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100780 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200781 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
782 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
783 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
784 const char *name; /**< node name (mandatory) */
785 const char *dsc; /**< description statement */
786 const char *ref; /**< reference statement */
787 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200788 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200789 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200790
791 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200792 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200793};
794
795struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100796 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200797 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200798 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
799 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
800 const char *name; /**< grouping name reference (mandatory) */
801 const char *dsc; /**< description statement */
802 const char *ref; /**< reference statement */
803 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200804 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200805 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200806
807 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200808 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
809 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200810};
811
812/**
813 * @brief YANG input-stmt and output-stmt
814 */
815struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100816 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
817 uint16_t nodetype; /**< LYS_INOUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200818 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
819 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
820 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200821 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200822 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200823};
824
825/**
826 * @brief YANG rpc-stmt and action-stmt
827 */
828struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100829 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
830 uint16_t nodetype; /**< LYS_ACTION */
831 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200832 const char *name; /**< grouping name reference (mandatory) */
833 const char *dsc; /**< description statement */
834 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200835 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200836 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
837 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200838 struct lysp_action_inout *input; /**< RPC's/Action's input */
839 struct lysp_action_inout *output;/**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200840 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200841};
842
843/**
844 * @brief YANG notification-stmt
845 */
846struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100847 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
848 uint16_t nodetype; /**< LYS_NOTIF */
849 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200850 const char *name; /**< grouping name reference (mandatory) */
851 const char *dsc; /**< description statement */
852 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200853 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200854 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
855 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
856 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200857 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200858 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200859};
860
861/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200862 * @brief supported YANG schema version values
863 */
864typedef enum LYS_VERSION {
865 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
866 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
867 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
868} LYS_VERSION;
869
870/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200871 * @brief Printable YANG schema tree structure representing YANG module.
872 *
873 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
874 */
875struct lysp_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100876 struct lys_module *mod; /**< covering module structure */
877
Radek Krejcib7db73a2018-10-24 14:18:40 +0200878 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
879 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200880 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
881 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200882 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
883 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
884 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
885 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
886 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200887 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200888 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
889 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
890 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
891 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
892 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200893
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100894 uint8_t parsing:1; /**< flag for circular check */
895};
896
897struct lysp_submodule {
898 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
899
900 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
901 in the list is always the last (newest) revision of the module */
902 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
903 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
904 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
905 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
906 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
907 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
908 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
909 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
910 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
911 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
912 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
913 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
914 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
915
916 uint8_t parsing:1; /**< flag for circular check */
917
Radek Krejci086c7132018-10-26 15:29:04 +0200918 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
919 1 - the latest revision in searchdirs was not searched yet and this is the
920 latest revision in the current context
921 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100922 const char *name; /**< name of the module (mandatory) */
923 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
924 const char *prefix; /**< submodule belongsto prefix of main module (mandatory) */
925 const char *org; /**< party/company responsible for the module */
926 const char *contact; /**< contact information for the module */
927 const char *dsc; /**< description of the module */
928 const char *ref; /**< cross-reference for the module */
Radek Krejci086c7132018-10-26 15:29:04 +0200929 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200930};
931
932/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200933 * @brief Free the printable YANG schema tree structure.
934 *
935 * @param[in] module Printable YANG schema tree structure to free.
936 */
937void lysp_module_free(struct lysp_module *module);
938
939/**
Radek Krejcice8c1592018-10-29 15:35:51 +0100940 * @brief YANG extension instance
941 */
942struct lysc_ext_instance {
943 struct lyext_plugin *plugin; /**< pointer to the plugin implementing the extension (if present) */
944 void *parent; /**< pointer to the parent element holding the extension instance(s), use
945 ::lysc_ext_instance#parent_type to access the schema element */
946 const char *argument; /**< optional value of the extension's argument */
947 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
948 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
949 this identifies the index of the substatement for this extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +0100950 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejcice8c1592018-10-29 15:35:51 +0100951#if 0
Radek Krejcice8c1592018-10-29 15:35:51 +0100952 uint8_t ext_type; /**< extension type (#LYEXT_TYPE) */
953 uint8_t padding; /**< 32b padding */
Radek Krejcice8c1592018-10-29 15:35:51 +0100954 struct lys_module *module; /**< pointer to the extension instance's module (mandatory) */
955 LYS_NODE nodetype; /**< LYS_EXT */
956#endif
Radek Krejci2a408df2018-10-29 16:32:26 +0100957 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
958 void *priv; /**< private caller's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +0100959};
960
961/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +0100962 * @brief Compiled YANG if-feature-stmt
963 */
964struct lysc_iffeature {
965 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
966 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
967};
968
969/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200970 * @brief YANG import-stmt
971 */
972struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100973 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +0200974 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejcice8c1592018-10-29 15:35:51 +0100975 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200976};
977
978/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200979 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200980 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200981struct lysc_when {
982 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +0100983 const char *dsc; /**< description */
984 const char *ref; /**< reference */
Radek Krejci00b874b2019-02-12 10:54:50 +0100985 struct lysc_node *context; /**< context node for evaluating the expression */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200986 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +0100987 uint32_t refcount; /**< reference counter since some of the when statements are shared among several nodes */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200988};
989
990/**
Radek Krejci2a408df2018-10-29 16:32:26 +0100991 * @brief YANG identity-stmt
992 */
993struct lysc_ident {
994 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejcic8b31002019-01-08 10:24:45 +0100995 const char *dsc; /**< description */
996 const char *ref; /**< reference */
Radek Krejci2a408df2018-10-29 16:32:26 +0100997 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
998 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
999 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1000 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
1001};
1002
1003/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001004 * @brief YANG feature-stmt
1005 */
1006struct lysc_feature {
1007 const char *name; /**< feature name (mandatory) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001008 const char *dsc; /**< description */
1009 const char *ref; /**< reference */
Radek Krejci151a5b72018-10-19 14:21:44 +02001010 struct lysc_feature **depfeatures;/**< list of pointers to other features depending on this one ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001011 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001012 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001013 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
1014 #LYS_FENABLED values allowed */
1015};
1016
Radek Krejci151a5b72018-10-19 14:21:44 +02001017/**
1018 * @defgroup ifftokens if-feature expression tokens
1019 * Tokens of if-feature expression used in ::lysc_iffeature#expr
1020 *
1021 * @{
1022 */
1023#define LYS_IFF_NOT 0x00 /**< operand "not" */
1024#define LYS_IFF_AND 0x01 /**< operand "and" */
1025#define LYS_IFF_OR 0x02 /**< operand "or" */
1026#define LYS_IFF_F 0x03 /**< feature */
1027/**
1028 * @}
1029 */
1030
1031/**
Radek Krejcib7db73a2018-10-24 14:18:40 +02001032 * @brief Compiled YANG revision statement
1033 */
1034struct lysc_revision {
1035 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
1036 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1037};
1038
Radek Krejci2167ee12018-11-02 16:09:07 +01001039struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001040 struct lysc_range_part {
Radek Krejci2167ee12018-11-02 16:09:07 +01001041 union { /**< min boundary TODO decimal */
1042 int64_t min_64; /**< for int8, int16, int32 and int64 */
1043 uint64_t min_u64; /**< for uint8, uint16, uint32 and uint64 */
1044 };
1045 union { /**< max boundary TODO decimal */
1046 int64_t max_64; /**< for int8, int16, int32 and int64 */
1047 uint64_t max_u64; /**< for uint8, uint16, uint32 and uint64 */
1048 };
Radek Krejci4f28eda2018-11-12 11:46:16 +01001049 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejcic8b31002019-01-08 10:24:45 +01001050 const char *dsc; /**< description */
1051 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001052 const char *emsg; /**< error-message */
1053 const char *eapptag; /**< error-app-tag value */
1054 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1055};
1056
1057struct lysc_pattern {
1058 pcre *expr; /**< compiled regular expression */
1059 pcre_extra *expr_extra; /**< additional information to speed up matching */
Radek Krejcic8b31002019-01-08 10:24:45 +01001060 const char *dsc; /**< description */
1061 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001062 const char *emsg; /**< error-message */
1063 const char *eapptag; /**< error-app-tag value */
1064 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci4586a022018-11-13 11:29:26 +01001065 uint32_t inverted:1; /**< invert-match flag */
1066 uint32_t refcount:31; /**< reference counter */
Radek Krejci2167ee12018-11-02 16:09:07 +01001067};
1068
1069struct lysc_must {
1070 struct lys_module *module; /**< module where the must was defined */
1071 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcic8b31002019-01-08 10:24:45 +01001072 const char *dsc; /**< description */
1073 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001074 const char *emsg; /**< error-message */
1075 const char *eapptag; /**< error-app-tag value */
1076 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1077};
1078
1079struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001080 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001081 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001082 LY_DATA_TYPE basetype; /**< Base type of the type */
1083 uint32_t refcount; /**< reference counter for type sharing */
1084};
1085
1086struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001087 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001088 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001089 LY_DATA_TYPE basetype; /**< Base type of the type */
1090 uint32_t refcount; /**< reference counter for type sharing */
1091 struct lysc_range *range; /**< Optional range limitation */
1092};
1093
1094struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001095 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001096 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001097 LY_DATA_TYPE basetype; /**< Base type of the type */
1098 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci6cba4292018-11-15 17:33:29 +01001099 uint8_t fraction_digits; /**< fraction digits specification */
Radek Krejci2167ee12018-11-02 16:09:07 +01001100 struct lysc_range *range; /**< Optional range limitation */
1101};
1102
1103struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001104 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001105 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001106 LY_DATA_TYPE basetype; /**< Base type of the type */
1107 uint32_t refcount; /**< reference counter for type sharing */
1108 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci4586a022018-11-13 11:29:26 +01001109 struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001110};
1111
1112struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001113 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001114 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001115 LY_DATA_TYPE basetype; /**< Base type of the type */
1116 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci8b764662018-11-14 14:15:13 +01001117 struct lysc_type_enum_item {
Radek Krejci2167ee12018-11-02 16:09:07 +01001118 const char *name; /**< enumeration identifier */
Radek Krejcic8b31002019-01-08 10:24:45 +01001119 const char *dsc; /**< description */
1120 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001121 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci8b764662018-11-14 14:15:13 +01001122 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001123 int32_t value; /**< integer value associated with the enumeration */
1124 } *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1125};
1126
1127struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001128 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001129 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001130 LY_DATA_TYPE basetype; /**< Base type of the type */
1131 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejcia3045382018-11-22 14:30:31 +01001132 const char* path; /**< target path */
Radek Krejci96a0bfd2018-11-22 15:25:06 +01001133 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 +01001134 struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
Radek Krejci2167ee12018-11-02 16:09:07 +01001135 uint8_t require_instance; /**< require-instance flag */
1136};
1137
1138struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001139 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001140 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001141 LY_DATA_TYPE basetype; /**< Base type of the type */
1142 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci555cb5b2018-11-16 14:54:33 +01001143 struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
Radek Krejci2167ee12018-11-02 16:09:07 +01001144 mandatory (at least 1 item) */
1145};
1146
1147struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001148 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001149 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001150 LY_DATA_TYPE basetype; /**< Base type of the type */
1151 uint32_t refcount; /**< reference counter for type sharing */
1152 uint8_t require_instance; /**< require-instance flag */
1153};
1154
1155struct lysc_type_bits {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001156 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001157 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001158 LY_DATA_TYPE basetype; /**< Base type of the type */
1159 uint32_t refcount; /**< reference counter for type sharing */
Radek Krejci8b764662018-11-14 14:15:13 +01001160 struct lysc_type_bits_item {
Radek Krejci2167ee12018-11-02 16:09:07 +01001161 const char *name; /**< bit identifier */
Radek Krejcic8b31002019-01-08 10:24:45 +01001162 const char *dsc; /**< description */
1163 const char *ref; /**< reference */
Radek Krejci2167ee12018-11-02 16:09:07 +01001164 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci8b764662018-11-14 14:15:13 +01001165 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001166 uint32_t position; /**< non-negative integer value associated with the bit */
1167 } *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1168};
1169
1170struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001171 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001172 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001173 LY_DATA_TYPE basetype; /**< Base type of the type */
1174 uint32_t refcount; /**< reference counter for type sharing */
1175 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1176};
1177
1178struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001179 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci01342af2019-01-03 15:18:08 +01001180 const char *dflt; /**< type's default value if any */
Radek Krejci2167ee12018-11-02 16:09:07 +01001181 LY_DATA_TYPE basetype; /**< Base type of the type */
1182 uint32_t refcount; /**< reference counter for type sharing */
1183 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001184};
1185
Radek Krejci056d0a82018-12-06 16:57:25 +01001186struct lysc_action {
1187 uint16_t nodetype; /**< LYS_ACTION */
1188 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001189 struct lys_module *module; /**< module structure */
Radek Krejci056d0a82018-12-06 16:57:25 +01001190 const char *name; /**< action/RPC name (mandatory) */
1191 /* TODO */
1192};
1193
1194struct lysc_notif {
1195 uint16_t nodetype; /**< LYS_NOTIF */
1196 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci95710c92019-02-11 15:49:55 +01001197 struct lys_module *module; /**< module structure */
Radek Krejci056d0a82018-12-06 16:57:25 +01001198 const char *name; /**< Notification name (mandatory) */
1199 /* TODO */
1200};
1201
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001202/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001203 * @brief Compiled YANG data node
1204 */
1205struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001206 uint16_t nodetype; /**< type of the node (mandatory) */
1207 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001208 struct lys_module *module; /**< module structure */
1209 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. */
1210 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1211 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1212 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1213 never NULL. If there is no sibling node, pointer points to the node
1214 itself. In case of the first node, this pointer points to the last
1215 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001216 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001217 const char *dsc; /**< description */
1218 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001219 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001220 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001221 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001222};
1223
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001224struct lysc_node_container {
1225 uint16_t nodetype; /**< LYS_CONTAINER */
1226 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1227 struct lys_module *module; /**< module structure */
1228 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. */
1229 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1230 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1231 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1232 never NULL. If there is no sibling node, pointer points to the node
1233 itself. In case of the first node, this pointer points to the last
1234 node in the list. */
1235 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001236 const char *dsc; /**< description */
1237 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001238 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001239 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001240 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1241
1242 struct lysc_node *child; /**< first child node (linked list) */
1243 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1244 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1245 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001246};
1247
Radek Krejcia3045382018-11-22 14:30:31 +01001248struct lysc_node_case {
Radek Krejci056d0a82018-12-06 16:57:25 +01001249 uint16_t nodetype; /**< LYS_CASE */
1250 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1251 struct lys_module *module; /**< module structure */
1252 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. */
1253 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1254 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1255 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1256 never NULL. If there is no sibling node, pointer points to the node
1257 itself. In case of the first node, this pointer points to the last
1258 node in the list. */
Radek Krejcia3045382018-11-22 14:30:31 +01001259 const char *name; /**< name of the case, including the implicit case */
Radek Krejci12fb9142019-01-08 09:45:30 +01001260 const char *dsc; /**< description */
1261 const char *ref; /**< reference */
Radek Krejci056d0a82018-12-06 16:57:25 +01001262 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001263 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001264 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1265
Radek Krejcia3045382018-11-22 14:30:31 +01001266 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 +01001267 each other as siblings with the parent pointer pointing to appropriate case node. */
Radek Krejcia3045382018-11-22 14:30:31 +01001268};
1269
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001270struct lysc_node_choice {
1271 uint16_t nodetype; /**< LYS_CHOICE */
1272 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1273 struct lys_module *module; /**< module structure */
1274 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1275 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1276 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1277 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1278 never NULL. If there is no sibling node, pointer points to the node
1279 itself. In case of the first node, this pointer points to the last
1280 node in the list. */
1281 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001282 const char *dsc; /**< description */
1283 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001284 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001285 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001286 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001287
Radek Krejcia9026eb2018-12-12 16:04:47 +01001288 struct lysc_node_case *cases; /**< list of the cases (linked list). Note that all the children of all the cases are linked each other
1289 as siblings. Their parent pointers points to the specific case they belongs to, so distinguish the
1290 case is simple. */
Radek Krejci056d0a82018-12-06 16:57:25 +01001291 struct lysc_node_case *dflt; /**< default case of the choice, only a pointer into the cases array. */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001292};
1293
1294struct lysc_node_leaf {
1295 uint16_t nodetype; /**< LYS_LEAF */
1296 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1297 struct lys_module *module; /**< module structure */
1298 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1299 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1300 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1301 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1302 never NULL. If there is no sibling node, pointer points to the node
1303 itself. In case of the first node, this pointer points to the last
1304 node in the list. */
1305 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001306 const char *dsc; /**< description */
1307 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001308 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001309 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci4f28eda2018-11-12 11:46:16 +01001310 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1311
1312 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1313 struct lysc_type *type; /**< type of the leaf node (mandatory) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001314
Radek Krejci4f28eda2018-11-12 11:46:16 +01001315 const char *units; /**< units of the leaf's type */
1316 const char *dflt; /**< default value */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001317};
1318
1319struct lysc_node_leaflist {
1320 uint16_t nodetype; /**< LYS_LEAFLIST */
1321 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1322 struct lys_module *module; /**< module structure */
1323 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. */
1324 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1325 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1326 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1327 never NULL. If there is no sibling node, pointer points to the node
1328 itself. In case of the first node, this pointer points to the last
1329 node in the list. */
1330 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001331 const char *dsc; /**< description */
1332 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001333 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001334 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejcib57cf1e2018-11-23 14:07:05 +01001335 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1336
1337 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1338 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1339
Radek Krejci0e5d8382018-11-28 16:37:53 +01001340 const char *units; /**< units of the leaf's type */
1341 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
1342 uint32_t min; /**< min-elements constraint */
1343 uint32_t max; /**< max-elements constraint */
1344
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001345};
1346
1347struct lysc_node_list {
1348 uint16_t nodetype; /**< LYS_LIST */
1349 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1350 struct lys_module *module; /**< module structure */
1351 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. */
1352 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1353 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1354 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1355 never NULL. If there is no sibling node, pointer points to the node
1356 itself. In case of the first node, this pointer points to the last
1357 node in the list. */
1358 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001359 const char *dsc; /**< description */
1360 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001361 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001362 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001363 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1364
1365 struct lysc_node *child; /**< first child node (linked list) */
1366 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1367 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1368 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
1369
1370 struct lysc_node_leaf **keys; /**< list of pointers to the keys ([sized array](@ref sizedarrays)) */
1371 struct lysc_node_leaf ***uniques; /**< list of sized arrays of pointers to the unique nodes ([sized array](@ref sizedarrays)) */
1372 uint32_t min; /**< min-elements constraint */
1373 uint32_t max; /**< max-elements constraint */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001374};
1375
1376struct lysc_node_anydata {
1377 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1378 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1379 struct lys_module *module; /**< module structure */
1380 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. */
1381 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1382 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1383 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1384 never NULL. If there is no sibling node, pointer points to the node
1385 itself. In case of the first node, this pointer points to the last
1386 node in the list. */
1387 const char *name; /**< node name (mandatory) */
Radek Krejci12fb9142019-01-08 09:45:30 +01001388 const char *dsc; /**< description */
1389 const char *ref; /**< reference */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001390 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci00b874b2019-02-12 10:54:50 +01001391 struct lysc_when **when; /**< list of pointers to when statements ([sized array](@ref sizedarrays)) */
Radek Krejci056d0a82018-12-06 16:57:25 +01001392 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci9800fb82018-12-13 14:26:23 +01001393
1394 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001395};
1396
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001397/**
1398 * @brief Compiled YANG schema tree structure representing YANG module.
1399 *
1400 * Semantically validated YANG schema tree for data tree parsing.
1401 * Contains only the necessary information for the data validation.
1402 */
1403struct lysc_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001404 struct lys_module *mod; /**< covering module structure */
Radek Krejci151a5b72018-10-19 14:21:44 +02001405 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001406
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001407 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001408 struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1409 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1410 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1411 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001412 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001413};
1414
1415/**
Radek Krejci53ea6152018-12-13 15:21:15 +01001416 * @brief Get the groupings sized array of the given (parsed) schema node.
1417 * Decides the node's type and in case it has a groupings array, returns it.
1418 * @param[in] node Node to examine.
1419 * @return The node's groupings sized array if any, NULL otherwise.
1420 */
1421const struct lysp_grp *lysp_node_groupings(const struct lysp_node *node);
1422
1423/**
Radek Krejci056d0a82018-12-06 16:57:25 +01001424 * @brief Get the typedefs sized array of the given (parsed) schema node.
1425 * Decides the node's type and in case it has a typedefs array, returns it.
1426 * @param[in] node Node to examine.
1427 * @return The node's typedefs sized array if any, NULL otherwise.
1428 */
1429const struct lysp_tpdf *lysp_node_typedefs(const struct lysp_node *node);
1430
1431/**
1432 * @brief Get the actions/RPCs sized array of the given (parsed) schema node.
1433 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1434 * @param[in] node Node to examine.
1435 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1436 */
1437const struct lysp_action *lysp_node_actions(const struct lysp_node *node);
1438
1439/**
1440 * @brief Get the Notifications sized array of the given (parsed) schema node.
1441 * Decides the node's type and in case it has a Notifications array, returns it.
1442 * @param[in] node Node to examine.
1443 * @return The node's Notifications sized array if any, NULL otherwise.
1444 */
1445const struct lysp_notif *lysp_node_notifs(const struct lysp_node *node);
1446
1447/**
1448 * @brief Get the children linked list of the given (parsed) schema node.
1449 * Decides the node's type and in case it has a children list, returns it.
1450 * @param[in] node Node to examine.
1451 * @return The node's children linked list if any, NULL otherwise.
1452 */
1453const struct lysp_node *lysp_node_children(const struct lysp_node *node);
1454
1455/**
1456 * @brief Get the actions/RPCs sized array of the given (compiled) schema node.
1457 * Decides the node's type and in case it has a actions/RPCs array, returns it.
1458 * @param[in] node Node to examine.
1459 * @return The node's actions/RPCs sized array if any, NULL otherwise.
1460 */
1461const struct lysc_action *lysc_node_actions(const struct lysc_node *node);
1462
1463/**
1464 * @brief Get the Notifications sized array of the given (compiled) schema node.
1465 * Decides the node's type and in case it has a Notifications array, returns it.
1466 * @param[in] node Node to examine.
1467 * @return The node's Notifications sized array if any, NULL otherwise.
1468 */
1469const struct lysc_notif *lysc_node_notifs(const struct lysc_node *node);
1470
1471/**
1472 * @brief Get the children linked list of the given (compiled) schema node.
1473 * Decides the node's type and in case it has a children list, returns it.
1474 * @param[in] node Node to examine.
1475 * @return The node's children linked list if any, NULL otherwise.
1476 */
1477const struct lysc_node *lysc_node_children(const struct lysc_node *node);
1478
1479/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001480 * @brief Get how the if-feature statement currently evaluates.
1481 *
1482 * @param[in] iff Compiled if-feature statement to evaluate.
1483 * @return If the statement evaluates to true, 1 is returned. 0 is returned when the statement evaluates to false.
1484 */
1485int lysc_iffeature_value(const struct lysc_iffeature *iff);
1486
1487/**
1488 * @brief Get the current status of the provided feature.
1489 *
1490 * @param[in] feature Compiled feature statement to examine.
1491 * @return
1492 * - 1 if feature is enabled,
1493 * - 0 if feature is disabled,
1494 * - -1 in case of error (invalid argument)
1495 */
1496int lysc_feature_value(const struct lysc_feature *feature);
1497
1498/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001499 * @brief Available YANG schema tree structures representing YANG module.
1500 */
1501struct lys_module {
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001502 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
1503 const char *name; /**< name of the module (mandatory) */
Radek Krejci0af46292019-01-11 16:02:31 +01001504 const char *revision; /**< revision of the module (if present) */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001505 const char *ns; /**< namespace of the module (module - mandatory) */
1506 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
1507 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
1508 const char *org; /**< party/company responsible for the module */
1509 const char *contact; /**< contact information for the module */
1510 const char *dsc; /**< description of the module */
1511 const char *ref; /**< cross-reference for the module */
1512
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001513 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
Radek Krejci0af46292019-01-11 16:02:31 +01001514 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing.
1515 Available only for implemented modules. */
1516 struct lysc_feature *off_features;/**< List of pre-compiled features of the module in non implemented modules ([sized array](@ref sizedarrays)).
1517 These features are always disabled and cannot be enabled until the module
1518 become implemented. The features are present in this form to allow their linkage
1519 from if-feature statements of the compiled schemas and their proper use in case
1520 the module became implemented in future (no matter if implicitly via augment/deviate
1521 or explicitly via ly_ctx_module_implement()). */
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001522
Radek Krejci95710c92019-02-11 15:49:55 +01001523 uint8_t implemented; /**< flag if the module is implemented, not just imported. The module is implemented if
1524 the flag has non-zero value. Specific values are used internally:
1525 1 - implemented module
1526 2 - recently implemented module by dependency, it can be reverted in rollback procedure */
1527 uint8_t latest_revision; /**< flag to mark the latest available revision:
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001528 1 - the latest revision in searchdirs was not searched yet and this is the
1529 latest revision in the current context
1530 2 - searchdirs were searched and this is the latest available revision */
1531 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001532};
1533
Radek Krejci151a5b72018-10-19 14:21:44 +02001534/**
1535 * @brief Enable specified feature in the module
1536 *
1537 * By default, when the module is loaded by libyang parser, all features are disabled.
1538 *
Radek Krejcica3db002018-11-01 10:31:01 +01001539 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
1540 * enabling all features on the following feature set will fail since it is not possible to enable both features
1541 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
1542 * is untouched.
1543 *
1544 * feature f1;
1545 * feature f2 { if-feature 'not f1';}
1546 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001547 * @param[in] module Module where the feature will be enabled.
1548 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
1549 * @return LY_ERR value.
1550 */
1551LY_ERR lys_feature_enable(struct lys_module *module, const char *feature);
1552
1553/**
1554 * @brief Disable specified feature in the module
1555 *
1556 * By default, when the module is loaded by libyang parser, all features are disabled.
1557 *
1558 * @param[in] module Module where the feature will be disabled.
1559 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
1560 * @return LY_ERR value
1561 */
1562LY_ERR lys_feature_disable(struct lys_module *module, const char *feature);
1563
1564/**
1565 * @brief Get the current status of the specified feature in the module.
1566 *
1567 * @param[in] module Module where the feature is defined.
1568 * @param[in] feature Name of the feature to inspect.
1569 * @return
1570 * - 1 if feature is enabled,
1571 * - 0 if feature is disabled,
1572 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
1573 */
1574int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001575
1576/**
Radek Krejci86d106e2018-10-18 09:53:19 +02001577 * @brief Load a schema into the specified context.
1578 *
1579 * @param[in] ctx libyang context where to process the data model.
1580 * @param[in] data The string containing the dumped data model in the specified
1581 * format.
1582 * @param[in] format Format of the input data (YANG or YIN).
1583 * @return Pointer to the data model structure or NULL on error.
1584 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001585struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001586
1587/**
1588 * @brief Read a schema from file descriptor into the specified context.
1589 *
1590 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
1591 *
1592 * @param[in] ctx libyang context where to process the data model.
1593 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
1594 * in the specified format.
1595 * @param[in] format Format of the input data (YANG or YIN).
1596 * @return Pointer to the data model structure or NULL on error.
1597 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001598struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001599
1600/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001601 * @brief Read a schema into the specified context from a file.
Radek Krejci86d106e2018-10-18 09:53:19 +02001602 *
1603 * @param[in] ctx libyang context where to process the data model.
1604 * @param[in] path Path to the file with the model in the specified format.
1605 * @param[in] format Format of the input data (YANG or YIN).
1606 * @return Pointer to the data model structure or NULL on error.
1607 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001608struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001609
1610/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001611 * @brief Search for the schema file in the specified searchpaths.
1612 *
1613 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
1614 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
1615 * result of the ly_ctx_get_searchdirs().
1616 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
1617 * @param[in] name Name of the schema to find.
1618 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
1619 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
1620 * complying the provided restriction is found, NULL is set.
1621 * @param[out] format Optional output variable containing expected format of the schema document according to the
1622 * file suffix.
1623 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
1624 */
1625LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
1626
1627/**
Radek Krejcia3045382018-11-22 14:30:31 +01001628 * @brief Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can
1629 * be from an augment.
1630 *
1631 * lys_getnext() is supposed to be called sequentially. In the first call, the \p last parameter is usually NULL
1632 * and function starts returning i) the first \p parent's child or ii) the first top level element of the \p module.
1633 * Consequent calls suppose to provide the previously returned node as the \p last parameter and still the same
1634 * \p parent and \p module parameters.
1635 *
1636 * Without options, the function is used to traverse only the schema nodes that can be paired with corresponding
1637 * data nodes in a data tree. By setting some \p options the behavior can be modified to the extent that
1638 * all the schema nodes are iteratively returned.
1639 *
1640 * @param[in] last Previously returned schema tree node, or NULL in case of the first call.
1641 * @param[in] parent Parent of the subtree where the function starts processing.
1642 * @param[in] module In case of iterating on top level elements, the \p parent is NULL and
1643 * module must be specified.
1644 * @param[in] options [ORed options](@ref sgetnextflags).
1645 * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
1646 */
1647const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
1648 const struct lysc_module *module, int options);
1649
1650/**
1651 * @defgroup sgetnextflags lys_getnext() flags
1652 * @ingroup schematree
1653 *
1654 * @{
1655 */
1656#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 +01001657#define LYS_GETNEXT_NOCHOICE 0x02 /**< lys_getnext() option to ignore (kind of conditional) nodes within choice node */
Radek Krejci056d0a82018-12-06 16:57:25 +01001658#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 +01001659#define LYS_GETNEXT_INTONPCONT 0x40 /**< lys_getnext() option to look into non-presence container, instead of returning container itself */
1660#define LYS_GETNEXT_NOSTATECHECK 0x100 /**< lys_getnext() option to skip checking module validity (import-only, disabled) and
1661 relevant if-feature conditions state */
1662/** @} sgetnextflags */
1663
1664/**
1665 * @brief Get child node according to the specified criteria.
1666 *
1667 * @param[in] parent Optional parent of the node to find. If not specified, the module's top-level nodes are searched.
1668 * @param[in] module module of the node to find. It is also limitation for the children node of the given parent.
1669 * @param[in] name Name of the node to find.
1670 * @param[in] name_len Optional length of the name in case it is not NULL-terminated string.
1671 * @param[in] nodetype Optional criteria (to speedup) specifying nodetype(s) of the node to find.
1672 * Used as a bitmask, so multiple nodetypes can be specified.
1673 * @param[in] options [ORed options](@ref sgetnextflags).
1674 * @return Found node if any.
1675 */
1676const struct lysc_node *lys_child(const struct lysc_node *parent, const struct lys_module *module,
1677 const char *name, size_t name_len, uint16_t nodetype, int options);
1678
1679/**
1680 * @brief Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statement
1681 * affecting the node.
1682 *
1683 * @param[in] node Schema node to check.
1684 * @param[in] recursive - 0 to check if-feature only in the \p node schema node,
1685 * - 1 to check if-feature in all ascendant schema nodes until there is a node possibly having an instance in a data tree
1686 * @return - NULL if enabled,
1687 * - pointer to the node with the unsatisfied (disabling) if-feature expression.
1688 */
1689const struct lysc_iffeature *lys_is_disabled(const struct lysc_node *node, int recursive);
1690
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001691/** @} */
1692
Radek Krejci70853c52018-10-15 14:46:16 +02001693#ifdef __cplusplus
1694}
1695#endif
1696
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001697#endif /* LY_TREE_SCHEMA_H_ */