blob: 6266427e275d8e57224d4ccd797e27cfae49fd73 [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
20/**
21 * @defgroup schematree Schema Tree
22 * @{
23 *
24 * Data structures and functions to manipulate and access schema tree.
25 */
26
Radek Krejci0af5f5d2018-09-07 15:00:30 +020027/**
Radek Krejci5fac3592018-10-12 15:23:45 +020028 * @brief Helper macro to go through 0-terminated arrays
29 *
30 * Use with opening curly bracket '{'.
31 *
32 * @param[in] ARRAY Array to go through
33 * @param[out] ITER Numeric iterator storing available indexes of the ARRAY
34 */
Michal Vasko4f3980b2018-10-15 10:50:48 +020035#define LY_ARRAY_FOR(ARRAY, ITER) for (ITER = 0; (ARRAY) && *((void **)((ARRAY) + ITER)); ++ITER)
Radek Krejci5fac3592018-10-12 15:23:45 +020036
37/**
38 * @brief Macro to iterate via all sibling elements without affecting the list itself
39 *
40 * Works for all types of nodes despite it is data or schema tree, but all the
41 * parameters must be pointers to the same type.
42 *
43 * Use with opening curly bracket '{'. All parameters must be of the same type.
44 *
45 * @param START Pointer to the starting element.
46 * @param ELEM Iterator.
47 */
48#define LY_LIST_FOR(START, ELEM) \
49 for ((ELEM) = (START); \
50 (ELEM); \
51 (ELEM) = (ELEM)->next)
52
53/**
54 * @ingroup datatree
55 * @brief Macro to iterate via all sibling elements allowing to modify the list itself (e.g. removing elements)
56 *
57 * Use with opening curly bracket '{'. All parameters must be of the same type.
58 *
59 * @param START Pointer to the starting element.
60 * @param NEXT Temporary storage to allow removing of the current iterator content.
61 * @param ELEM Iterator.
62 */
63#define LY_LIST_FOR_SAFE(START, NEXT, ELEM) \
64 for ((ELEM) = (START); \
65 (ELEM) ? (NEXT = (ELEM)->next, 1) : 0; \
66 (ELEM) = (NEXT))
67
68/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +020069 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
70 */
71typedef enum {
72 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
73 LYS_IN_YANG = 1, /**< YANG schema input format */
74 LYS_IN_YIN = 2 /**< YIN schema input format */
75} LYS_INFORMAT;
76
77/**
78 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
79 */
80typedef enum {
81 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
82 LYS_OUT_YANG = 1, /**< YANG schema output format */
83 LYS_OUT_YIN = 2, /**< YIN schema output format */
84 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
85 LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
86 LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */
87} LYS_OUTFORMAT;
88
Radek Krejci5aeea3a2018-09-05 13:29:36 +020089#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
90
Michal Vaskob55f6c12018-09-12 11:13:15 +020091#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
92#define LYS_CONTAINER 0x0001 /**< container statement node */
93#define LYS_CHOICE 0x0002 /**< choice statement node */
94#define LYS_LEAF 0x0004 /**< leaf statement node */
95#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
96#define LYS_LIST 0x0010 /**< list statement node */
97#define LYS_ANYXML 0x0020 /**< anyxml statement node */
98#define LYS_CASE 0x0040 /**< case statement node */
99#define LYS_USES 0x0080 /**< uses statement node */
100#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 +0200101
102/**
103 * @brief YANG import-stmt
104 */
105struct lysp_import {
Michal Vaskod5927ca2018-09-07 15:05:32 +0200106 const char *name; /**< name of the module to import (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200107 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200108 const char *dsc; /**< description */
109 const char *ref; /**< reference */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200110 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200111 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
112};
113
114/**
115 * @brief YANG include-stmt
116 */
117struct lysp_include {
Michal Vaskod5927ca2018-09-07 15:05:32 +0200118 const char *name; /**< name of the submodule to include (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200119 const char *dsc; /**< description */
120 const char *ref; /**< reference */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200121 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200122 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
123};
124
125/**
126 * @brief YANG extension-stmt
127 */
128struct lysp_ext {
129 const char *name; /**< extension name */
130 const char *argument; /**< argument name, NULL if not specified */
131 const char *dsc; /**< description statement */
132 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200133 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200134 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
135};
136
137/**
138 * @brief Helper structure for generic storage of the extension instances content.
139 */
140struct lysp_stmt {
141 const char *stmt; /**< identifier of the statement */
142 const char *arg; /**< statement's argument */
143 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200144 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200145};
146
147/**
Michal Vaskod92e42a2018-09-07 08:35:02 +0200148 * @brief Enum of substatements in which extension instances can appear.
149 */
150typedef enum {
151 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
152 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
153 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
154 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
155 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
156 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
157 lys_node_choice and lys_deviate */
158 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
159 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
160 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
161 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
162 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
163 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
164 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
165 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
166 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
167 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
168 belongs-to's prefix) and lys_import */
169 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
170 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
171 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
172 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
173 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
174 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
175 lys_node_leaflist and lys_deviate */
176 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
177 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
178 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
179 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
180 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
181 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
182 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
183 lys_node_anydata and lys_deviate */
184 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
185 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
186 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200187 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200188 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
189 lys_node_leaflist and lys_deviate */
190 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
191 lys_node_leaflist and lys_deviate */
192 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
193 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200194 LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200195} LYEXT_SUBSTMT;
196
197/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200198 * @brief YANG extension instance
199 */
200struct lysp_ext_instance {
201 const char *name; /**< extension identifier, including possible prefix */
202 const char *argument; /**< optional value of the extension's argument */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200203 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
204 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
205 the index of that substatement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200206 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200207};
208
209/**
210 * @brief YANG feature-stmt
211 */
212struct lysp_feature {
213 const char *name; /**< feature name (mandatory) */
214 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
215 const char *dsc; /**< description statement */
216 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200217 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200218 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
219};
220
221/**
222 * @brief YANG identity-stmt
223 */
224struct lysp_ident {
225 const char *name; /**< identity name (mandatory), including possible prefix */
226 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
227 const char **bases; /**< list of base identifiers (NULL-terminated) */
228 const char *dsc; /**< description statement */
229 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200230 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200231 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
232};
233
Michal Vasko71e64ca2018-09-07 16:30:29 +0200234/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200235 * @brief Covers restrictions: range, length, pattern, must
236 */
237struct lysp_restr {
238 const char *arg; /**< The restriction expression/value (mandatory);
239 in case of pattern restriction, the first byte has a special meaning:
240 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
241 const char *emsg; /**< error-message */
242 const char *eapptag; /**< error-app-tag value */
243 const char *dsc; /**< description */
244 const char *ref; /**< reference */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200245 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200246};
247
248/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200249 * @brief YANG revision-stmt
250 */
251struct lysp_revision {
252 char rev[LY_REV_SIZE]; /**< revision date (madatory) */
253 const char *dsc; /**< description statement */
254 const char *ref; /**< reference statement */
255 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
256};
257
258/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200259 * @brief Enumeration/Bit value definition
260 */
261struct lysp_type_enum {
262 const char *name; /**< name (mandatory) */
263 const char *dsc; /**< description statement */
264 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200265 int64_t value; /**< enum's value or bit's position */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200266 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200267 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200268 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
269 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200270};
271
272/**
273 * @brief YANG type-stmt
274 *
275 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
276 */
277struct lysp_type {
278 const char *name; /**< name of the type (mandatory) */
279 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
280 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200281 struct lysp_restr *patterns; /**< list of patterns (0-terminated) - string */
282 struct lysp_type_enum *enums; /**< list of enum-stmts (0-terminated) - enum */
283 struct lysp_type_enum *bits; /**< list of bit-stmts (0-terminated) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200284 const char *path; /**< path - leafref */
285 const char **bases; /**< list of base identifiers (NULL-terminated) - identityref */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200286 struct lysp_type *types; /**< list of sub-types (0-terminated) - union */
287 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200288
289 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
290 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200291 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_SET_REQINST allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200292};
293
294/**
295 * @brief YANG typedef-stmt
296 */
297struct lysp_tpdf {
298 const char *name; /**< name of the newly defined type (mandatory) */
299 const char *units; /**< units of the newly defined type */
300 const char *dflt; /**< default value of the newly defined type */
301 const char *dsc; /**< description statement */
302 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200303 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200304 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
305 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
306};
307
308/**
309 * @brief YANG grouping-stmt
310 */
311struct lysp_grp {
312 const char *name; /**< grouping name (mandatory) */
313 const char *dsc; /**< description statement */
314 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200315 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
316 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200317 struct lysp_node *data; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200318 struct lysp_action *actions; /**< list of actions (0-terminated) */
319 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
320 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200321 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
322};
323
324/**
325 * @brief YANG when-stmt
326 */
327struct lysp_when {
328 const char *cond; /**< specified condition (mandatory) */
329 const char *dsc; /**< description statement */
330 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200331 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200332};
333
334/**
335 * @brief YANG refine-stmt
336 */
337struct lysp_refine {
338 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
339 const char *dsc; /**< description statement */
340 const char *ref; /**< reference statement */
341 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200342 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200343 const char *presence; /**< presence description */
344 const char **dflts; /**< list of default values (NULL-terminated) */
345 uint32_t min; /**< min-elements constraint */
346 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200347 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200348 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
349};
350
351/**
352 * @brief YANG uses-augment-stmt and augment-stmt
353 */
354struct lysp_augment {
355 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
356 const char *dsc; /**< description statement */
357 const char *ref; /**< reference statement */
358 struct lysp_when *when; /**< when statement */
359 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
360 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200361 struct lysp_action *actions; /**< list of actions (0-terminated) */
362 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
363 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200364 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
365};
366
367/**
368 * @defgroup deviatetypes Deviate types
369 * @{
370 */
371#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
372#define LYS_DEV_ADD 2 /**< deviate type add */
373#define LYS_DEV_DELETE 3 /**< deviate type delete */
374#define LYS_DEV_REPLACE 4 /**< deviate type replace */
375/** @} */
376
377/**
378 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
379 */
380struct lysp_deviate {
381 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
382 struct lysp_deviate *next; /**< next deviate structure in the list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200383 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200384};
385
386struct lysp_deviate_add {
387 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
388 struct lysp_deviate *next; /**< next deviate structure in the list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200389 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
390 const char *units; /**< units of the values */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200391 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200392 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
393 const char **dflts; /**< list of default values (NULL-terminated) */
394 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
395 uint32_t min; /**< min-elements constraint */
396 uint32_t max; /**< max-elements constraint, 0 means unbounded */
397};
398
399struct lysp_deviate_del {
400 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
401 struct lysp_deviate *next; /**< next deviate structure in the list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200402 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
403 const char *units; /**< units of the values */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200404 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200405 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
406 const char **dflts; /**< list of default values (NULL-terminated) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200407 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200408};
409
410struct lysp_deviate_rpl {
411 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
412 struct lysp_deviate *next; /**< next deviate structure in the list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200413 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
414 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200415 const char *units; /**< units of the values */
416 const char *dflt; /**< default value */
417 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
418 uint32_t min; /**< min-elements constraint */
419 uint32_t max; /**< max-elements constraint, 0 means unbounded */
420};
421
422struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200423 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200424 const char *dsc; /**< description statement */
425 const char *ref; /**< reference statement */
426 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200427 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200428};
429
Michal Vaskob55f6c12018-09-12 11:13:15 +0200430#define LYS_CONFIG_W 0x01 /**< config true; */
431#define LYS_CONFIG_R 0x02 /**< config false; */
432#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
433#define LYS_STATUS_CURR 0x08 /**< status current; */
434#define LYS_STATUS_DEPRC 0x10 /**< status deprecated; */
435#define LYS_STATUS_OBSLT 0x20 /**< status obsolete; */
436#define LYS_STATUS_MASK 0x38 /**< mask for status value */
437#define LYS_MAND_TRUE 0x40 /**< mandatory true; applicable only to
438 ::lys_node_choice, ::lys_node_leaf and ::lys_node_anydata */
439#define LYS_MAND_FALSE 0x80 /**< mandatory false; applicable only to
440 ::lys_node_choice, ::lys_node_leaf and ::lys_node_anydata */
441#define LYS_MAND_MASK 0xc0 /**< mask for mandatory values */
442#define LYS_ORDBY_SYSTEM 0x100 /**< ordered-by system lists, applicable only to
443 ::lys_node_list and ::lys_node_leaflist */
444#define LYS_ORDBY_USER 0x200 /**< ordered-by user lists, applicable only to
445 ::lys_node_list and ::lys_node_leaflist */
446#define LYS_ORDBY_MASK 0x300 /**< mask for ordered-by flags */
447#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lys_feature */
448#define LYS_AUTOASSIGNED 0x01 /**< value was auto-assigned, applicable only to
449 ::lys_type enum and bits flags */
450#define LYS_YINELEM_TRUE 0x01 /**< yin-element true for extension's argument */
451#define LYS_YINELEM_FALSE 0x02 /**< yin-element false for extension's argument */
452#define LYS_YINELEM_MASK 0x03 /**< mask for yin-element value */
453#define LYS_SET_VALUE 0x01 /**< value attribute is set */
454#define LYS_SET_MAX 0x400 /**< max attribute is set */
455#define LYS_SET_MIN 0x800 /**< min attribute is set */
456#define LYS_SET_REQINST 0x01 /**< require_instance attribute is set */
457
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200458/**
459 * @brief Generic YANG data node
460 */
461struct lysp_node {
462 uint16_t nodetype; /**< type of the node (mandatory) */
463 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
464 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
465 const char *name; /**< node name (mandatory) */
466 const char *dsc; /**< description statement */
467 const char *ref; /**< reference statement */
468 struct lysp_when *when; /**< when statement */
469 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200470 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200471};
472
473/**
474 * @brief Extension structure of the lysp_node for YANG container
475 */
476struct lysp_node_container {
477 uint16_t nodetype; /**< LYS_CONTAINER */
478 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
479 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
480 const char *name; /**< node name (mandatory) */
481 const char *dsc; /**< description statement */
482 const char *ref; /**< reference statement */
483 struct lysp_when *when; /**< when statement */
484 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200485 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200486
487 /* container */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200488 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200489 const char *presence; /**< presence description */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200490 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
491 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200492 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200493 struct lysp_action *actions; /**< list of actions (0-terminated) */
494 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200495};
496
497struct lysp_node_leaf {
498 uint16_t nodetype; /**< LYS_LEAF */
499 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
500 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
501 const char *name; /**< node name (mandatory) */
502 const char *dsc; /**< description statement */
503 const char *ref; /**< reference statement */
504 struct lysp_when *when; /**< when statement */
505 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200506 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200507
508 /* leaf */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200509 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200510 struct lysp_type type; /**< type of the leaf node (mandatory) */
511 const char *units; /**< units of the leaf's type */
512 const char *dflt; /**< default value */
513};
514
515struct lysp_node_leaflist {
516 uint16_t nodetype; /**< LYS_LEAFLIST */
517 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
518 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
519 const char *name; /**< node name (mandatory) */
520 const char *dsc; /**< description statement */
521 const char *ref; /**< reference statement */
522 struct lysp_when *when; /**< when statement */
523 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200524 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200525
526 /* leaf-list */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200527 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200528 struct lysp_type type; /**< type of the leaf node (mandatory) */
529 const char *units; /**< units of the leaf's type */
530 const char **dflts; /**< list of default values (NULL-terminated) */
531 uint32_t min; /**< min-elements constraint */
532 uint32_t max; /**< max-elements constraint, 0 means unbounded */
533};
534
535struct lysp_node_list {
536 uint16_t nodetype; /**< LYS_LIST */
537 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
538 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
539 const char *name; /**< node name (mandatory) */
540 const char *dsc; /**< description statement */
541 const char *ref; /**< reference statement */
542 struct lysp_when *when; /**< when statement */
543 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200544 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200545
546 /* list */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200547 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200548 const char *key; /**< keys specification */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200549 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
550 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200551 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200552 struct lysp_action *actions; /**< list of actions (0-terminated) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200553 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200554 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
555 uint32_t min; /**< min-elements constraint */
556 uint32_t max; /**< max-elements constraint, 0 means unbounded */
557};
558
559struct lysp_node_choice {
560 uint16_t nodetype; /**< LYS_CHOICE */
561 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
562 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
563 const char *name; /**< node name (mandatory) */
564 const char *dsc; /**< description statement */
565 const char *ref; /**< reference statement */
566 struct lysp_when *when; /**< when statement */
567 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200568 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200569
570 /* choice */
571 struct lysp_node *child; /**< list of data nodes (linked list) */
572 const char* dflt; /**< default case */
573};
574
575struct lysp_node_case {
576 uint16_t nodetype; /**< LYS_CASE */
577 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
578 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
579 const char *name; /**< node name (mandatory) */
580 const char *dsc; /**< description statement */
581 const char *ref; /**< reference statement */
582 struct lysp_when *when; /**< when statement */
583 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200584 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200585
586 /* case */
587 struct lysp_node *child; /**< list of data nodes (linked list) */
588};
589
590struct lysp_node_anydata {
591 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
592 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
593 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
594 const char *name; /**< node name (mandatory) */
595 const char *dsc; /**< description statement */
596 const char *ref; /**< reference statement */
597 struct lysp_when *when; /**< when statement */
598 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200599 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200600
601 /* anyxml/anydata */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200602 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200603};
604
605struct lysp_node_uses {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200606 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200607 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
608 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
609 const char *name; /**< grouping name reference (mandatory) */
610 const char *dsc; /**< description statement */
611 const char *ref; /**< reference statement */
612 struct lysp_when *when; /**< when statement */
613 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200614 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200615
616 /* uses */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200617 struct lysp_refine *refines; /**< list of uses's refines (0-terminated) */
618 struct lysp_augment *augments; /**< list of uses's augment (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200619};
620
621/**
622 * @brief YANG input-stmt and output-stmt
623 */
624struct lysp_action_inout {
Michal Vaskobc2559f2018-09-07 10:17:50 +0200625 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
626 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
627 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200628 struct lysp_node *data; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200629 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200630};
631
632/**
633 * @brief YANG rpc-stmt and action-stmt
634 */
635struct lysp_action {
636 const char *name; /**< grouping name reference (mandatory) */
637 const char *dsc; /**< description statement */
638 const char *ref; /**< reference statement */
639 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200640 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
641 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200642 struct lysp_action_inout *input; /**< RPC's/Action's input */
643 struct lysp_action_inout *output;/**< RPC's/Action's output */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200644 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200645 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
646};
647
648/**
649 * @brief YANG notification-stmt
650 */
651struct lysp_notif {
652 const char *name; /**< grouping name reference (mandatory) */
653 const char *dsc; /**< description statement */
654 const char *ref; /**< reference statement */
655 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200656 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
657 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
658 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200659 struct lysp_node *data; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200660 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200661 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
662};
663
664/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200665 * @brief supported YANG schema version values
666 */
667typedef enum LYS_VERSION {
668 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
669 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
670 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
671} LYS_VERSION;
672
673/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200674 * @brief Printable YANG schema tree structure representing YANG module.
675 *
676 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
677 */
678struct lysp_module {
679 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
680 const char *name; /**< name of the module (mandatory) */
681 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
682 union {
683 /* module */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200684 const char *ns; /**< namespace of the module (module - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200685 /* submodule */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200686 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200687 };
Michal Vaskod5927ca2018-09-07 15:05:32 +0200688 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200689 struct lysp_import *imports; /**< list of imported modules (0-terminated) */
690 struct lysp_include *includes; /**< list of included submodules (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200691 const char *org; /**< party/company responsible for the module */
692 const char *contact; /**< contact information for the module */
693 const char *dsc; /**< description of the module */
694 const char *ref; /**< cross-reference for the module */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200695 struct lysp_revision *revs; /**< list of the module revisions (0-terminated), the first revision
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200696 in the list is always the last (newest) revision of the module */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200697 struct lysp_ext *extensions; /**< list of extension statements (0-terminated) */
698 struct lysp_feature *features; /**< list of feature definitions (0-terminated) */
699 struct lysp_ident *identities; /**< list of identities (0-terminated) */
700 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
701 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200702 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200703 struct lysp_augment *augments; /**< list of augments (0-terminated) */
704 struct lysp_action *rpcs; /**< list of RPCs (0-terminated) */
705 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
706 struct lysp_deviation *deviations; /**< list of deviations (0-terminated) */
707 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200708
Radek Krejcif0fceb62018-09-05 14:58:45 +0200709 uint8_t submodule:1; /**< flag to distinguish main modules and submodules */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200710 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
711 uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is
712 the latest revision found */
Radek Krejcif0fceb62018-09-05 14:58:45 +0200713 uint8_t version:4; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200714};
715
716/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200717 * @brief Free the printable YANG schema tree structure.
718 *
719 * @param[in] module Printable YANG schema tree structure to free.
720 */
721void lysp_module_free(struct lysp_module *module);
722
723/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200724 * @brief Compiled YANG schema tree structure representing YANG module.
725 *
726 * Semantically validated YANG schema tree for data tree parsing.
727 * Contains only the necessary information for the data validation.
728 */
729struct lysc_module {
730};
731
732/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200733 * @brief Compiled YANG data node
734 */
735struct lysc_node {
736};
737
738/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200739 * @brief Available YANG schema tree structures representing YANG module.
740 */
741struct lys_module {
742 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
743 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing */
744};
745
746/** @} */
747
748#endif /* LY_TREE_SCHEMA_H_ */