blob: d6aa6c06d55114ad62683cdaed30471d9d7de297 [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 */
159#define LYS_CASE 0x0040 /**< case statement node */
160#define LYS_USES 0x0080 /**< uses statement node */
161#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 +0200162
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)) */
175 LY_TYPE_BITS, /**< A set of bits or flags ([RFC 6020 sec 9.7](http://tools.ietf.org/html/rfc6020#section-9.7)) */
176 LY_TYPE_BOOL, /**< "true" or "false" ([RFC 6020 sec 9.5](http://tools.ietf.org/html/rfc6020#section-9.5)) */
177 LY_TYPE_DEC64, /**< 64-bit signed decimal number ([RFC 6020 sec 9.3](http://tools.ietf.org/html/rfc6020#section-9.3))*/
178 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)) */
179 LY_TYPE_ENUM, /**< Enumerated strings ([RFC 6020 sec 9.6](http://tools.ietf.org/html/rfc6020#section-9.6)) */
180 LY_TYPE_IDENT, /**< A reference to an abstract identity ([RFC 6020 sec 9.10](http://tools.ietf.org/html/rfc6020#section-9.10)) */
181 LY_TYPE_INST, /**< References a data tree node ([RFC 6020 sec 9.13](http://tools.ietf.org/html/rfc6020#section-9.13)) */
182 LY_TYPE_LEAFREF, /**< A reference to a leaf instance ([RFC 6020 sec 9.9](http://tools.ietf.org/html/rfc6020#section-9.9))*/
183 LY_TYPE_STRING, /**< Human-readable string ([RFC 6020 sec 9.4](http://tools.ietf.org/html/rfc6020#section-9.4)) */
184 LY_TYPE_UNION, /**< Choice of member types ([RFC 6020 sec 9.12](http://tools.ietf.org/html/rfc6020#section-9.12)) */
185 LY_TYPE_INT8, /**< 8-bit signed integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
186 LY_TYPE_UINT8, /**< 8-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
187 LY_TYPE_INT16, /**< 16-bit signed integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
188 LY_TYPE_UINT16, /**< 16-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
189 LY_TYPE_INT32, /**< 32-bit signed integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
190 LY_TYPE_UINT32, /**< 32-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
191 LY_TYPE_INT64, /**< 64-bit signed integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
192 LY_TYPE_UINT64, /**< 64-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
193} LY_DATA_TYPE;
194#define LY_DATA_TYPE_COUNT 20 /**< Number of different types */
195
196/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200197 * @brief YANG import-stmt
198 */
199struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200200 struct lys_module *module; /**< pointer to the imported module
201 (mandatory, but resolved when the referring module is completely parsed) */
202 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200203 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200204 const char *dsc; /**< description */
205 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200206 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200207 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
208};
209
210/**
211 * @brief YANG include-stmt
212 */
213struct lysp_include {
Radek Krejci086c7132018-10-26 15:29:04 +0200214 struct lysp_module *submodule; /**< pointer to the parsed submodule structure
215 (mandatory, but resolved when the referring module is completely parsed) */
216 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200217 const char *dsc; /**< description */
218 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200219 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200220 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
221};
222
223/**
224 * @brief YANG extension-stmt
225 */
226struct lysp_ext {
227 const char *name; /**< extension name */
228 const char *argument; /**< argument name, NULL if not specified */
229 const char *dsc; /**< description statement */
230 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200231 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200232 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
233};
234
235/**
236 * @brief Helper structure for generic storage of the extension instances content.
237 */
238struct lysp_stmt {
239 const char *stmt; /**< identifier of the statement */
240 const char *arg; /**< statement's argument */
241 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200242 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200243};
244
245/**
246 * @brief YANG extension instance
247 */
248struct lysp_ext_instance {
249 const char *name; /**< extension identifier, including possible prefix */
250 const char *argument; /**< optional value of the extension's argument */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200251 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
252 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
253 the index of that substatement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200254 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200255};
256
257/**
258 * @brief YANG feature-stmt
259 */
260struct lysp_feature {
261 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200262 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200263 const char *dsc; /**< description statement */
264 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200265 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200266 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
267};
268
269/**
270 * @brief YANG identity-stmt
271 */
272struct lysp_ident {
273 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200274 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
275 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200276 const char *dsc; /**< description statement */
277 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200278 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200279 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
280};
281
Michal Vasko71e64ca2018-09-07 16:30:29 +0200282/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200283 * @brief Covers restrictions: range, length, pattern, must
284 */
285struct lysp_restr {
286 const char *arg; /**< The restriction expression/value (mandatory);
287 in case of pattern restriction, the first byte has a special meaning:
288 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
289 const char *emsg; /**< error-message */
290 const char *eapptag; /**< error-app-tag value */
291 const char *dsc; /**< description */
292 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200293 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200294};
295
296/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200297 * @brief YANG revision-stmt
298 */
299struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200300 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200301 const char *dsc; /**< description statement */
302 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200303 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200304};
305
306/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200307 * @brief Enumeration/Bit value definition
308 */
309struct lysp_type_enum {
310 const char *name; /**< name (mandatory) */
311 const char *dsc; /**< description statement */
312 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200313 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200314 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200315 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200316 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
317 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200318};
319
320/**
321 * @brief YANG type-stmt
322 *
323 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
324 */
325struct lysp_type {
326 const char *name; /**< name of the type (mandatory) */
327 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
328 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200329 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
330 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
331 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200332 const char *path; /**< path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200333 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200334 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
335 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200336
Radek Krejci2167ee12018-11-02 16:09:07 +0100337 struct lysc_type *compiled; /**< pointer to the compiled type */
338
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200339 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
340 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200341 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_SET_REQINST allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200342};
343
344/**
345 * @brief YANG typedef-stmt
346 */
347struct lysp_tpdf {
348 const char *name; /**< name of the newly defined type (mandatory) */
349 const char *units; /**< units of the newly defined type */
350 const char *dflt; /**< default value of the newly defined type */
351 const char *dsc; /**< description statement */
352 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200353 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200354 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
355 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
356};
357
358/**
359 * @brief YANG grouping-stmt
360 */
361struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100362 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
363 uint16_t nodetype; /**< LYS_GROUPING */
364 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200365 const char *name; /**< grouping name (mandatory) */
366 const char *dsc; /**< description statement */
367 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200368 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
369 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200370 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200371 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
372 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
373 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200374};
375
376/**
377 * @brief YANG when-stmt
378 */
379struct lysp_when {
380 const char *cond; /**< specified condition (mandatory) */
381 const char *dsc; /**< description statement */
382 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200383 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200384};
385
386/**
387 * @brief YANG refine-stmt
388 */
389struct lysp_refine {
390 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
391 const char *dsc; /**< description statement */
392 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200393 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200394 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200395 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200396 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200397 uint32_t min; /**< min-elements constraint */
398 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200399 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200400 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
401};
402
403/**
404 * @brief YANG uses-augment-stmt and augment-stmt
405 */
406struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100407 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
408 uint16_t nodetype; /**< LYS_AUGMENT */
409 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200410 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
411 const char *dsc; /**< description statement */
412 const char *ref; /**< reference statement */
413 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200414 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200415 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200416 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
417 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
418 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200419};
420
421/**
422 * @defgroup deviatetypes Deviate types
423 * @{
424 */
425#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
426#define LYS_DEV_ADD 2 /**< deviate type add */
427#define LYS_DEV_DELETE 3 /**< deviate type delete */
428#define LYS_DEV_REPLACE 4 /**< deviate type replace */
429/** @} */
430
431/**
432 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
433 */
434struct lysp_deviate {
435 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
436 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200437 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200438};
439
440struct lysp_deviate_add {
441 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
442 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200443 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200444 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200445 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200446 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
447 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200448 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
449 uint32_t min; /**< min-elements constraint */
450 uint32_t max; /**< max-elements constraint, 0 means unbounded */
451};
452
453struct lysp_deviate_del {
454 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
455 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200456 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200457 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200458 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200459 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
460 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200461 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200462};
463
464struct lysp_deviate_rpl {
465 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
466 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200467 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200468 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200469 const char *units; /**< units of the values */
470 const char *dflt; /**< default value */
471 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
472 uint32_t min; /**< min-elements constraint */
473 uint32_t max; /**< max-elements constraint, 0 means unbounded */
474};
475
476struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200477 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200478 const char *dsc; /**< description statement */
479 const char *ref; /**< reference statement */
480 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200481 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200482};
483
Michal Vaskob55f6c12018-09-12 11:13:15 +0200484#define LYS_CONFIG_W 0x01 /**< config true; */
485#define LYS_CONFIG_R 0x02 /**< config false; */
486#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
487#define LYS_STATUS_CURR 0x08 /**< status current; */
488#define LYS_STATUS_DEPRC 0x10 /**< status deprecated; */
489#define LYS_STATUS_OBSLT 0x20 /**< status obsolete; */
490#define LYS_STATUS_MASK 0x38 /**< mask for status value */
491#define LYS_MAND_TRUE 0x40 /**< mandatory true; applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200492 ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf
493 and ::lysp_node_anydata/::lysc_node_anydata */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200494#define LYS_MAND_FALSE 0x80 /**< mandatory false; applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200495 ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf
496 and ::lysp_node_anydata/::lysc_node_anydata */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200497#define LYS_MAND_MASK 0xc0 /**< mask for mandatory values */
498#define LYS_ORDBY_SYSTEM 0x100 /**< ordered-by system lists, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200499 ::lysp_node_list/lysc_node_list and ::lysp_node_leaflist/::lysc_node_list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200500#define LYS_ORDBY_USER 0x200 /**< ordered-by user lists, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200501 ::lysp_node_list/lysc_node_list and ::lysp_node_leaflist/::lysc_node_list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200502#define LYS_ORDBY_MASK 0x300 /**< mask for ordered-by flags */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200503#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysp_feature/::lysc_feature */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200504#define LYS_AUTOASSIGNED 0x01 /**< value was auto-assigned, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200505 ::lysp_type/::lysc_type enum and bits flags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200506#define LYS_YINELEM_TRUE 0x01 /**< yin-element true for extension's argument */
507#define LYS_YINELEM_FALSE 0x02 /**< yin-element false for extension's argument */
508#define LYS_YINELEM_MASK 0x03 /**< mask for yin-element value */
509#define LYS_SET_VALUE 0x01 /**< value attribute is set */
510#define LYS_SET_MAX 0x400 /**< max attribute is set */
511#define LYS_SET_MIN 0x800 /**< min attribute is set */
512#define LYS_SET_REQINST 0x01 /**< require_instance attribute is set */
513
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200514/**
515 * @brief Generic YANG data node
516 */
517struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100518 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200519 uint16_t nodetype; /**< type of the node (mandatory) */
520 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100521 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200522 const char *name; /**< node name (mandatory) */
523 const char *dsc; /**< description statement */
524 const char *ref; /**< reference statement */
525 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200526 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200527 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200528};
529
530/**
531 * @brief Extension structure of the lysp_node for YANG container
532 */
533struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100534 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200535 uint16_t nodetype; /**< LYS_CONTAINER */
536 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
537 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
538 const char *name; /**< node name (mandatory) */
539 const char *dsc; /**< description statement */
540 const char *ref; /**< reference statement */
541 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200542 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200543 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200544
545 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200546 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200547 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200548 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
549 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200550 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200551 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
552 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200553};
554
555struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100556 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200557 uint16_t nodetype; /**< LYS_LEAF */
558 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
559 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
560 const char *name; /**< node name (mandatory) */
561 const char *dsc; /**< description statement */
562 const char *ref; /**< reference statement */
563 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200564 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200565 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200566
567 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200568 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200569 struct lysp_type type; /**< type of the leaf node (mandatory) */
570 const char *units; /**< units of the leaf's type */
571 const char *dflt; /**< default value */
572};
573
574struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100575 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200576 uint16_t nodetype; /**< LYS_LEAFLIST */
577 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
578 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
579 const char *name; /**< node name (mandatory) */
580 const char *dsc; /**< description statement */
581 const char *ref; /**< reference statement */
582 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200583 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200584 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200585
586 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200587 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200588 struct lysp_type type; /**< type of the leaf node (mandatory) */
589 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200590 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200591 uint32_t min; /**< min-elements constraint */
592 uint32_t max; /**< max-elements constraint, 0 means unbounded */
593};
594
595struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100596 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200597 uint16_t nodetype; /**< LYS_LIST */
598 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
599 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
600 const char *name; /**< node name (mandatory) */
601 const char *dsc; /**< description statement */
602 const char *ref; /**< reference statement */
603 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200604 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200605 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200606
607 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200608 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200609 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200610 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
611 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200612 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200613 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
614 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200615 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200616 uint32_t min; /**< min-elements constraint */
617 uint32_t max; /**< max-elements constraint, 0 means unbounded */
618};
619
620struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100621 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200622 uint16_t nodetype; /**< LYS_CHOICE */
623 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
624 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
625 const char *name; /**< node name (mandatory) */
626 const char *dsc; /**< description statement */
627 const char *ref; /**< reference statement */
628 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200629 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200630 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200631
632 /* choice */
633 struct lysp_node *child; /**< list of data nodes (linked list) */
634 const char* dflt; /**< default case */
635};
636
637struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100638 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200639 uint16_t nodetype; /**< LYS_CASE */
640 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
641 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
642 const char *name; /**< node name (mandatory) */
643 const char *dsc; /**< description statement */
644 const char *ref; /**< reference statement */
645 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200646 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200647 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200648
649 /* case */
650 struct lysp_node *child; /**< list of data nodes (linked list) */
651};
652
653struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100654 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200655 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
656 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
657 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
658 const char *name; /**< node name (mandatory) */
659 const char *dsc; /**< description statement */
660 const char *ref; /**< reference statement */
661 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200662 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200663 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200664
665 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200666 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200667};
668
669struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100670 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200671 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200672 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
673 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
674 const char *name; /**< grouping name reference (mandatory) */
675 const char *dsc; /**< description statement */
676 const char *ref; /**< reference statement */
677 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200678 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200679 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200680
681 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200682 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
683 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200684};
685
686/**
687 * @brief YANG input-stmt and output-stmt
688 */
689struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100690 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
691 uint16_t nodetype; /**< LYS_INOUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200692 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
693 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
694 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200695 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200696 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200697};
698
699/**
700 * @brief YANG rpc-stmt and action-stmt
701 */
702struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100703 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
704 uint16_t nodetype; /**< LYS_ACTION */
705 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200706 const char *name; /**< grouping name reference (mandatory) */
707 const char *dsc; /**< description statement */
708 const char *ref; /**< reference 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_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
711 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200712 struct lysp_action_inout *input; /**< RPC's/Action's input */
713 struct lysp_action_inout *output;/**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200714 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200715};
716
717/**
718 * @brief YANG notification-stmt
719 */
720struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100721 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
722 uint16_t nodetype; /**< LYS_NOTIF */
723 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200724 const char *name; /**< grouping name reference (mandatory) */
725 const char *dsc; /**< description statement */
726 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200727 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200728 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
729 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
730 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200731 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200732 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200733};
734
735/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200736 * @brief supported YANG schema version values
737 */
738typedef enum LYS_VERSION {
739 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
740 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
741 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
742} LYS_VERSION;
743
744/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200745 * @brief Printable YANG schema tree structure representing YANG module.
746 *
747 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
748 */
749struct lysp_module {
750 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
751 const char *name; /**< name of the module (mandatory) */
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100752 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200753 union {
754 /* module */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200755 const char *ns; /**< namespace of the module (module - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200756 /* submodule */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200757 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200758 };
Michal Vaskod5927ca2018-09-07 15:05:32 +0200759 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
Radek Krejcib7db73a2018-10-24 14:18:40 +0200760 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
761 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200762 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
763 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200764 const char *org; /**< party/company responsible for the module */
765 const char *contact; /**< contact information for the module */
766 const char *dsc; /**< description of the module */
767 const char *ref; /**< cross-reference for the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200768 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
769 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
770 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
771 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
772 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200773 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200774 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
775 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
776 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
777 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
778 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200779
Radek Krejcif0fceb62018-09-05 14:58:45 +0200780 uint8_t submodule:1; /**< flag to distinguish main modules and submodules */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200781 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
Radek Krejci086c7132018-10-26 15:29:04 +0200782 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
783 1 - the latest revision in searchdirs was not searched yet and this is the
784 latest revision in the current context
785 2 - searchdirs were searched and this is the latest available revision */
786 uint8_t parsing:1; /**< flag for circular check */
787 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200788};
789
790/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200791 * @brief Free the printable YANG schema tree structure.
792 *
793 * @param[in] module Printable YANG schema tree structure to free.
794 */
795void lysp_module_free(struct lysp_module *module);
796
797/**
Radek Krejcice8c1592018-10-29 15:35:51 +0100798 * @brief YANG extension instance
799 */
800struct lysc_ext_instance {
801 struct lyext_plugin *plugin; /**< pointer to the plugin implementing the extension (if present) */
802 void *parent; /**< pointer to the parent element holding the extension instance(s), use
803 ::lysc_ext_instance#parent_type to access the schema element */
804 const char *argument; /**< optional value of the extension's argument */
805 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
806 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
807 this identifies the index of the substatement for this extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +0100808 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejcice8c1592018-10-29 15:35:51 +0100809#if 0
Radek Krejcice8c1592018-10-29 15:35:51 +0100810 uint8_t ext_type; /**< extension type (#LYEXT_TYPE) */
811 uint8_t padding; /**< 32b padding */
Radek Krejcice8c1592018-10-29 15:35:51 +0100812 struct lys_module *module; /**< pointer to the extension instance's module (mandatory) */
813 LYS_NODE nodetype; /**< LYS_EXT */
814#endif
Radek Krejci2a408df2018-10-29 16:32:26 +0100815 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
816 void *priv; /**< private caller's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +0100817};
818
819/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +0100820 * @brief Compiled YANG if-feature-stmt
821 */
822struct lysc_iffeature {
823 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
824 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
825};
826
827/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200828 * @brief YANG import-stmt
829 */
830struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100831 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +0200832 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejcice8c1592018-10-29 15:35:51 +0100833 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200834};
835
836/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200837 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200838 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200839struct lysc_when {
840 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200841 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200842};
843
844/**
Radek Krejci2a408df2018-10-29 16:32:26 +0100845 * @brief YANG identity-stmt
846 */
847struct lysc_ident {
848 const char *name; /**< identity name (mandatory), including possible prefix */
849 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
850 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
851 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
852 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
853};
854
855/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200856 * @brief YANG feature-stmt
857 */
858struct lysc_feature {
859 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200860 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 +0200861 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +0100862 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200863 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
864 #LYS_FENABLED values allowed */
865};
866
Radek Krejci151a5b72018-10-19 14:21:44 +0200867/**
868 * @defgroup ifftokens if-feature expression tokens
869 * Tokens of if-feature expression used in ::lysc_iffeature#expr
870 *
871 * @{
872 */
873#define LYS_IFF_NOT 0x00 /**< operand "not" */
874#define LYS_IFF_AND 0x01 /**< operand "and" */
875#define LYS_IFF_OR 0x02 /**< operand "or" */
876#define LYS_IFF_F 0x03 /**< feature */
877/**
878 * @}
879 */
880
881/**
Radek Krejcib7db73a2018-10-24 14:18:40 +0200882 * @brief Compiled YANG revision statement
883 */
884struct lysc_revision {
885 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
886 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
887};
888
Radek Krejci2167ee12018-11-02 16:09:07 +0100889struct lysc_default {
890 struct lys_module *module; /**< module where the default was defined */
891 const char *value; /**< default value (with possible prefixes from the module where defined) */
892};
893
894struct lysc_range {
895 struct {
896 union { /**< min boundary TODO decimal */
897 int64_t min_64; /**< for int8, int16, int32 and int64 */
898 uint64_t min_u64; /**< for uint8, uint16, uint32 and uint64 */
899 };
900 union { /**< max boundary TODO decimal */
901 int64_t max_64; /**< for int8, int16, int32 and int64 */
902 uint64_t max_u64; /**< for uint8, uint16, uint32 and uint64 */
903 };
904 } *parts; /**< compiled range expression */
905 const char *emsg; /**< error-message */
906 const char *eapptag; /**< error-app-tag value */
907 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
908};
909
910struct lysc_pattern {
911 pcre *expr; /**< compiled regular expression */
912 pcre_extra *expr_extra; /**< additional information to speed up matching */
913 const char *emsg; /**< error-message */
914 const char *eapptag; /**< error-app-tag value */
915 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
916 uint8_t inverted; /**< invert-match flag */
917};
918
919struct lysc_must {
920 struct lys_module *module; /**< module where the must was defined */
921 struct lyxp_expr *cond; /**< XPath when condition */
922 const char *emsg; /**< error-message */
923 const char *eapptag; /**< error-app-tag value */
924 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
925};
926
927struct lysc_type {
928 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
929 LY_DATA_TYPE basetype; /**< Base type of the type */
930 uint32_t refcount; /**< reference counter for type sharing */
931};
932
933struct lysc_type_num {
934 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
935 LY_DATA_TYPE basetype; /**< Base type of the type */
936 uint32_t refcount; /**< reference counter for type sharing */
937 struct lysc_range *range; /**< Optional range limitation */
938};
939
940struct lysc_type_dec {
941 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
942 LY_DATA_TYPE basetype; /**< Base type of the type */
943 uint32_t refcount; /**< reference counter for type sharing */
944 uint64_t fraction_digits:1; /**< fraction digits specification */
945 uint64_t div:63; /**< value for moving decimal point (dividing the stored value to get the real value) */
946 struct lysc_range *range; /**< Optional range limitation */
947};
948
949struct lysc_type_str {
950 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
951 LY_DATA_TYPE basetype; /**< Base type of the type */
952 uint32_t refcount; /**< reference counter for type sharing */
953 struct lysc_range *length; /**< Optional length limitation */
954 struct lysc_pattern *patterns; /**< Optional list of pattern limitations ([sized array](@ref sizedarrays)) */
955};
956
957struct lysc_type_enum {
958 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
959 LY_DATA_TYPE basetype; /**< Base type of the type */
960 uint32_t refcount; /**< reference counter for type sharing */
961 struct {
962 const char *name; /**< enumeration identifier */
963 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
964 int32_t value; /**< integer value associated with the enumeration */
965 } *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
966};
967
968struct lysc_type_leafref {
969 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
970 LY_DATA_TYPE basetype; /**< Base type of the type */
971 uint32_t refcount; /**< reference counter for type sharing */
972 struct lysc_node* target; /**< Target schema node */
973 uint8_t require_instance; /**< require-instance flag */
974};
975
976struct lysc_type_identityref {
977 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
978 LY_DATA_TYPE basetype; /**< Base type of the type */
979 uint32_t refcount; /**< reference counter for type sharing */
980 struct lysc_ident **base; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
981 mandatory (at least 1 item) */
982};
983
984struct lysc_type_instanceid {
985 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
986 LY_DATA_TYPE basetype; /**< Base type of the type */
987 uint32_t refcount; /**< reference counter for type sharing */
988 uint8_t require_instance; /**< require-instance flag */
989};
990
991struct lysc_type_bits {
992 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
993 LY_DATA_TYPE basetype; /**< Base type of the type */
994 uint32_t refcount; /**< reference counter for type sharing */
995 struct {
996 const char *name; /**< bit identifier */
997 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
998 uint32_t position; /**< non-negative integer value associated with the bit */
999 } *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1000};
1001
1002struct lysc_type_union {
1003 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1004 LY_DATA_TYPE basetype; /**< Base type of the type */
1005 uint32_t refcount; /**< reference counter for type sharing */
1006 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1007};
1008
1009struct lysc_type_bin {
1010 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1011 LY_DATA_TYPE basetype; /**< Base type of the type */
1012 uint32_t refcount; /**< reference counter for type sharing */
1013 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001014};
1015
1016/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001017 * @brief Compiled YANG data node
1018 */
1019struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001020 uint16_t nodetype; /**< type of the node (mandatory) */
1021 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001022 struct lys_module *module; /**< module structure */
1023 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. */
1024 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1025 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1026 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1027 never NULL. If there is no sibling node, pointer points to the node
1028 itself. In case of the first node, this pointer points to the last
1029 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001030 const char *name; /**< node name (mandatory) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001031 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001032};
1033
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001034struct lysc_node_container {
1035 uint16_t nodetype; /**< LYS_CONTAINER */
1036 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1037 struct lys_module *module; /**< module structure */
1038 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. */
1039 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1040 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1041 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1042 never NULL. If there is no sibling node, pointer points to the node
1043 itself. In case of the first node, this pointer points to the last
1044 node in the list. */
1045 const char *name; /**< node name (mandatory) */
1046 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1047
1048 struct lysc_node *child;
1049};
1050
1051struct lysc_node_choice {
1052 uint16_t nodetype; /**< LYS_CHOICE */
1053 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1054 struct lys_module *module; /**< module structure */
1055 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. */
1056 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1057 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1058 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1059 never NULL. If there is no sibling node, pointer points to the node
1060 itself. In case of the first node, this pointer points to the last
1061 node in the list. */
1062 const char *name; /**< node name (mandatory) */
1063 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1064
1065 struct lysc_node *child;
1066};
1067
1068struct lysc_node_leaf {
1069 uint16_t nodetype; /**< LYS_LEAF */
1070 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1071 struct lys_module *module; /**< module structure */
1072 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. */
1073 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1074 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1075 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1076 never NULL. If there is no sibling node, pointer points to the node
1077 itself. In case of the first node, this pointer points to the last
1078 node in the list. */
1079 const char *name; /**< node name (mandatory) */
1080 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1081
1082};
1083
1084struct lysc_node_leaflist {
1085 uint16_t nodetype; /**< LYS_LEAFLIST */
1086 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1087 struct lys_module *module; /**< module structure */
1088 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. */
1089 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1090 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1091 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1092 never NULL. If there is no sibling node, pointer points to the node
1093 itself. In case of the first node, this pointer points to the last
1094 node in the list. */
1095 const char *name; /**< node name (mandatory) */
1096 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1097
1098};
1099
1100struct lysc_node_list {
1101 uint16_t nodetype; /**< LYS_LIST */
1102 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1103 struct lys_module *module; /**< module structure */
1104 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. */
1105 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1106 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1107 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1108 never NULL. If there is no sibling node, pointer points to the node
1109 itself. In case of the first node, this pointer points to the last
1110 node in the list. */
1111 const char *name; /**< node name (mandatory) */
1112 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1113
1114 struct lysc_node *child;
1115};
1116
1117struct lysc_node_anydata {
1118 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1119 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1120 struct lys_module *module; /**< module structure */
1121 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. */
1122 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1123 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1124 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1125 never NULL. If there is no sibling node, pointer points to the node
1126 itself. In case of the first node, this pointer points to the last
1127 node in the list. */
1128 const char *name; /**< node name (mandatory) */
1129 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1130
1131};
1132
1133struct lysc_node_case {
1134 uint16_t nodetype; /**< LYS_CASE */
1135 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1136 struct lys_module *module; /**< module structure */
1137 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. */
1138 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1139 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1140 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1141 never NULL. If there is no sibling node, pointer points to the node
1142 itself. In case of the first node, this pointer points to the last
1143 node in the list. */
1144 const char *name; /**< node name (mandatory) */
1145 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1146
1147 struct lysc_node *child;
1148};
1149
1150struct lysc_node_uses {
1151 uint16_t nodetype; /**< LYS_CHOICE */
1152 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1153 struct lys_module *module; /**< module structure */
1154 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. */
1155 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1156 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1157 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1158 never NULL. If there is no sibling node, pointer points to the node
1159 itself. In case of the first node, this pointer points to the last
1160 node in the list. */
1161 const char *name; /**< node name (mandatory) */
1162 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1163
1164 struct lysc_node *child;
1165};
1166
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001167/**
1168 * @brief Compiled YANG schema tree structure representing YANG module.
1169 *
1170 * Semantically validated YANG schema tree for data tree parsing.
1171 * Contains only the necessary information for the data validation.
1172 */
1173struct lysc_module {
1174 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
1175 const char *name; /**< name of the module (mandatory) */
Radek Krejci6d6e4e42018-10-29 13:28:19 +01001176 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001177 const char *ns; /**< namespace of the module (mandatory) */
1178 const char *prefix; /**< module prefix (mandatory) */
Radek Krejcif8f882a2018-10-31 14:51:15 +01001179 const char *revision; /**< the revision of the module */
Radek Krejci151a5b72018-10-19 14:21:44 +02001180 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001181
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001182 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001183 struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1184 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1185 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1186 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001187 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001188
1189 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
Radek Krejcifaa1eac2018-10-30 14:34:55 +01001190 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
1191 1 - the latest revision in searchdirs was not searched yet and this is the
1192 latest revision in the current context
1193 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci086c7132018-10-26 15:29:04 +02001194 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001195};
1196
1197/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001198 * @brief Get how the if-feature statement currently evaluates.
1199 *
1200 * @param[in] iff Compiled if-feature statement to evaluate.
1201 * @return If the statement evaluates to true, 1 is returned. 0 is returned when the statement evaluates to false.
1202 */
1203int lysc_iffeature_value(const struct lysc_iffeature *iff);
1204
1205/**
1206 * @brief Get the current status of the provided feature.
1207 *
1208 * @param[in] feature Compiled feature statement to examine.
1209 * @return
1210 * - 1 if feature is enabled,
1211 * - 0 if feature is disabled,
1212 * - -1 in case of error (invalid argument)
1213 */
1214int lysc_feature_value(const struct lysc_feature *feature);
1215
1216/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001217 * @brief Available YANG schema tree structures representing YANG module.
1218 */
1219struct lys_module {
1220 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
1221 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing */
1222};
1223
Radek Krejci151a5b72018-10-19 14:21:44 +02001224/**
1225 * @brief Enable specified feature in the module
1226 *
1227 * By default, when the module is loaded by libyang parser, all features are disabled.
1228 *
Radek Krejcica3db002018-11-01 10:31:01 +01001229 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
1230 * enabling all features on the following feature set will fail since it is not possible to enable both features
1231 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
1232 * is untouched.
1233 *
1234 * feature f1;
1235 * feature f2 { if-feature 'not f1';}
1236 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001237 * @param[in] module Module where the feature will be enabled.
1238 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
1239 * @return LY_ERR value.
1240 */
1241LY_ERR lys_feature_enable(struct lys_module *module, const char *feature);
1242
1243/**
1244 * @brief Disable specified feature in the module
1245 *
1246 * By default, when the module is loaded by libyang parser, all features are disabled.
1247 *
1248 * @param[in] module Module where the feature will be disabled.
1249 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
1250 * @return LY_ERR value
1251 */
1252LY_ERR lys_feature_disable(struct lys_module *module, const char *feature);
1253
1254/**
1255 * @brief Get the current status of the specified feature in the module.
1256 *
1257 * @param[in] module Module where the feature is defined.
1258 * @param[in] feature Name of the feature to inspect.
1259 * @return
1260 * - 1 if feature is enabled,
1261 * - 0 if feature is disabled,
1262 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
1263 */
1264int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001265
1266/**
Radek Krejci86d106e2018-10-18 09:53:19 +02001267 * @brief Load a schema into the specified context.
1268 *
1269 * @param[in] ctx libyang context where to process the data model.
1270 * @param[in] data The string containing the dumped data model in the specified
1271 * format.
1272 * @param[in] format Format of the input data (YANG or YIN).
1273 * @return Pointer to the data model structure or NULL on error.
1274 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001275struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001276
1277/**
1278 * @brief Read a schema from file descriptor into the specified context.
1279 *
1280 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
1281 *
1282 * @param[in] ctx libyang context where to process the data model.
1283 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
1284 * in the specified format.
1285 * @param[in] format Format of the input data (YANG or YIN).
1286 * @return Pointer to the data model structure or NULL on error.
1287 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001288struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001289
1290/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001291 * @brief Read a schema into the specified context from a file.
Radek Krejci86d106e2018-10-18 09:53:19 +02001292 *
1293 * @param[in] ctx libyang context where to process the data model.
1294 * @param[in] path Path to the file with the model in the specified format.
1295 * @param[in] format Format of the input data (YANG or YIN).
1296 * @return Pointer to the data model structure or NULL on error.
1297 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001298struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001299
1300/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001301 * @brief Search for the schema file in the specified searchpaths.
1302 *
1303 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
1304 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
1305 * result of the ly_ctx_get_searchdirs().
1306 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
1307 * @param[in] name Name of the schema to find.
1308 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
1309 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
1310 * complying the provided restriction is found, NULL is set.
1311 * @param[out] format Optional output variable containing expected format of the schema document according to the
1312 * file suffix.
1313 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
1314 */
1315LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
1316
1317/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001318 * @defgroup scflags Schema compile flags
1319 * @ingroup schematree
1320 *
1321 * @{
1322 */
1323#define LYSC_OPT_FREE_SP 1 /**< Free the input printable schema */
1324
1325/**
1326 * @}
1327 */
1328
1329/**
1330 * @brief Compile printable schema into a validated schema linking all the references.
1331 *
Radek Krejcif8f882a2018-10-31 14:51:15 +01001332 * @param[in, out] mod Schema structure holding pointers to both schema structure types. The ::lys_module#parsed
1333 * member is used as input and ::lys_module#compiled is used to hold the result of the compilation.
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001334 * @param[in] options Various options to modify compiler behavior, see [compile flags](@ref scflags).
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001335 * @return LY_ERR value.
1336 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001337LY_ERR lys_compile(struct lys_module *mod, int options);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001338
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001339/** @} */
1340
Radek Krejci70853c52018-10-15 14:46:16 +02001341#ifdef __cplusplus
1342}
1343#endif
1344
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001345#endif /* LY_TREE_SCHEMA_H_ */