blob: 8971864edef759cc48c2bd5fe144db7f1ce7656f [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
18#include <stdint.h>
19
Radek Krejcice8c1592018-10-29 15:35:51 +010020#include "extensions.h"
21
Radek Krejci70853c52018-10-15 14:46:16 +020022#ifdef __cplusplus
23extern "C" {
24#endif
25
Radek Krejci5aeea3a2018-09-05 13:29:36 +020026/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +020027 * @brief XPath representation.
28 */
29struct lyxp_expr;
30
31/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020032 * @brief Macro selector for other LY_ARRAY_* macros, do not use directly!
33 */
34#define LY_ARRAY_SELECT(_1, _2, NAME, ...) NAME
35
36/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020037 * @brief Helper macro to go through sized-arrays with a pointer iterator.
38 *
39 * Use with opening curly bracket (`{`).
40 *
41 * @param[in] ARRAY Array to go through
42 * @param[in] TYPE Type of the records in the ARRAY
43 * @param[out] ITER Iterating pointer to the item being processed in each loop
44 */
45#define LY_ARRAY_FOR_ITER(ARRAY, TYPE, ITER) \
Radek Krejci2c4e7172018-10-19 15:56:26 +020046 for (ITER = ARRAY; \
47 (ARRAY) && ((void*)ITER - (void*)ARRAY)/(sizeof(TYPE)) < (*((uint32_t*)(ARRAY) - 1)); \
Radek Krejcie53a8dc2018-10-17 12:52:40 +020048 ITER = (void*)((TYPE*)ITER + 1))
49
50/**
51 * @brief Helper macro to go through sized-arrays with a numeric iterator.
52 *
53 * Use with opening curly bracket (`{`).
54 *
55 * To access an item with the INDEX value, use always LY_ARRAY_INDEX macro!
56 *
57 * @param[in] ARRAY Array to go through
58 * @param[out] INDEX Iterating index of the item being processed in each loop
59 */
60#define LY_ARRAY_FOR_INDEX(ARRAY, INDEX) \
61 for (INDEX = 0; \
Radek Krejci2c4e7172018-10-19 15:56:26 +020062 ARRAY && INDEX < (*((uint32_t*)(ARRAY) - 1)); \
Radek Krejcie53a8dc2018-10-17 12:52:40 +020063 ++INDEX)
64
65/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +020066 * @defgroup schematree Schema Tree
67 * @{
68 *
69 * Data structures and functions to manipulate and access schema tree.
70 */
71
Radek Krejci0af5f5d2018-09-07 15:00:30 +020072/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020073 * @brief Get a number of records in the ARRAY.
Radek Krejci86d106e2018-10-18 09:53:19 +020074 *
75 * Does not check if array exists!
Radek Krejcie53a8dc2018-10-17 12:52:40 +020076 */
Radek Krejci2c4e7172018-10-19 15:56:26 +020077#define LY_ARRAY_SIZE(ARRAY) (*((uint32_t*)(ARRAY) - 1))
Radek Krejcie53a8dc2018-10-17 12:52:40 +020078
79/**
80 * @brief Sized-array iterator (for-loop).
81 *
82 * Use with opening curly bracket (`{`).
83 *
84 * There are 2 variants:
85 *
86 * LY_ARRAY_FOR(ARRAY, TYPE, ITER)
87 *
88 * 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
89 * providing the items of the ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_ITER macro
90 *
91 * LY_ARRAY_FOR(ARRAY, INDEX)
92 *
93 * 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 +020094 * 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 +020095 */
96#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 +020097
98/**
99 * @brief Macro to iterate via all sibling elements without affecting the list itself
100 *
101 * Works for all types of nodes despite it is data or schema tree, but all the
102 * parameters must be pointers to the same type.
103 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200104 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200105 *
106 * @param START Pointer to the starting element.
107 * @param ELEM Iterator.
108 */
109#define LY_LIST_FOR(START, ELEM) \
110 for ((ELEM) = (START); \
111 (ELEM); \
112 (ELEM) = (ELEM)->next)
113
114/**
115 * @ingroup datatree
116 * @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
163/**
164 * @brief YANG import-stmt
165 */
166struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200167 struct lys_module *module; /**< pointer to the imported module
168 (mandatory, but resolved when the referring module is completely parsed) */
169 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200170 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200171 const char *dsc; /**< description */
172 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200173 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200174 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
175};
176
177/**
178 * @brief YANG include-stmt
179 */
180struct lysp_include {
Radek Krejci086c7132018-10-26 15:29:04 +0200181 struct lysp_module *submodule; /**< pointer to the parsed submodule structure
182 (mandatory, but resolved when the referring module is completely parsed) */
183 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200184 const char *dsc; /**< description */
185 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200186 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200187 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
188};
189
190/**
191 * @brief YANG extension-stmt
192 */
193struct lysp_ext {
194 const char *name; /**< extension name */
195 const char *argument; /**< argument name, NULL if not specified */
196 const char *dsc; /**< description statement */
197 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200198 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200199 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
200};
201
202/**
203 * @brief Helper structure for generic storage of the extension instances content.
204 */
205struct lysp_stmt {
206 const char *stmt; /**< identifier of the statement */
207 const char *arg; /**< statement's argument */
208 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200209 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200210};
211
212/**
213 * @brief YANG extension instance
214 */
215struct lysp_ext_instance {
216 const char *name; /**< extension identifier, including possible prefix */
217 const char *argument; /**< optional value of the extension's argument */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200218 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
219 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
220 the index of that substatement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200221 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200222};
223
224/**
225 * @brief YANG feature-stmt
226 */
227struct lysp_feature {
228 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200229 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200230 const char *dsc; /**< description statement */
231 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200232 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200233 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
234};
235
236/**
237 * @brief YANG identity-stmt
238 */
239struct lysp_ident {
240 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200241 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
242 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200243 const char *dsc; /**< description statement */
244 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200245 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200246 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
247};
248
Michal Vasko71e64ca2018-09-07 16:30:29 +0200249/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200250 * @brief Covers restrictions: range, length, pattern, must
251 */
252struct lysp_restr {
253 const char *arg; /**< The restriction expression/value (mandatory);
254 in case of pattern restriction, the first byte has a special meaning:
255 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
256 const char *emsg; /**< error-message */
257 const char *eapptag; /**< error-app-tag value */
258 const char *dsc; /**< description */
259 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200260 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200261};
262
263/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200264 * @brief YANG revision-stmt
265 */
266struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200267 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +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)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200271};
272
273/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200274 * @brief Enumeration/Bit value definition
275 */
276struct lysp_type_enum {
277 const char *name; /**< name (mandatory) */
278 const char *dsc; /**< description statement */
279 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200280 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200281 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200282 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200283 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
284 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200285};
286
287/**
288 * @brief YANG type-stmt
289 *
290 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
291 */
292struct lysp_type {
293 const char *name; /**< name of the type (mandatory) */
294 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
295 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200296 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
297 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
298 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200299 const char *path; /**< path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200300 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200301 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
302 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200303
304 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
305 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200306 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_SET_REQINST allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200307};
308
309/**
310 * @brief YANG typedef-stmt
311 */
312struct lysp_tpdf {
313 const char *name; /**< name of the newly defined type (mandatory) */
314 const char *units; /**< units of the newly defined type */
315 const char *dflt; /**< default value of the newly defined type */
316 const char *dsc; /**< description statement */
317 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200318 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200319 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
320 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
321};
322
323/**
324 * @brief YANG grouping-stmt
325 */
326struct lysp_grp {
327 const char *name; /**< grouping name (mandatory) */
328 const char *dsc; /**< description statement */
329 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200330 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
331 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200332 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200333 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
334 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
335 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200336 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
337};
338
339/**
340 * @brief YANG when-stmt
341 */
342struct lysp_when {
343 const char *cond; /**< specified condition (mandatory) */
344 const char *dsc; /**< description statement */
345 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200346 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200347};
348
349/**
350 * @brief YANG refine-stmt
351 */
352struct lysp_refine {
353 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
354 const char *dsc; /**< description statement */
355 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200356 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200357 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200358 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200359 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200360 uint32_t min; /**< min-elements constraint */
361 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200362 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200363 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
364};
365
366/**
367 * @brief YANG uses-augment-stmt and augment-stmt
368 */
369struct lysp_augment {
370 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
371 const char *dsc; /**< description statement */
372 const char *ref; /**< reference statement */
373 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200374 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200375 struct lysp_node *child; /**< 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 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
380};
381
382/**
383 * @defgroup deviatetypes Deviate types
384 * @{
385 */
386#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
387#define LYS_DEV_ADD 2 /**< deviate type add */
388#define LYS_DEV_DELETE 3 /**< deviate type delete */
389#define LYS_DEV_REPLACE 4 /**< deviate type replace */
390/** @} */
391
392/**
393 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
394 */
395struct lysp_deviate {
396 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
397 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200398 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200399};
400
401struct lysp_deviate_add {
402 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
403 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200404 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200405 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200406 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200407 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
408 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200409 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
410 uint32_t min; /**< min-elements constraint */
411 uint32_t max; /**< max-elements constraint, 0 means unbounded */
412};
413
414struct lysp_deviate_del {
415 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
416 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200417 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200418 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200419 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200420 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
421 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200422 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200423};
424
425struct lysp_deviate_rpl {
426 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
427 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200428 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200429 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200430 const char *units; /**< units of the values */
431 const char *dflt; /**< default value */
432 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
433 uint32_t min; /**< min-elements constraint */
434 uint32_t max; /**< max-elements constraint, 0 means unbounded */
435};
436
437struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200438 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200439 const char *dsc; /**< description statement */
440 const char *ref; /**< reference statement */
441 struct lysp_deviate* deviates; /**< list of deviate specifications (linked 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
Michal Vaskob55f6c12018-09-12 11:13:15 +0200445#define LYS_CONFIG_W 0x01 /**< config true; */
446#define LYS_CONFIG_R 0x02 /**< config false; */
447#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
448#define LYS_STATUS_CURR 0x08 /**< status current; */
449#define LYS_STATUS_DEPRC 0x10 /**< status deprecated; */
450#define LYS_STATUS_OBSLT 0x20 /**< status obsolete; */
451#define LYS_STATUS_MASK 0x38 /**< mask for status value */
452#define LYS_MAND_TRUE 0x40 /**< mandatory true; applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200453 ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf
454 and ::lysp_node_anydata/::lysc_node_anydata */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200455#define LYS_MAND_FALSE 0x80 /**< mandatory false; applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200456 ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf
457 and ::lysp_node_anydata/::lysc_node_anydata */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200458#define LYS_MAND_MASK 0xc0 /**< mask for mandatory values */
459#define LYS_ORDBY_SYSTEM 0x100 /**< ordered-by system lists, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200460 ::lysp_node_list/lysc_node_list and ::lysp_node_leaflist/::lysc_node_list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200461#define LYS_ORDBY_USER 0x200 /**< ordered-by user lists, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200462 ::lysp_node_list/lysc_node_list and ::lysp_node_leaflist/::lysc_node_list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200463#define LYS_ORDBY_MASK 0x300 /**< mask for ordered-by flags */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200464#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysp_feature/::lysc_feature */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200465#define LYS_AUTOASSIGNED 0x01 /**< value was auto-assigned, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200466 ::lysp_type/::lysc_type enum and bits flags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200467#define LYS_YINELEM_TRUE 0x01 /**< yin-element true for extension's argument */
468#define LYS_YINELEM_FALSE 0x02 /**< yin-element false for extension's argument */
469#define LYS_YINELEM_MASK 0x03 /**< mask for yin-element value */
470#define LYS_SET_VALUE 0x01 /**< value attribute is set */
471#define LYS_SET_MAX 0x400 /**< max attribute is set */
472#define LYS_SET_MIN 0x800 /**< min attribute is set */
473#define LYS_SET_REQINST 0x01 /**< require_instance attribute is set */
474
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200475/**
476 * @brief Generic YANG data node
477 */
478struct lysp_node {
479 uint16_t nodetype; /**< type of the node (mandatory) */
480 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
481 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
482 const char *name; /**< node name (mandatory) */
483 const char *dsc; /**< description statement */
484 const char *ref; /**< reference statement */
485 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200486 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200487 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200488};
489
490/**
491 * @brief Extension structure of the lysp_node for YANG container
492 */
493struct lysp_node_container {
494 uint16_t nodetype; /**< LYS_CONTAINER */
495 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
496 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
497 const char *name; /**< node name (mandatory) */
498 const char *dsc; /**< description statement */
499 const char *ref; /**< reference statement */
500 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200501 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200502 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200503
504 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200505 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200506 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200507 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
508 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200509 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200510 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
511 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200512};
513
514struct lysp_node_leaf {
515 uint16_t nodetype; /**< LYS_LEAF */
516 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
517 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
518 const char *name; /**< node name (mandatory) */
519 const char *dsc; /**< description statement */
520 const char *ref; /**< reference statement */
521 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200522 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200523 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200524
525 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200526 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200527 struct lysp_type type; /**< type of the leaf node (mandatory) */
528 const char *units; /**< units of the leaf's type */
529 const char *dflt; /**< default value */
530};
531
532struct lysp_node_leaflist {
533 uint16_t nodetype; /**< LYS_LEAFLIST */
534 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
535 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
536 const char *name; /**< node name (mandatory) */
537 const char *dsc; /**< description statement */
538 const char *ref; /**< reference statement */
539 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200540 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200541 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200542
543 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200544 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200545 struct lysp_type type; /**< type of the leaf node (mandatory) */
546 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200547 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200548 uint32_t min; /**< min-elements constraint */
549 uint32_t max; /**< max-elements constraint, 0 means unbounded */
550};
551
552struct lysp_node_list {
553 uint16_t nodetype; /**< LYS_LIST */
554 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
555 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
556 const char *name; /**< node name (mandatory) */
557 const char *dsc; /**< description statement */
558 const char *ref; /**< reference statement */
559 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200560 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200561 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200562
563 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200564 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200565 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200566 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
567 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200568 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200569 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
570 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200571 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200572 uint32_t min; /**< min-elements constraint */
573 uint32_t max; /**< max-elements constraint, 0 means unbounded */
574};
575
576struct lysp_node_choice {
577 uint16_t nodetype; /**< LYS_CHOICE */
578 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
579 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
580 const char *name; /**< node name (mandatory) */
581 const char *dsc; /**< description statement */
582 const char *ref; /**< reference statement */
583 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200584 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200585 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200586
587 /* choice */
588 struct lysp_node *child; /**< list of data nodes (linked list) */
589 const char* dflt; /**< default case */
590};
591
592struct lysp_node_case {
593 uint16_t nodetype; /**< LYS_CASE */
594 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
595 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
596 const char *name; /**< node name (mandatory) */
597 const char *dsc; /**< description statement */
598 const char *ref; /**< reference statement */
599 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200600 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200601 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200602
603 /* case */
604 struct lysp_node *child; /**< list of data nodes (linked list) */
605};
606
607struct lysp_node_anydata {
608 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
609 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
610 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
611 const char *name; /**< node name (mandatory) */
612 const char *dsc; /**< description statement */
613 const char *ref; /**< reference statement */
614 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200615 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200616 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200617
618 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200619 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200620};
621
622struct lysp_node_uses {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200623 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200624 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
625 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
626 const char *name; /**< grouping name reference (mandatory) */
627 const char *dsc; /**< description statement */
628 const char *ref; /**< reference statement */
629 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200630 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200631 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200632
633 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200634 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
635 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200636};
637
638/**
639 * @brief YANG input-stmt and output-stmt
640 */
641struct lysp_action_inout {
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200642 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
643 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
644 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200645 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200646 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200647};
648
649/**
650 * @brief YANG rpc-stmt and action-stmt
651 */
652struct lysp_action {
653 const char *name; /**< grouping name reference (mandatory) */
654 const char *dsc; /**< description statement */
655 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200656 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200657 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
658 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200659 struct lysp_action_inout *input; /**< RPC's/Action's input */
660 struct lysp_action_inout *output;/**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200661 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200662 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
663};
664
665/**
666 * @brief YANG notification-stmt
667 */
668struct lysp_notif {
669 const char *name; /**< grouping name reference (mandatory) */
670 const char *dsc; /**< description statement */
671 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200672 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200673 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
674 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 *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200677 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200678 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
679};
680
681/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200682 * @brief supported YANG schema version values
683 */
684typedef enum LYS_VERSION {
685 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
686 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
687 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
688} LYS_VERSION;
689
690/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200691 * @brief Printable YANG schema tree structure representing YANG module.
692 *
693 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
694 */
695struct lysp_module {
696 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
697 const char *name; /**< name of the module (mandatory) */
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100698 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 +0200699 union {
700 /* module */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200701 const char *ns; /**< namespace of the module (module - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200702 /* submodule */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200703 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200704 };
Michal Vaskod5927ca2018-09-07 15:05:32 +0200705 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
Radek Krejcib7db73a2018-10-24 14:18:40 +0200706 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
707 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200708 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
709 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200710 const char *org; /**< party/company responsible for the module */
711 const char *contact; /**< contact information for the module */
712 const char *dsc; /**< description of the module */
713 const char *ref; /**< cross-reference for the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200714 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
715 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
716 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
717 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
718 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200719 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200720 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
721 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
722 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
723 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
724 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200725
Radek Krejcif0fceb62018-09-05 14:58:45 +0200726 uint8_t submodule:1; /**< flag to distinguish main modules and submodules */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200727 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
Radek Krejci086c7132018-10-26 15:29:04 +0200728 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
729 1 - the latest revision in searchdirs was not searched yet and this is the
730 latest revision in the current context
731 2 - searchdirs were searched and this is the latest available revision */
732 uint8_t parsing:1; /**< flag for circular check */
733 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejcid33273d2018-10-25 14:55:52 +0200734 uint16_t refcount; /**< 0 in modules, number of includes of a submodules */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200735};
736
737/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200738 * @brief Free the printable YANG schema tree structure.
739 *
740 * @param[in] module Printable YANG schema tree structure to free.
741 */
742void lysp_module_free(struct lysp_module *module);
743
744/**
Radek Krejcice8c1592018-10-29 15:35:51 +0100745 * @brief YANG extension instance
746 */
747struct lysc_ext_instance {
748 struct lyext_plugin *plugin; /**< pointer to the plugin implementing the extension (if present) */
749 void *parent; /**< pointer to the parent element holding the extension instance(s), use
750 ::lysc_ext_instance#parent_type to access the schema element */
751 const char *argument; /**< optional value of the extension's argument */
752 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
753 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
754 this identifies the index of the substatement for this extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +0100755 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejcice8c1592018-10-29 15:35:51 +0100756#if 0
Radek Krejcice8c1592018-10-29 15:35:51 +0100757 uint8_t ext_type; /**< extension type (#LYEXT_TYPE) */
758 uint8_t padding; /**< 32b padding */
Radek Krejcice8c1592018-10-29 15:35:51 +0100759 struct lys_module *module; /**< pointer to the extension instance's module (mandatory) */
760 LYS_NODE nodetype; /**< LYS_EXT */
761#endif
Radek Krejci2a408df2018-10-29 16:32:26 +0100762 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
763 void *priv; /**< private caller's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +0100764};
765
766/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200767 * @brief YANG import-stmt
768 */
769struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100770 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +0200771 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejcice8c1592018-10-29 15:35:51 +0100772 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200773};
774
775/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200776 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200777 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200778struct lysc_when {
779 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200780 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200781};
782
783/**
Radek Krejci2a408df2018-10-29 16:32:26 +0100784 * @brief YANG identity-stmt
785 */
786struct lysc_ident {
787 const char *name; /**< identity name (mandatory), including possible prefix */
788 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
789 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
790 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
791 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
792};
793
794/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200795 * @brief YANG feature-stmt
796 */
797struct lysc_feature {
798 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200799 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 +0200800 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +0100801 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200802 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
803 #LYS_FENABLED values allowed */
804};
805
Radek Krejci151a5b72018-10-19 14:21:44 +0200806/**
807 * @defgroup ifftokens if-feature expression tokens
808 * Tokens of if-feature expression used in ::lysc_iffeature#expr
809 *
810 * @{
811 */
812#define LYS_IFF_NOT 0x00 /**< operand "not" */
813#define LYS_IFF_AND 0x01 /**< operand "and" */
814#define LYS_IFF_OR 0x02 /**< operand "or" */
815#define LYS_IFF_F 0x03 /**< feature */
816/**
817 * @}
818 */
819
820/**
Radek Krejcib7db73a2018-10-24 14:18:40 +0200821 * @brief Compiled YANG revision statement
822 */
823struct lysc_revision {
824 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
825 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
826};
827
828/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200829 * @brief Compiled YANG if-feature-stmt
830 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200831struct lysc_iffeature {
Radek Krejci151a5b72018-10-19 14:21:44 +0200832 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
833 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200834};
835
836/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200837 * @brief Compiled YANG data node
838 */
839struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200840 uint16_t nodetype; /**< type of the node (mandatory) */
841 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
842 struct lysp_node *sp; /**< link to the simply parsed (SP) original of the node, NULL if the SP schema was removed. */
843 struct lysc_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
844 const char *name; /**< node name (mandatory) */
845 struct lysc_when *when; /**< when statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200846 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
847 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200848};
849
850/**
851 * @brief Compiled YANG schema tree structure representing YANG module.
852 *
853 * Semantically validated YANG schema tree for data tree parsing.
854 * Contains only the necessary information for the data validation.
855 */
856struct lysc_module {
857 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
858 const char *name; /**< name of the module (mandatory) */
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100859 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 +0200860 const char *ns; /**< namespace of the module (mandatory) */
861 const char *prefix; /**< module prefix (mandatory) */
Radek Krejcib7db73a2018-10-24 14:18:40 +0200862 struct lysc_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
863 in the list is always the last (newest) revision of the module */
Radek Krejci151a5b72018-10-19 14:21:44 +0200864 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200865
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200866 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +0100867 struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
868 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
869 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
870 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +0100871 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200872
873 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
874 uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is
875 the latest revision found */
Radek Krejci086c7132018-10-26 15:29:04 +0200876 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200877};
878
879/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200880 * @brief Get how the if-feature statement currently evaluates.
881 *
882 * @param[in] iff Compiled if-feature statement to evaluate.
883 * @return If the statement evaluates to true, 1 is returned. 0 is returned when the statement evaluates to false.
884 */
885int lysc_iffeature_value(const struct lysc_iffeature *iff);
886
887/**
888 * @brief Get the current status of the provided feature.
889 *
890 * @param[in] feature Compiled feature statement to examine.
891 * @return
892 * - 1 if feature is enabled,
893 * - 0 if feature is disabled,
894 * - -1 in case of error (invalid argument)
895 */
896int lysc_feature_value(const struct lysc_feature *feature);
897
898/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200899 * @brief Available YANG schema tree structures representing YANG module.
900 */
901struct lys_module {
902 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
903 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing */
904};
905
Radek Krejci151a5b72018-10-19 14:21:44 +0200906/**
907 * @brief Enable specified feature in the module
908 *
909 * By default, when the module is loaded by libyang parser, all features are disabled.
910 *
911 * @param[in] module Module where the feature will be enabled.
912 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
913 * @return LY_ERR value.
914 */
915LY_ERR lys_feature_enable(struct lys_module *module, const char *feature);
916
917/**
918 * @brief Disable specified feature in the module
919 *
920 * By default, when the module is loaded by libyang parser, all features are disabled.
921 *
922 * @param[in] module Module where the feature will be disabled.
923 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
924 * @return LY_ERR value
925 */
926LY_ERR lys_feature_disable(struct lys_module *module, const char *feature);
927
928/**
929 * @brief Get the current status of the specified feature in the module.
930 *
931 * @param[in] module Module where the feature is defined.
932 * @param[in] feature Name of the feature to inspect.
933 * @return
934 * - 1 if feature is enabled,
935 * - 0 if feature is disabled,
936 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
937 */
938int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200939
940/**
Radek Krejci86d106e2018-10-18 09:53:19 +0200941 * @brief Load a schema into the specified context.
942 *
943 * @param[in] ctx libyang context where to process the data model.
944 * @param[in] data The string containing the dumped data model in the specified
945 * format.
946 * @param[in] format Format of the input data (YANG or YIN).
947 * @return Pointer to the data model structure or NULL on error.
948 */
949const struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
950
951/**
952 * @brief Read a schema from file descriptor into the specified context.
953 *
954 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
955 *
956 * @param[in] ctx libyang context where to process the data model.
957 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
958 * in the specified format.
959 * @param[in] format Format of the input data (YANG or YIN).
960 * @return Pointer to the data model structure or NULL on error.
961 */
962const struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
963
964/**
Radek Krejcid33273d2018-10-25 14:55:52 +0200965 * @brief Read a schema into the specified context from a file.
Radek Krejci86d106e2018-10-18 09:53:19 +0200966 *
967 * @param[in] ctx libyang context where to process the data model.
968 * @param[in] path Path to the file with the model in the specified format.
969 * @param[in] format Format of the input data (YANG or YIN).
970 * @return Pointer to the data model structure or NULL on error.
971 */
972const struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
973
974/**
Radek Krejcid33273d2018-10-25 14:55:52 +0200975 * @brief Search for the schema file in the specified searchpaths.
976 *
977 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
978 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
979 * result of the ly_ctx_get_searchdirs().
980 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
981 * @param[in] name Name of the schema to find.
982 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
983 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
984 * complying the provided restriction is found, NULL is set.
985 * @param[out] format Optional output variable containing expected format of the schema document according to the
986 * file suffix.
987 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
988 */
989LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
990
991/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200992 * @defgroup scflags Schema compile flags
993 * @ingroup schematree
994 *
995 * @{
996 */
997#define LYSC_OPT_FREE_SP 1 /**< Free the input printable schema */
998
999/**
1000 * @}
1001 */
1002
1003/**
1004 * @brief Compile printable schema into a validated schema linking all the references.
1005 *
1006 * @param[in] sp Simple parsed printable schema to compile. Can be changed according to the provided options.
1007 * @param[in] options Various options to modify compiler behavior, see [compile flags](@ref scflags).
1008 * @param[out] sc Resulting compiled schema structure.
1009 * @return LY_ERR value.
1010 */
1011LY_ERR lys_compile(struct lysp_module *sp, int options, struct lysc_module **sc);
1012
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001013/** @} */
1014
Radek Krejci70853c52018-10-15 14:46:16 +02001015#ifdef __cplusplus
1016}
1017#endif
1018
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001019#endif /* LY_TREE_SCHEMA_H_ */