blob: 6f3c82c2fd115813855023a00b883dae305131cc [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 Krejci5aeea3a2018-09-05 13:29:36 +020030 * @defgroup schematree Schema Tree
31 * @{
32 *
33 * Data structures and functions to manipulate and access schema tree.
34 */
35
Radek Krejci0af5f5d2018-09-07 15:00:30 +020036/**
Radek Krejci5fac3592018-10-12 15:23:45 +020037 * @brief Helper macro to go through 0-terminated arrays
38 *
39 * Use with opening curly bracket '{'.
40 *
41 * @param[in] ARRAY Array to go through
42 * @param[out] ITER Numeric iterator storing available indexes of the ARRAY
43 */
Michal Vasko4f3980b2018-10-15 10:50:48 +020044#define LY_ARRAY_FOR(ARRAY, ITER) for (ITER = 0; (ARRAY) && *((void **)((ARRAY) + ITER)); ++ITER)
Radek Krejci5fac3592018-10-12 15:23:45 +020045
46/**
47 * @brief Macro to iterate via all sibling elements without affecting the list itself
48 *
49 * Works for all types of nodes despite it is data or schema tree, but all the
50 * parameters must be pointers to the same type.
51 *
52 * Use with opening curly bracket '{'. All parameters must be of the same type.
53 *
54 * @param START Pointer to the starting element.
55 * @param ELEM Iterator.
56 */
57#define LY_LIST_FOR(START, ELEM) \
58 for ((ELEM) = (START); \
59 (ELEM); \
60 (ELEM) = (ELEM)->next)
61
62/**
63 * @ingroup datatree
64 * @brief Macro to iterate via all sibling elements allowing to modify the list itself (e.g. removing elements)
65 *
66 * Use with opening curly bracket '{'. All parameters must be of the same type.
67 *
68 * @param START Pointer to the starting element.
69 * @param NEXT Temporary storage to allow removing of the current iterator content.
70 * @param ELEM Iterator.
71 */
72#define LY_LIST_FOR_SAFE(START, NEXT, ELEM) \
73 for ((ELEM) = (START); \
74 (ELEM) ? (NEXT = (ELEM)->next, 1) : 0; \
75 (ELEM) = (NEXT))
76
77/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +020078 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
79 */
80typedef enum {
81 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
82 LYS_IN_YANG = 1, /**< YANG schema input format */
83 LYS_IN_YIN = 2 /**< YIN schema input format */
84} LYS_INFORMAT;
85
86/**
87 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
88 */
89typedef enum {
90 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
91 LYS_OUT_YANG = 1, /**< YANG schema output format */
92 LYS_OUT_YIN = 2, /**< YIN schema output format */
93 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
94 LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
95 LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */
96} LYS_OUTFORMAT;
97
Radek Krejci5aeea3a2018-09-05 13:29:36 +020098#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
99
Michal Vaskob55f6c12018-09-12 11:13:15 +0200100#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
101#define LYS_CONTAINER 0x0001 /**< container statement node */
102#define LYS_CHOICE 0x0002 /**< choice statement node */
103#define LYS_LEAF 0x0004 /**< leaf statement node */
104#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
105#define LYS_LIST 0x0010 /**< list statement node */
106#define LYS_ANYXML 0x0020 /**< anyxml statement node */
107#define LYS_CASE 0x0040 /**< case statement node */
108#define LYS_USES 0x0080 /**< uses statement node */
109#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 +0200110
111/**
112 * @brief YANG import-stmt
113 */
114struct lysp_import {
Michal Vaskod5927ca2018-09-07 15:05:32 +0200115 const char *name; /**< name of the module to import (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200116 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200117 const char *dsc; /**< description */
118 const char *ref; /**< reference */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200119 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200120 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
121};
122
123/**
124 * @brief YANG include-stmt
125 */
126struct lysp_include {
Michal Vaskod5927ca2018-09-07 15:05:32 +0200127 const char *name; /**< name of the submodule to include (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200128 const char *dsc; /**< description */
129 const char *ref; /**< reference */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200130 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200131 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
132};
133
134/**
135 * @brief YANG extension-stmt
136 */
137struct lysp_ext {
138 const char *name; /**< extension name */
139 const char *argument; /**< argument name, NULL if not specified */
140 const char *dsc; /**< description statement */
141 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200142 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200143 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
144};
145
146/**
147 * @brief Helper structure for generic storage of the extension instances content.
148 */
149struct lysp_stmt {
150 const char *stmt; /**< identifier of the statement */
151 const char *arg; /**< statement's argument */
152 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200153 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200154};
155
156/**
Michal Vaskod92e42a2018-09-07 08:35:02 +0200157 * @brief Enum of substatements in which extension instances can appear.
158 */
159typedef enum {
160 LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */
161 LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */
162 LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */
163 LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */
164 LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */
165 LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist,
166 lys_node_choice and lys_deviate */
167 LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule,
168 lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr,
169 lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */
170 LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */
171 LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */
172 LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */
173 LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */
174 LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */
175 LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */
176 LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for
177 belongs-to's prefix) and lys_import */
178 LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */
179 LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule,
180 lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident,
181 lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */
182 LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */
183 LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf,
184 lys_node_leaflist and lys_deviate */
185 LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */
186 LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */
187 LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */
188 LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */
189 LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */
190 LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */
191 LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice,
192 lys_node_anydata and lys_deviate */
193 LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */
194 LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident,
195 lys_ext, lys_feature, lys_type_enum and lys_type_bit */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200196 LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200197 LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list,
198 lys_node_leaflist and lys_deviate */
199 LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list,
200 lys_node_leaflist and lys_deviate */
201 LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */
202 LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200203 LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200204} LYEXT_SUBSTMT;
205
206/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200207 * @brief YANG extension instance
208 */
209struct lysp_ext_instance {
210 const char *name; /**< extension identifier, including possible prefix */
211 const char *argument; /**< optional value of the extension's argument */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200212 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
213 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
214 the index of that substatement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200215 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200216};
217
218/**
219 * @brief YANG feature-stmt
220 */
221struct lysp_feature {
222 const char *name; /**< feature name (mandatory) */
223 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
224 const char *dsc; /**< description statement */
225 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200226 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200227 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
228};
229
230/**
231 * @brief YANG identity-stmt
232 */
233struct lysp_ident {
234 const char *name; /**< identity name (mandatory), including possible prefix */
235 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
236 const char **bases; /**< list of base identifiers (NULL-terminated) */
237 const char *dsc; /**< description statement */
238 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200239 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200240 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
241};
242
Michal Vasko71e64ca2018-09-07 16:30:29 +0200243/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200244 * @brief Covers restrictions: range, length, pattern, must
245 */
246struct lysp_restr {
247 const char *arg; /**< The restriction expression/value (mandatory);
248 in case of pattern restriction, the first byte has a special meaning:
249 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
250 const char *emsg; /**< error-message */
251 const char *eapptag; /**< error-app-tag value */
252 const char *dsc; /**< description */
253 const char *ref; /**< reference */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200254 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200255};
256
257/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200258 * @brief YANG revision-stmt
259 */
260struct lysp_revision {
261 char rev[LY_REV_SIZE]; /**< revision date (madatory) */
262 const char *dsc; /**< description statement */
263 const char *ref; /**< reference statement */
264 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
265};
266
267/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200268 * @brief Enumeration/Bit value definition
269 */
270struct lysp_type_enum {
271 const char *name; /**< name (mandatory) */
272 const char *dsc; /**< description statement */
273 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200274 int64_t value; /**< enum's value or bit's position */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200275 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200276 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200277 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
278 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200279};
280
281/**
282 * @brief YANG type-stmt
283 *
284 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
285 */
286struct lysp_type {
287 const char *name; /**< name of the type (mandatory) */
288 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
289 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200290 struct lysp_restr *patterns; /**< list of patterns (0-terminated) - string */
291 struct lysp_type_enum *enums; /**< list of enum-stmts (0-terminated) - enum */
292 struct lysp_type_enum *bits; /**< list of bit-stmts (0-terminated) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200293 const char *path; /**< path - leafref */
294 const char **bases; /**< list of base identifiers (NULL-terminated) - identityref */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200295 struct lysp_type *types; /**< list of sub-types (0-terminated) - union */
296 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200297
298 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
299 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200300 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_SET_REQINST allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200301};
302
303/**
304 * @brief YANG typedef-stmt
305 */
306struct lysp_tpdf {
307 const char *name; /**< name of the newly defined type (mandatory) */
308 const char *units; /**< units of the newly defined type */
309 const char *dflt; /**< default value of the newly defined type */
310 const char *dsc; /**< description statement */
311 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200312 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200313 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
314 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
315};
316
317/**
318 * @brief YANG grouping-stmt
319 */
320struct lysp_grp {
321 const char *name; /**< grouping name (mandatory) */
322 const char *dsc; /**< description statement */
323 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200324 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
325 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200326 struct lysp_node *data; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200327 struct lysp_action *actions; /**< list of actions (0-terminated) */
328 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
329 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200330 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
331};
332
333/**
334 * @brief YANG when-stmt
335 */
336struct lysp_when {
337 const char *cond; /**< specified condition (mandatory) */
338 const char *dsc; /**< description statement */
339 const char *ref; /**< reference statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200340 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200341};
342
343/**
344 * @brief YANG refine-stmt
345 */
346struct lysp_refine {
347 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
348 const char *dsc; /**< description statement */
349 const char *ref; /**< reference statement */
350 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200351 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200352 const char *presence; /**< presence description */
353 const char **dflts; /**< list of default values (NULL-terminated) */
354 uint32_t min; /**< min-elements constraint */
355 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200356 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200357 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
358};
359
360/**
361 * @brief YANG uses-augment-stmt and augment-stmt
362 */
363struct lysp_augment {
364 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
365 const char *dsc; /**< description statement */
366 const char *ref; /**< reference statement */
367 struct lysp_when *when; /**< when statement */
368 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
369 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200370 struct lysp_action *actions; /**< list of actions (0-terminated) */
371 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
372 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200373 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
374};
375
376/**
377 * @defgroup deviatetypes Deviate types
378 * @{
379 */
380#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
381#define LYS_DEV_ADD 2 /**< deviate type add */
382#define LYS_DEV_DELETE 3 /**< deviate type delete */
383#define LYS_DEV_REPLACE 4 /**< deviate type replace */
384/** @} */
385
386/**
387 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
388 */
389struct lysp_deviate {
390 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
391 struct lysp_deviate *next; /**< next deviate structure in the list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200392 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200393};
394
395struct lysp_deviate_add {
396 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
397 struct lysp_deviate *next; /**< next deviate structure in the list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200398 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
399 const char *units; /**< units of the values */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200400 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200401 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
402 const char **dflts; /**< list of default values (NULL-terminated) */
403 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
404 uint32_t min; /**< min-elements constraint */
405 uint32_t max; /**< max-elements constraint, 0 means unbounded */
406};
407
408struct lysp_deviate_del {
409 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
410 struct lysp_deviate *next; /**< next deviate structure in the list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200411 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
412 const char *units; /**< units of the values */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200413 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200414 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
415 const char **dflts; /**< list of default values (NULL-terminated) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200416 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200417};
418
419struct lysp_deviate_rpl {
420 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
421 struct lysp_deviate *next; /**< next deviate structure in the list */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200422 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
423 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200424 const char *units; /**< units of the values */
425 const char *dflt; /**< default value */
426 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
427 uint32_t min; /**< min-elements constraint */
428 uint32_t max; /**< max-elements constraint, 0 means unbounded */
429};
430
431struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200432 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200433 const char *dsc; /**< description statement */
434 const char *ref; /**< reference statement */
435 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200436 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200437};
438
Michal Vaskob55f6c12018-09-12 11:13:15 +0200439#define LYS_CONFIG_W 0x01 /**< config true; */
440#define LYS_CONFIG_R 0x02 /**< config false; */
441#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
442#define LYS_STATUS_CURR 0x08 /**< status current; */
443#define LYS_STATUS_DEPRC 0x10 /**< status deprecated; */
444#define LYS_STATUS_OBSLT 0x20 /**< status obsolete; */
445#define LYS_STATUS_MASK 0x38 /**< mask for status value */
446#define LYS_MAND_TRUE 0x40 /**< mandatory true; applicable only to
447 ::lys_node_choice, ::lys_node_leaf and ::lys_node_anydata */
448#define LYS_MAND_FALSE 0x80 /**< mandatory false; applicable only to
449 ::lys_node_choice, ::lys_node_leaf and ::lys_node_anydata */
450#define LYS_MAND_MASK 0xc0 /**< mask for mandatory values */
451#define LYS_ORDBY_SYSTEM 0x100 /**< ordered-by system lists, applicable only to
452 ::lys_node_list and ::lys_node_leaflist */
453#define LYS_ORDBY_USER 0x200 /**< ordered-by user lists, applicable only to
454 ::lys_node_list and ::lys_node_leaflist */
455#define LYS_ORDBY_MASK 0x300 /**< mask for ordered-by flags */
456#define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lys_feature */
457#define LYS_AUTOASSIGNED 0x01 /**< value was auto-assigned, applicable only to
458 ::lys_type enum and bits flags */
459#define LYS_YINELEM_TRUE 0x01 /**< yin-element true for extension's argument */
460#define LYS_YINELEM_FALSE 0x02 /**< yin-element false for extension's argument */
461#define LYS_YINELEM_MASK 0x03 /**< mask for yin-element value */
462#define LYS_SET_VALUE 0x01 /**< value attribute is set */
463#define LYS_SET_MAX 0x400 /**< max attribute is set */
464#define LYS_SET_MIN 0x800 /**< min attribute is set */
465#define LYS_SET_REQINST 0x01 /**< require_instance attribute is set */
466
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200467/**
468 * @brief Generic YANG data node
469 */
470struct lysp_node {
471 uint16_t nodetype; /**< type of the node (mandatory) */
472 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
473 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
474 const char *name; /**< node name (mandatory) */
475 const char *dsc; /**< description statement */
476 const char *ref; /**< reference statement */
477 struct lysp_when *when; /**< when statement */
478 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200479 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200480};
481
482/**
483 * @brief Extension structure of the lysp_node for YANG container
484 */
485struct lysp_node_container {
486 uint16_t nodetype; /**< LYS_CONTAINER */
487 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
488 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
489 const char *name; /**< node name (mandatory) */
490 const char *dsc; /**< description statement */
491 const char *ref; /**< reference statement */
492 struct lysp_when *when; /**< when statement */
493 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200494 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200495
496 /* container */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200497 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200498 const char *presence; /**< presence description */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200499 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
500 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200501 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200502 struct lysp_action *actions; /**< list of actions (0-terminated) */
503 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200504};
505
506struct lysp_node_leaf {
507 uint16_t nodetype; /**< LYS_LEAF */
508 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
509 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
510 const char *name; /**< node name (mandatory) */
511 const char *dsc; /**< description statement */
512 const char *ref; /**< reference statement */
513 struct lysp_when *when; /**< when statement */
514 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200515 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200516
517 /* leaf */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200518 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200519 struct lysp_type type; /**< type of the leaf node (mandatory) */
520 const char *units; /**< units of the leaf's type */
521 const char *dflt; /**< default value */
522};
523
524struct lysp_node_leaflist {
525 uint16_t nodetype; /**< LYS_LEAFLIST */
526 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
527 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
528 const char *name; /**< node name (mandatory) */
529 const char *dsc; /**< description statement */
530 const char *ref; /**< reference statement */
531 struct lysp_when *when; /**< when statement */
532 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200533 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200534
535 /* leaf-list */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200536 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200537 struct lysp_type type; /**< type of the leaf node (mandatory) */
538 const char *units; /**< units of the leaf's type */
539 const char **dflts; /**< list of default values (NULL-terminated) */
540 uint32_t min; /**< min-elements constraint */
541 uint32_t max; /**< max-elements constraint, 0 means unbounded */
542};
543
544struct lysp_node_list {
545 uint16_t nodetype; /**< LYS_LIST */
546 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
547 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
548 const char *name; /**< node name (mandatory) */
549 const char *dsc; /**< description statement */
550 const char *ref; /**< reference statement */
551 struct lysp_when *when; /**< when statement */
552 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200553 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200554
555 /* list */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200556 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200557 const char *key; /**< keys specification */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200558 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
559 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200560 struct lysp_node *child; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200561 struct lysp_action *actions; /**< list of actions (0-terminated) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200562 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200563 const char **uniques; /**< list of uniques specifications (NULL-terminated) */
564 uint32_t min; /**< min-elements constraint */
565 uint32_t max; /**< max-elements constraint, 0 means unbounded */
566};
567
568struct lysp_node_choice {
569 uint16_t nodetype; /**< LYS_CHOICE */
570 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
571 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
572 const char *name; /**< node name (mandatory) */
573 const char *dsc; /**< description statement */
574 const char *ref; /**< reference statement */
575 struct lysp_when *when; /**< when statement */
576 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200577 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200578
579 /* choice */
580 struct lysp_node *child; /**< list of data nodes (linked list) */
581 const char* dflt; /**< default case */
582};
583
584struct lysp_node_case {
585 uint16_t nodetype; /**< LYS_CASE */
586 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
587 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
588 const char *name; /**< node name (mandatory) */
589 const char *dsc; /**< description statement */
590 const char *ref; /**< reference statement */
591 struct lysp_when *when; /**< when statement */
592 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200593 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200594
595 /* case */
596 struct lysp_node *child; /**< list of data nodes (linked list) */
597};
598
599struct lysp_node_anydata {
600 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
601 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
602 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
603 const char *name; /**< node name (mandatory) */
604 const char *dsc; /**< description statement */
605 const char *ref; /**< reference statement */
606 struct lysp_when *when; /**< when statement */
607 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200608 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200609
610 /* anyxml/anydata */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200611 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200612};
613
614struct lysp_node_uses {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200615 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200616 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; /**< grouping name reference (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) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200623 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200624
625 /* uses */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200626 struct lysp_refine *refines; /**< list of uses's refines (0-terminated) */
627 struct lysp_augment *augments; /**< list of uses's augment (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200628};
629
630/**
631 * @brief YANG input-stmt and output-stmt
632 */
633struct lysp_action_inout {
Michal Vaskobc2559f2018-09-07 10:17:50 +0200634 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
635 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
636 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200637 struct lysp_node *data; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200638 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200639};
640
641/**
642 * @brief YANG rpc-stmt and action-stmt
643 */
644struct lysp_action {
645 const char *name; /**< grouping name reference (mandatory) */
646 const char *dsc; /**< description statement */
647 const char *ref; /**< reference statement */
648 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200649 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
650 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200651 struct lysp_action_inout *input; /**< RPC's/Action's input */
652 struct lysp_action_inout *output;/**< RPC's/Action's output */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200653 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200654 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
655};
656
657/**
658 * @brief YANG notification-stmt
659 */
660struct lysp_notif {
661 const char *name; /**< grouping name reference (mandatory) */
662 const char *dsc; /**< description statement */
663 const char *ref; /**< reference statement */
664 const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200665 struct lysp_restr *musts; /**< list of must restrictions (0-terminated) */
666 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
667 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200668 struct lysp_node *data; /**< list of data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200669 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200670 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
671};
672
673/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200674 * @brief supported YANG schema version values
675 */
676typedef enum LYS_VERSION {
677 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
678 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
679 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
680} LYS_VERSION;
681
682/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200683 * @brief Printable YANG schema tree structure representing YANG module.
684 *
685 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
686 */
687struct lysp_module {
688 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
689 const char *name; /**< name of the module (mandatory) */
690 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
691 union {
692 /* module */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200693 const char *ns; /**< namespace of the module (module - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200694 /* submodule */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200695 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200696 };
Michal Vaskod5927ca2018-09-07 15:05:32 +0200697 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200698 struct lysp_import *imports; /**< list of imported modules (0-terminated) */
699 struct lysp_include *includes; /**< list of included submodules (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200700 const char *org; /**< party/company responsible for the module */
701 const char *contact; /**< contact information for the module */
702 const char *dsc; /**< description of the module */
703 const char *ref; /**< cross-reference for the module */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200704 struct lysp_revision *revs; /**< list of the module revisions (0-terminated), the first revision
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200705 in the list is always the last (newest) revision of the module */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200706 struct lysp_ext *extensions; /**< list of extension statements (0-terminated) */
707 struct lysp_feature *features; /**< list of feature definitions (0-terminated) */
708 struct lysp_ident *identities; /**< list of identities (0-terminated) */
709 struct lysp_tpdf *typedefs; /**< list of typedefs (0-terminated) */
710 struct lysp_grp *groupings; /**< list of groupings (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200711 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200712 struct lysp_augment *augments; /**< list of augments (0-terminated) */
713 struct lysp_action *rpcs; /**< list of RPCs (0-terminated) */
714 struct lysp_notif *notifs; /**< list of notifications (0-terminated) */
715 struct lysp_deviation *deviations; /**< list of deviations (0-terminated) */
716 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200717
Radek Krejcif0fceb62018-09-05 14:58:45 +0200718 uint8_t submodule:1; /**< flag to distinguish main modules and submodules */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200719 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
720 uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is
721 the latest revision found */
Radek Krejcif0fceb62018-09-05 14:58:45 +0200722 uint8_t version:4; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200723};
724
725/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200726 * @brief Free the printable YANG schema tree structure.
727 *
728 * @param[in] module Printable YANG schema tree structure to free.
729 */
730void lysp_module_free(struct lysp_module *module);
731
732/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200733 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200734 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200735struct lysc_when {
736 struct lyxp_expr *cond; /**< XPath when condition */
737 struct lysc_ext_instance *exts; /**< list of the extension instances (0-terminated) */
738};
739
740/**
741 * @brief YANG feature-stmt
742 */
743struct lysc_feature {
744 const char *name; /**< feature name (mandatory) */
745 struct lysc_feature *depfeatures;/**< list of other features depending on this one (0-terminated) */
746 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions (0-terminated) */
747 struct lysp_ext_instance *exts; /**< list of the extension instances (0-terminated) */
748 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
749 #LYS_FENABLED values allowed */
750};
751
752struct lysc_iffeature {
753 struct lysc_feature *features; /**< array of pointers to the features used in expression, size depends on content of expr */
754 uint32_t expr[]; /**< 2bits array describing the if-feature expression in prefix format */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200755};
756
757/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200758 * @brief Compiled YANG data node
759 */
760struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200761 uint16_t nodetype; /**< type of the node (mandatory) */
762 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
763 struct lysp_node *sp; /**< link to the simply parsed (SP) original of the node, NULL if the SP schema was removed. */
764 struct lysc_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
765 const char *name; /**< node name (mandatory) */
766 struct lysc_when *when; /**< when statement */
767 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions (0-terminated) */
768 struct lysc_ext_instance *exts; /**< list of the extension instances (0-terminated) */
769};
770
771/**
772 * @brief Compiled YANG schema tree structure representing YANG module.
773 *
774 * Semantically validated YANG schema tree for data tree parsing.
775 * Contains only the necessary information for the data validation.
776 */
777struct lysc_module {
778 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
779 const char *name; /**< name of the module (mandatory) */
780 const char *ns; /**< namespace of the module (mandatory) */
781 const char *prefix; /**< module prefix (mandatory) */
782
783
784 struct lysc_feature *features; /**< list of feature definitions (0-terminated) */
785
786
787 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
788 uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is
789 the latest revision found */
790 uint8_t version:4; /**< yang-version (LYS_VERSION values) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200791};
792
793/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200794 * @brief Available YANG schema tree structures representing YANG module.
795 */
796struct lys_module {
797 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
798 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing */
799};
800
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200801
802/**
803 * @defgroup scflags Schema compile flags
804 * @ingroup schematree
805 *
806 * @{
807 */
808#define LYSC_OPT_FREE_SP 1 /**< Free the input printable schema */
809
810/**
811 * @}
812 */
813
814/**
815 * @brief Compile printable schema into a validated schema linking all the references.
816 *
817 * @param[in] sp Simple parsed printable schema to compile. Can be changed according to the provided options.
818 * @param[in] options Various options to modify compiler behavior, see [compile flags](@ref scflags).
819 * @param[out] sc Resulting compiled schema structure.
820 * @return LY_ERR value.
821 */
822LY_ERR lys_compile(struct lysp_module *sp, int options, struct lysc_module **sc);
823
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200824/** @} */
825
Radek Krejci70853c52018-10-15 14:46:16 +0200826#ifdef __cplusplus
827}
828#endif
829
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200830#endif /* LY_TREE_SCHEMA_H_ */