blob: cee90f520c7ed4e826639a724ec199a3dc1d731c [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 Krejci70853c52018-10-15 14:46:16 +020020#ifdef __cplusplus
21extern "C" {
22#endif
23
Radek Krejci5aeea3a2018-09-05 13:29:36 +020024/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +020025 * @brief XPath representation.
26 */
27struct lyxp_expr;
28
29/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020030 * @brief Macro selector for other LY_ARRAY_* macros, do not use directly!
31 */
32#define LY_ARRAY_SELECT(_1, _2, NAME, ...) NAME
33
34/**
35 * @brief Get void pointer to the item on the INDEX in the ARRAY
36 */
37#define LY_ARRAY_INDEX1(ARRAY, INDEX) ((void*)((uint32_t*)((ARRAY) + INDEX) + 1))
38
39/**
40 * @brief Get the TYPE pointer to the item on the INDEX in the ARRAY
41 */
42#define LY_ARRAY_INDEX2(ARRAY, INDEX, TYPE) ((TYPE*)((uint32_t*)((ARRAY) + INDEX) + 1))
43
44/**
45 * @brief Helper macro to go through sized-arrays with a pointer iterator.
46 *
47 * Use with opening curly bracket (`{`).
48 *
49 * @param[in] ARRAY Array to go through
50 * @param[in] TYPE Type of the records in the ARRAY
51 * @param[out] ITER Iterating pointer to the item being processed in each loop
52 */
53#define LY_ARRAY_FOR_ITER(ARRAY, TYPE, ITER) \
54 for (ITER = LY_ARRAY_INDEX1(ARRAY, 0); \
55 (ARRAY) && ((void*)ITER - (void*)ARRAY - sizeof(uint32_t))/(sizeof(TYPE)) < (*(uint32_t*)(ARRAY)); \
56 ITER = (void*)((TYPE*)ITER + 1))
57
58/**
59 * @brief Helper macro to go through sized-arrays with a numeric iterator.
60 *
61 * Use with opening curly bracket (`{`).
62 *
63 * To access an item with the INDEX value, use always LY_ARRAY_INDEX macro!
64 *
65 * @param[in] ARRAY Array to go through
66 * @param[out] INDEX Iterating index of the item being processed in each loop
67 */
68#define LY_ARRAY_FOR_INDEX(ARRAY, INDEX) \
69 for (INDEX = 0; \
70 ARRAY && INDEX < (*((uint32_t*)(ARRAY))); \
71 ++INDEX)
72
73/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +020074 * @defgroup schematree Schema Tree
75 * @{
76 *
77 * Data structures and functions to manipulate and access schema tree.
78 */
79
Radek Krejci0af5f5d2018-09-07 15:00:30 +020080/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020081 * @brief Get (optionally TYPEd) pointer to the item on the INDEX in the ARRAY
Radek Krejci5fac3592018-10-12 15:23:45 +020082 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +020083 * LY_ARRAY_INDEX(ARRAY, INDEX [, TYPE])
Radek Krejci5fac3592018-10-12 15:23:45 +020084 */
Radek Krejcie53a8dc2018-10-17 12:52:40 +020085#define LY_ARRAY_INDEX(ARRAY, ...) LY_ARRAY_SELECT(__VA_ARGS__, LY_ARRAY_INDEX2, LY_ARRAY_INDEX1)(ARRAY, __VA_ARGS__)
86
87/**
88 * @brief Get a number of records in the ARRAY.
Radek Krejci86d106e2018-10-18 09:53:19 +020089 *
90 * Does not check if array exists!
Radek Krejcie53a8dc2018-10-17 12:52:40 +020091 */
92#define LY_ARRAY_SIZE(ARRAY) (*((uint32_t*)(ARRAY)))
93
94/**
95 * @brief Sized-array iterator (for-loop).
96 *
97 * Use with opening curly bracket (`{`).
98 *
99 * There are 2 variants:
100 *
101 * LY_ARRAY_FOR(ARRAY, TYPE, ITER)
102 *
103 * 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
104 * providing the items of the ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_ITER macro
105 *
106 * LY_ARRAY_FOR(ARRAY, INDEX)
107 *
108 * The ARRAY is again a sized-array to go through, the INDEX is a variable (unsigned integer) for storing iterating ARRAY's index
109 * to access the items of ARRAY in the loops. The INDEX is supposed to be used via LY_ARRAY_INDEX macro which can provide the item
110 * in the loop body. This functionality is provided by LY_ARRAY_FOR_INDEX macro.
111 */
112#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 +0200113
114/**
115 * @brief Macro to iterate via all sibling elements without affecting the list itself
116 *
117 * Works for all types of nodes despite it is data or schema tree, but all the
118 * parameters must be pointers to the same type.
119 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200120 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200121 *
122 * @param START Pointer to the starting element.
123 * @param ELEM Iterator.
124 */
125#define LY_LIST_FOR(START, ELEM) \
126 for ((ELEM) = (START); \
127 (ELEM); \
128 (ELEM) = (ELEM)->next)
129
130/**
131 * @ingroup datatree
132 * @brief Macro to iterate via all sibling elements allowing to modify the list itself (e.g. removing elements)
133 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200134 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200135 *
136 * @param START Pointer to the starting element.
137 * @param NEXT Temporary storage to allow removing of the current iterator content.
138 * @param ELEM Iterator.
139 */
140#define LY_LIST_FOR_SAFE(START, NEXT, ELEM) \
141 for ((ELEM) = (START); \
142 (ELEM) ? (NEXT = (ELEM)->next, 1) : 0; \
143 (ELEM) = (NEXT))
144
145/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200146 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
147 */
148typedef enum {
149 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
150 LYS_IN_YANG = 1, /**< YANG schema input format */
151 LYS_IN_YIN = 2 /**< YIN schema input format */
152} LYS_INFORMAT;
153
154/**
155 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
156 */
157typedef enum {
158 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
159 LYS_OUT_YANG = 1, /**< YANG schema output format */
160 LYS_OUT_YIN = 2, /**< YIN schema output format */
161 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
162 LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
163 LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */
164} LYS_OUTFORMAT;
165
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200166#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
167
Michal Vaskob55f6c12018-09-12 11:13:15 +0200168#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
169#define LYS_CONTAINER 0x0001 /**< container statement node */
170#define LYS_CHOICE 0x0002 /**< choice statement node */
171#define LYS_LEAF 0x0004 /**< leaf statement node */
172#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
173#define LYS_LIST 0x0010 /**< list statement node */
174#define LYS_ANYXML 0x0020 /**< anyxml statement node */
175#define LYS_CASE 0x0040 /**< case statement node */
176#define LYS_USES 0x0080 /**< uses statement node */
177#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 +0200178
179/**
180 * @brief YANG import-stmt
181 */
182struct lysp_import {
Michal Vaskod5927ca2018-09-07 15:05:32 +0200183 const char *name; /**< name of the module to import (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200184 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200185 const char *dsc; /**< description */
186 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200187 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200188 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
189};
190
191/**
192 * @brief YANG include-stmt
193 */
194struct lysp_include {
Michal Vaskod5927ca2018-09-07 15:05:32 +0200195 const char *name; /**< name of the submodule to include (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200196 const char *dsc; /**< description */
197 const char *ref; /**< reference */
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 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
200};
201
202/**
203 * @brief YANG extension-stmt
204 */
205struct lysp_ext {
206 const char *name; /**< extension name */
207 const char *argument; /**< argument name, NULL if not specified */
208 const char *dsc; /**< description statement */
209 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200210 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200211 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
212};
213
214/**
215 * @brief Helper structure for generic storage of the extension instances content.
216 */
217struct lysp_stmt {
218 const char *stmt; /**< identifier of the statement */
219 const char *arg; /**< statement's argument */
220 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200221 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200222};
223
224/**
Michal Vaskod92e42a2018-09-07 08:35:02 +0200225 * @brief Enum of substatements in which extension instances can appear.
226 */
227typedef enum {
228 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
229 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
230 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
231 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
232 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
233 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
234 lys_node_choice and lys_deviate */
235 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
236 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
237 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
238 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
239 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
240 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
241 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
242 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
243 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
244 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
245 belongs-to's prefix) and lys_import */
246 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
247 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
248 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
249 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
250 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
251 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
252 lys_node_leaflist and lys_deviate */
253 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
254 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
255 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
256 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
257 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
258 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
259 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
260 lys_node_anydata and lys_deviate */
261 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
262 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
263 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200264 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200265 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
266 lys_node_leaflist and lys_deviate */
267 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
268 lys_node_leaflist and lys_deviate */
269 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
270 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200271 LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200272} LYEXT_SUBSTMT;
273
274/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200275 * @brief YANG extension instance
276 */
277struct lysp_ext_instance {
278 const char *name; /**< extension identifier, including possible prefix */
279 const char *argument; /**< optional value of the extension's argument */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200280 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
281 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
282 the index of that substatement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200283 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200284};
285
286/**
287 * @brief YANG feature-stmt
288 */
289struct lysp_feature {
290 const char *name; /**< feature name (mandatory) */
291 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
292 const char *dsc; /**< description statement */
293 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200294 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200295 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
296};
297
298/**
299 * @brief YANG identity-stmt
300 */
301struct lysp_ident {
302 const char *name; /**< identity name (mandatory), including possible prefix */
303 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
304 const char **bases; /**< list of base identifiers (NULL-terminated) */
305 const char *dsc; /**< description statement */
306 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200307 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200308 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
309};
310
Michal Vasko71e64ca2018-09-07 16:30:29 +0200311/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200312 * @brief Covers restrictions: range, length, pattern, must
313 */
314struct lysp_restr {
315 const char *arg; /**< The restriction expression/value (mandatory);
316 in case of pattern restriction, the first byte has a special meaning:
317 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
318 const char *emsg; /**< error-message */
319 const char *eapptag; /**< error-app-tag value */
320 const char *dsc; /**< description */
321 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200322 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200323};
324
325/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200326 * @brief YANG revision-stmt
327 */
328struct lysp_revision {
329 char rev[LY_REV_SIZE]; /**< revision date (madatory) */
330 const char *dsc; /**< description statement */
331 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200332 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200333};
334
335/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200336 * @brief Enumeration/Bit value definition
337 */
338struct lysp_type_enum {
339 const char *name; /**< name (mandatory) */
340 const char *dsc; /**< description statement */
341 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200342 int64_t value; /**< enum's value or bit's position */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200343 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200344 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200345 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
346 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200347};
348
349/**
350 * @brief YANG type-stmt
351 *
352 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
353 */
354struct lysp_type {
355 const char *name; /**< name of the type (mandatory) */
356 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
357 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200358 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
359 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
360 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200361 const char *path; /**< path - leafref */
362 const char **bases; /**< list of base identifiers (NULL-terminated) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200363 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
364 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200365
366 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
367 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200368 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_SET_REQINST allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200369};
370
371/**
372 * @brief YANG typedef-stmt
373 */
374struct lysp_tpdf {
375 const char *name; /**< name of the newly defined type (mandatory) */
376 const char *units; /**< units of the newly defined type */
377 const char *dflt; /**< default value of the newly defined type */
378 const char *dsc; /**< description statement */
379 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200380 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200381 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
382 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
383};
384
385/**
386 * @brief YANG grouping-stmt
387 */
388struct lysp_grp {
389 const char *name; /**< grouping name (mandatory) */
390 const char *dsc; /**< description statement */
391 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200392 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
393 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200394 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200395 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
396 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
397 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200398 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
399};
400
401/**
402 * @brief YANG when-stmt
403 */
404struct lysp_when {
405 const char *cond; /**< specified condition (mandatory) */
406 const char *dsc; /**< description statement */
407 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200408 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200409};
410
411/**
412 * @brief YANG refine-stmt
413 */
414struct lysp_refine {
415 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
416 const char *dsc; /**< description statement */
417 const char *ref; /**< reference statement */
418 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200419 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200420 const char *presence; /**< presence description */
421 const char **dflts; /**< list of default values (NULL-terminated) */
422 uint32_t min; /**< min-elements constraint */
423 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200424 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200425 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
426};
427
428/**
429 * @brief YANG uses-augment-stmt and augment-stmt
430 */
431struct lysp_augment {
432 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
433 const char *dsc; /**< description statement */
434 const char *ref; /**< reference statement */
435 struct lysp_when *when; /**< when statement */
436 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
437 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200438 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
439 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
440 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200441 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
442};
443
444/**
445 * @defgroup deviatetypes Deviate types
446 * @{
447 */
448#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
449#define LYS_DEV_ADD 2 /**< deviate type add */
450#define LYS_DEV_DELETE 3 /**< deviate type delete */
451#define LYS_DEV_REPLACE 4 /**< deviate type replace */
452/** @} */
453
454/**
455 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
456 */
457struct lysp_deviate {
458 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
459 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200460 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200461};
462
463struct lysp_deviate_add {
464 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
465 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200466 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200467 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200468 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200469 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
470 const char **dflts; /**< list of default values (NULL-terminated) */
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_deviate_del {
477 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
478 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200479 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200480 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200481 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200482 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
483 const char **dflts; /**< list of default values (NULL-terminated) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200484 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200485};
486
487struct lysp_deviate_rpl {
488 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
489 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200490 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200491 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200492 const char *units; /**< units of the values */
493 const char *dflt; /**< default value */
494 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
495 uint32_t min; /**< min-elements constraint */
496 uint32_t max; /**< max-elements constraint, 0 means unbounded */
497};
498
499struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200500 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200501 const char *dsc; /**< description statement */
502 const char *ref; /**< reference statement */
503 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200504 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200505};
506
Michal Vaskob55f6c12018-09-12 11:13:15 +0200507#define LYS_CONFIG_W 0x01 /**< config true; */
508#define LYS_CONFIG_R 0x02 /**< config false; */
509#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
510#define LYS_STATUS_CURR 0x08 /**< status current; */
511#define LYS_STATUS_DEPRC 0x10 /**< status deprecated; */
512#define LYS_STATUS_OBSLT 0x20 /**< status obsolete; */
513#define LYS_STATUS_MASK 0x38 /**< mask for status value */
514#define LYS_MAND_TRUE 0x40 /**< mandatory true; applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200515 ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf
516 and ::lysp_node_anydata/::lysc_node_anydata */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200517#define LYS_MAND_FALSE 0x80 /**< mandatory false; applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200518 ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf
519 and ::lysp_node_anydata/::lysc_node_anydata */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200520#define LYS_MAND_MASK 0xc0 /**< mask for mandatory values */
521#define LYS_ORDBY_SYSTEM 0x100 /**< ordered-by system lists, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200522 ::lysp_node_list/lysc_node_list and ::lysp_node_leaflist/::lysc_node_list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200523#define LYS_ORDBY_USER 0x200 /**< ordered-by user lists, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200524 ::lysp_node_list/lysc_node_list and ::lysp_node_leaflist/::lysc_node_list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200525#define LYS_ORDBY_MASK 0x300 /**< mask for ordered-by flags */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200526#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysp_feature/::lysc_feature */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200527#define LYS_AUTOASSIGNED 0x01 /**< value was auto-assigned, applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200528 ::lysp_type/::lysc_type enum and bits flags */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200529#define LYS_YINELEM_TRUE 0x01 /**< yin-element true for extension's argument */
530#define LYS_YINELEM_FALSE 0x02 /**< yin-element false for extension's argument */
531#define LYS_YINELEM_MASK 0x03 /**< mask for yin-element value */
532#define LYS_SET_VALUE 0x01 /**< value attribute is set */
533#define LYS_SET_MAX 0x400 /**< max attribute is set */
534#define LYS_SET_MIN 0x800 /**< min attribute is set */
535#define LYS_SET_REQINST 0x01 /**< require_instance attribute is set */
536
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200537/**
538 * @brief Generic YANG data node
539 */
540struct lysp_node {
541 uint16_t nodetype; /**< type of the node (mandatory) */
542 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
543 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
544 const char *name; /**< node name (mandatory) */
545 const char *dsc; /**< description statement */
546 const char *ref; /**< reference statement */
547 struct lysp_when *when; /**< when statement */
548 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200549 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200550};
551
552/**
553 * @brief Extension structure of the lysp_node for YANG container
554 */
555struct lysp_node_container {
556 uint16_t nodetype; /**< LYS_CONTAINER */
557 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
558 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
559 const char *name; /**< node name (mandatory) */
560 const char *dsc; /**< description statement */
561 const char *ref; /**< reference statement */
562 struct lysp_when *when; /**< when statement */
563 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200564 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200565
566 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200567 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200568 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200569 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
570 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200571 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200572 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
573 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200574};
575
576struct lysp_node_leaf {
577 uint16_t nodetype; /**< LYS_LEAF */
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 */
584 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
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 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200588 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200589 struct lysp_type type; /**< type of the leaf node (mandatory) */
590 const char *units; /**< units of the leaf's type */
591 const char *dflt; /**< default value */
592};
593
594struct lysp_node_leaflist {
595 uint16_t nodetype; /**< LYS_LEAFLIST */
596 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
597 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
598 const char *name; /**< node name (mandatory) */
599 const char *dsc; /**< description statement */
600 const char *ref; /**< reference statement */
601 struct lysp_when *when; /**< when statement */
602 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200603 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200604
605 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200606 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200607 struct lysp_type type; /**< type of the leaf node (mandatory) */
608 const char *units; /**< units of the leaf's type */
609 const char **dflts; /**< list of default values (NULL-terminated) */
610 uint32_t min; /**< min-elements constraint */
611 uint32_t max; /**< max-elements constraint, 0 means unbounded */
612};
613
614struct lysp_node_list {
615 uint16_t nodetype; /**< LYS_LIST */
616 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
617 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
618 const char *name; /**< node name (mandatory) */
619 const char *dsc; /**< description statement */
620 const char *ref; /**< reference statement */
621 struct lysp_when *when; /**< when statement */
622 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200623 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200624
625 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200626 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200627 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200628 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
629 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200630 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200631 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
632 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200633 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
634 uint32_t min; /**< min-elements constraint */
635 uint32_t max; /**< max-elements constraint, 0 means unbounded */
636};
637
638struct lysp_node_choice {
639 uint16_t nodetype; /**< LYS_CHOICE */
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 */
646 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
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 /* choice */
650 struct lysp_node *child; /**< list of data nodes (linked list) */
651 const char* dflt; /**< default case */
652};
653
654struct lysp_node_case {
655 uint16_t nodetype; /**< LYS_CASE */
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 */
662 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
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 /* case */
666 struct lysp_node *child; /**< list of data nodes (linked list) */
667};
668
669struct lysp_node_anydata {
670 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
671 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
672 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
673 const char *name; /**< node name (mandatory) */
674 const char *dsc; /**< description statement */
675 const char *ref; /**< reference statement */
676 struct lysp_when *when; /**< when statement */
677 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200678 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200679
680 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200681 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200682};
683
684struct lysp_node_uses {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200685 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200686 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
687 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
688 const char *name; /**< grouping name reference (mandatory) */
689 const char *dsc; /**< description statement */
690 const char *ref; /**< reference statement */
691 struct lysp_when *when; /**< when statement */
692 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200693 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200694
695 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200696 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
697 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200698};
699
700/**
701 * @brief YANG input-stmt and output-stmt
702 */
703struct lysp_action_inout {
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200704 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
705 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
706 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200707 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200708 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200709};
710
711/**
712 * @brief YANG rpc-stmt and action-stmt
713 */
714struct lysp_action {
715 const char *name; /**< grouping name reference (mandatory) */
716 const char *dsc; /**< description statement */
717 const char *ref; /**< reference statement */
718 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200719 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
720 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200721 struct lysp_action_inout *input; /**< RPC's/Action's input */
722 struct lysp_action_inout *output;/**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200723 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200724 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
725};
726
727/**
728 * @brief YANG notification-stmt
729 */
730struct lysp_notif {
731 const char *name; /**< grouping name reference (mandatory) */
732 const char *dsc; /**< description statement */
733 const char *ref; /**< reference statement */
734 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200735 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
736 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
737 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200738 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200739 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200740 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
741};
742
743/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200744 * @brief supported YANG schema version values
745 */
746typedef enum LYS_VERSION {
747 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
748 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
749 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
750} LYS_VERSION;
751
752/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200753 * @brief Printable YANG schema tree structure representing YANG module.
754 *
755 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
756 */
757struct lysp_module {
758 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
759 const char *name; /**< name of the module (mandatory) */
760 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
761 union {
762 /* module */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200763 const char *ns; /**< namespace of the module (module - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200764 /* submodule */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200765 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200766 };
Michal Vaskod5927ca2018-09-07 15:05:32 +0200767 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200768 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
769 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200770 const char *org; /**< party/company responsible for the module */
771 const char *contact; /**< contact information for the module */
772 const char *dsc; /**< description of the module */
773 const char *ref; /**< cross-reference for the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200774 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200775 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200776 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
777 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
778 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
779 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
780 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200781 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200782 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
783 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
784 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
785 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
786 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200787
Radek Krejcif0fceb62018-09-05 14:58:45 +0200788 uint8_t submodule:1; /**< flag to distinguish main modules and submodules */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200789 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
790 uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is
791 the latest revision found */
Radek Krejcif0fceb62018-09-05 14:58:45 +0200792 uint8_t version:4; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200793};
794
795/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200796 * @brief Free the printable YANG schema tree structure.
797 *
798 * @param[in] module Printable YANG schema tree structure to free.
799 */
800void lysp_module_free(struct lysp_module *module);
801
802/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200803 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200804 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200805struct lysc_when {
806 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200807 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200808};
809
810/**
811 * @brief YANG feature-stmt
812 */
813struct lysc_feature {
814 const char *name; /**< feature name (mandatory) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200815 struct lysc_feature *depfeatures;/**< list of other features depending on this one ([sized array](@ref sizedarrays)) */
816 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
817 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200818 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
819 #LYS_FENABLED values allowed */
820};
821
822struct lysc_iffeature {
823 struct lysc_feature *features; /**< array of pointers to the features used in expression, size depends on content of expr */
824 uint32_t expr[]; /**< 2bits array describing the if-feature expression in prefix format */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200825};
826
827/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200828 * @brief Compiled YANG data node
829 */
830struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200831 uint16_t nodetype; /**< type of the node (mandatory) */
832 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
833 struct lysp_node *sp; /**< link to the simply parsed (SP) original of the node, NULL if the SP schema was removed. */
834 struct lysc_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
835 const char *name; /**< node name (mandatory) */
836 struct lysc_when *when; /**< when statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200837 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
838 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200839};
840
841/**
842 * @brief Compiled YANG schema tree structure representing YANG module.
843 *
844 * Semantically validated YANG schema tree for data tree parsing.
845 * Contains only the necessary information for the data validation.
846 */
847struct lysc_module {
848 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
849 const char *name; /**< name of the module (mandatory) */
850 const char *ns; /**< namespace of the module (mandatory) */
851 const char *prefix; /**< module prefix (mandatory) */
852
853
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200854 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200855
856
857 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
858 uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is
859 the latest revision found */
860 uint8_t version:4; /**< yang-version (LYS_VERSION values) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200861};
862
863/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200864 * @brief Available YANG schema tree structures representing YANG module.
865 */
866struct lys_module {
867 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
868 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing */
869};
870
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200871
872/**
Radek Krejci86d106e2018-10-18 09:53:19 +0200873 * @brief Load a schema into the specified context.
874 *
875 * @param[in] ctx libyang context where to process the data model.
876 * @param[in] data The string containing the dumped data model in the specified
877 * format.
878 * @param[in] format Format of the input data (YANG or YIN).
879 * @return Pointer to the data model structure or NULL on error.
880 */
881const struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
882
883/**
884 * @brief Read a schema from file descriptor into the specified context.
885 *
886 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
887 *
888 * @param[in] ctx libyang context where to process the data model.
889 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
890 * in the specified format.
891 * @param[in] format Format of the input data (YANG or YIN).
892 * @return Pointer to the data model structure or NULL on error.
893 */
894const struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
895
896/**
897 * @brief Load a schema into the specified context from a file.
898 *
899 * @param[in] ctx libyang context where to process the data model.
900 * @param[in] path Path to the file with the model in the specified format.
901 * @param[in] format Format of the input data (YANG or YIN).
902 * @return Pointer to the data model structure or NULL on error.
903 */
904const struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
905
906/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200907 * @defgroup scflags Schema compile flags
908 * @ingroup schematree
909 *
910 * @{
911 */
912#define LYSC_OPT_FREE_SP 1 /**< Free the input printable schema */
913
914/**
915 * @}
916 */
917
918/**
919 * @brief Compile printable schema into a validated schema linking all the references.
920 *
921 * @param[in] sp Simple parsed printable schema to compile. Can be changed according to the provided options.
922 * @param[in] options Various options to modify compiler behavior, see [compile flags](@ref scflags).
923 * @param[out] sc Resulting compiled schema structure.
924 * @return LY_ERR value.
925 */
926LY_ERR lys_compile(struct lysp_module *sp, int options, struct lysc_module **sc);
927
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200928/** @} */
929
Radek Krejci70853c52018-10-15 14:46:16 +0200930#ifdef __cplusplus
931}
932#endif
933
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200934#endif /* LY_TREE_SCHEMA_H_ */