blob: e685f8c80fa67392def7ed20fea2d32312766750 [file] [log] [blame]
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001/**
2 * @file tree_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief libyang representation of YANG schema trees.
5 *
6 * Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_TREE_SCHEMA_H_
16#define LY_TREE_SCHEMA_H_
17
Radek Krejci2167ee12018-11-02 16:09:07 +010018#include <pcre.h>
Radek Krejci5aeea3a2018-09-05 13:29:36 +020019#include <stdint.h>
20
Radek Krejcice8c1592018-10-29 15:35:51 +010021#include "extensions.h"
22
Radek Krejci70853c52018-10-15 14:46:16 +020023#ifdef __cplusplus
24extern "C" {
25#endif
26
Radek Krejci5aeea3a2018-09-05 13:29:36 +020027/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +020028 * @brief XPath representation.
29 */
30struct lyxp_expr;
31
32/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020033 * @brief Macro selector for other LY_ARRAY_* macros, do not use directly!
34 */
35#define LY_ARRAY_SELECT(_1, _2, NAME, ...) NAME
36
37/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020038 * @brief Helper macro to go through sized-arrays with a pointer iterator.
39 *
40 * Use with opening curly bracket (`{`).
41 *
42 * @param[in] ARRAY Array to go through
43 * @param[in] TYPE Type of the records in the ARRAY
44 * @param[out] ITER Iterating pointer to the item being processed in each loop
45 */
46#define LY_ARRAY_FOR_ITER(ARRAY, TYPE, ITER) \
Radek Krejci2c4e7172018-10-19 15:56:26 +020047 for (ITER = ARRAY; \
48 (ARRAY) && ((void*)ITER - (void*)ARRAY)/(sizeof(TYPE)) < (*((uint32_t*)(ARRAY) - 1)); \
Radek Krejcie53a8dc2018-10-17 12:52:40 +020049 ITER = (void*)((TYPE*)ITER + 1))
50
51/**
52 * @brief Helper macro to go through sized-arrays with a numeric iterator.
53 *
54 * Use with opening curly bracket (`{`).
55 *
56 * To access an item with the INDEX value, use always LY_ARRAY_INDEX macro!
57 *
58 * @param[in] ARRAY Array to go through
59 * @param[out] INDEX Iterating index of the item being processed in each loop
60 */
61#define LY_ARRAY_FOR_INDEX(ARRAY, INDEX) \
62 for (INDEX = 0; \
Radek Krejci2c4e7172018-10-19 15:56:26 +020063 ARRAY && INDEX < (*((uint32_t*)(ARRAY) - 1)); \
Radek Krejcie53a8dc2018-10-17 12:52:40 +020064 ++INDEX)
65
66/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +020067 * @defgroup schematree Schema Tree
68 * @{
69 *
70 * Data structures and functions to manipulate and access schema tree.
71 */
72
Radek Krejci0af5f5d2018-09-07 15:00:30 +020073/**
Radek Krejcie53a8dc2018-10-17 12:52:40 +020074 * @brief Get a number of records in the ARRAY.
Radek Krejci86d106e2018-10-18 09:53:19 +020075 *
76 * Does not check if array exists!
Radek Krejcie53a8dc2018-10-17 12:52:40 +020077 */
Radek Krejci2c4e7172018-10-19 15:56:26 +020078#define LY_ARRAY_SIZE(ARRAY) (*((uint32_t*)(ARRAY) - 1))
Radek Krejcie53a8dc2018-10-17 12:52:40 +020079
80/**
81 * @brief Sized-array iterator (for-loop).
82 *
83 * Use with opening curly bracket (`{`).
84 *
85 * There are 2 variants:
86 *
87 * LY_ARRAY_FOR(ARRAY, TYPE, ITER)
88 *
89 * Where ARRAY is a sized-array to go through, TYPE is the type of the items in the ARRAY and ITER is a pointer variable
90 * providing the items of the ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_ITER macro
91 *
92 * LY_ARRAY_FOR(ARRAY, INDEX)
93 *
94 * The ARRAY is again a sized-array to go through, the INDEX is a variable (unsigned integer) for storing iterating ARRAY's index
Radek Krejci2c4e7172018-10-19 15:56:26 +020095 * to access the items of ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_INDEX macro.
Radek Krejcie53a8dc2018-10-17 12:52:40 +020096 */
97#define LY_ARRAY_FOR(ARRAY, ...) LY_ARRAY_SELECT(__VA_ARGS__, LY_ARRAY_FOR_ITER, LY_ARRAY_FOR_INDEX)(ARRAY, __VA_ARGS__)
Radek Krejci5fac3592018-10-12 15:23:45 +020098
99/**
100 * @brief Macro to iterate via all sibling elements without affecting the list itself
101 *
102 * Works for all types of nodes despite it is data or schema tree, but all the
103 * parameters must be pointers to the same type.
104 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200105 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200106 *
107 * @param START Pointer to the starting element.
108 * @param ELEM Iterator.
109 */
110#define LY_LIST_FOR(START, ELEM) \
111 for ((ELEM) = (START); \
112 (ELEM); \
113 (ELEM) = (ELEM)->next)
114
115/**
Radek Krejci5fac3592018-10-12 15:23:45 +0200116 * @brief Macro to iterate via all sibling elements allowing to modify the list itself (e.g. removing elements)
117 *
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200118 * Use with opening curly bracket (`{`). All parameters must be of the same type.
Radek Krejci5fac3592018-10-12 15:23:45 +0200119 *
120 * @param START Pointer to the starting element.
121 * @param NEXT Temporary storage to allow removing of the current iterator content.
122 * @param ELEM Iterator.
123 */
124#define LY_LIST_FOR_SAFE(START, NEXT, ELEM) \
125 for ((ELEM) = (START); \
126 (ELEM) ? (NEXT = (ELEM)->next, 1) : 0; \
127 (ELEM) = (NEXT))
128
129/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +0200130 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
131 */
132typedef enum {
133 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
134 LYS_IN_YANG = 1, /**< YANG schema input format */
135 LYS_IN_YIN = 2 /**< YIN schema input format */
136} LYS_INFORMAT;
137
138/**
139 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
140 */
141typedef enum {
142 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
143 LYS_OUT_YANG = 1, /**< YANG schema output format */
144 LYS_OUT_YIN = 2, /**< YIN schema output format */
145 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
146 LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
147 LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */
148} LYS_OUTFORMAT;
149
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200150#define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */
151
Michal Vaskob55f6c12018-09-12 11:13:15 +0200152#define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */
153#define LYS_CONTAINER 0x0001 /**< container statement node */
154#define LYS_CHOICE 0x0002 /**< choice statement node */
155#define LYS_LEAF 0x0004 /**< leaf statement node */
156#define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */
157#define LYS_LIST 0x0010 /**< list statement node */
158#define LYS_ANYXML 0x0020 /**< anyxml statement node */
159#define LYS_CASE 0x0040 /**< case statement node */
160#define LYS_USES 0x0080 /**< uses statement node */
161#define LYS_ANYDATA 0x0120 /**< anydata statement node, in tests it can be used for both #LYS_ANYXML and #LYS_ANYDATA */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200162
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100163#define LYS_INOUT 0x200
164#define LYS_ACTION 0x400
165#define LYS_NOTIF 0x800
166#define LYS_GROUPING 0x1000
167#define LYS_AUGMENT 0x2000
168
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200169/**
Radek Krejci2167ee12018-11-02 16:09:07 +0100170 * @brief YANG built-in types
171 */
172typedef enum {
173 LY_TYPE_UNKNOWN = 0, /**< Unknown type */
174 LY_TYPE_BINARY, /**< Any binary data ([RFC 6020 sec 9.8](http://tools.ietf.org/html/rfc6020#section-9.8)) */
175 LY_TYPE_BITS, /**< A set of bits or flags ([RFC 6020 sec 9.7](http://tools.ietf.org/html/rfc6020#section-9.7)) */
176 LY_TYPE_BOOL, /**< "true" or "false" ([RFC 6020 sec 9.5](http://tools.ietf.org/html/rfc6020#section-9.5)) */
177 LY_TYPE_DEC64, /**< 64-bit signed decimal number ([RFC 6020 sec 9.3](http://tools.ietf.org/html/rfc6020#section-9.3))*/
178 LY_TYPE_EMPTY, /**< A leaf that does not have any value ([RFC 6020 sec 9.11](http://tools.ietf.org/html/rfc6020#section-9.11)) */
179 LY_TYPE_ENUM, /**< Enumerated strings ([RFC 6020 sec 9.6](http://tools.ietf.org/html/rfc6020#section-9.6)) */
180 LY_TYPE_IDENT, /**< A reference to an abstract identity ([RFC 6020 sec 9.10](http://tools.ietf.org/html/rfc6020#section-9.10)) */
181 LY_TYPE_INST, /**< References a data tree node ([RFC 6020 sec 9.13](http://tools.ietf.org/html/rfc6020#section-9.13)) */
182 LY_TYPE_LEAFREF, /**< A reference to a leaf instance ([RFC 6020 sec 9.9](http://tools.ietf.org/html/rfc6020#section-9.9))*/
183 LY_TYPE_STRING, /**< Human-readable string ([RFC 6020 sec 9.4](http://tools.ietf.org/html/rfc6020#section-9.4)) */
184 LY_TYPE_UNION, /**< Choice of member types ([RFC 6020 sec 9.12](http://tools.ietf.org/html/rfc6020#section-9.12)) */
185 LY_TYPE_INT8, /**< 8-bit signed integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
186 LY_TYPE_UINT8, /**< 8-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
187 LY_TYPE_INT16, /**< 16-bit signed integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
188 LY_TYPE_UINT16, /**< 16-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
189 LY_TYPE_INT32, /**< 32-bit signed integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
190 LY_TYPE_UINT32, /**< 32-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
191 LY_TYPE_INT64, /**< 64-bit signed integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
192 LY_TYPE_UINT64, /**< 64-bit unsigned integer ([RFC 6020 sec 9.2](http://tools.ietf.org/html/rfc6020#section-9.2)) */
193} LY_DATA_TYPE;
194#define LY_DATA_TYPE_COUNT 20 /**< Number of different types */
195
196/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200197 * @brief YANG import-stmt
198 */
199struct lysp_import {
Radek Krejci086c7132018-10-26 15:29:04 +0200200 struct lys_module *module; /**< pointer to the imported module
201 (mandatory, but resolved when the referring module is completely parsed) */
202 const char *name; /**< name of the imported module (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200203 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200204 const char *dsc; /**< description */
205 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200206 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200207 char rev[LY_REV_SIZE]; /**< revision-date of the imported module */
208};
209
210/**
211 * @brief YANG include-stmt
212 */
213struct lysp_include {
Radek Krejci086c7132018-10-26 15:29:04 +0200214 struct lysp_module *submodule; /**< pointer to the parsed submodule structure
215 (mandatory, but resolved when the referring module is completely parsed) */
216 const char *name; /**< name of the included submodule (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200217 const char *dsc; /**< description */
218 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200219 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200220 char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */
221};
222
223/**
224 * @brief YANG extension-stmt
225 */
226struct lysp_ext {
227 const char *name; /**< extension name */
228 const char *argument; /**< argument name, NULL if not specified */
229 const char *dsc; /**< description statement */
230 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200231 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200232 uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */
233};
234
235/**
236 * @brief Helper structure for generic storage of the extension instances content.
237 */
238struct lysp_stmt {
239 const char *stmt; /**< identifier of the statement */
240 const char *arg; /**< statement's argument */
241 struct lysp_stmt *next; /**< link to the next statement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200242 struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200243};
244
245/**
246 * @brief YANG extension instance
247 */
248struct lysp_ext_instance {
249 const char *name; /**< extension identifier, including possible prefix */
250 const char *argument; /**< optional value of the extension's argument */
Michal Vaskod92e42a2018-09-07 08:35:02 +0200251 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
252 uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies
253 the index of that substatement */
Michal Vaskobc2559f2018-09-07 10:17:50 +0200254 struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200255};
256
257/**
258 * @brief YANG feature-stmt
259 */
260struct lysp_feature {
261 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200262 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200263 const char *dsc; /**< description statement */
264 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200265 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200266 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */
267};
268
269/**
270 * @brief YANG identity-stmt
271 */
272struct lysp_ident {
273 const char *name; /**< identity name (mandatory), including possible prefix */
Radek Krejci151a5b72018-10-19 14:21:44 +0200274 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
275 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200276 const char *dsc; /**< description statement */
277 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200278 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200279 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
280};
281
Michal Vasko71e64ca2018-09-07 16:30:29 +0200282/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200283 * @brief Covers restrictions: range, length, pattern, must
284 */
285struct lysp_restr {
286 const char *arg; /**< The restriction expression/value (mandatory);
287 in case of pattern restriction, the first byte has a special meaning:
288 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */
289 const char *emsg; /**< error-message */
290 const char *eapptag; /**< error-app-tag value */
291 const char *dsc; /**< description */
292 const char *ref; /**< reference */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200293 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200294};
295
296/**
Michal Vasko71e64ca2018-09-07 16:30:29 +0200297 * @brief YANG revision-stmt
298 */
299struct lysp_revision {
Radek Krejcib7db73a2018-10-24 14:18:40 +0200300 char date[LY_REV_SIZE]; /**< revision date (madatory) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200301 const char *dsc; /**< description statement */
302 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200303 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vasko71e64ca2018-09-07 16:30:29 +0200304};
305
306/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200307 * @brief Enumeration/Bit value definition
308 */
309struct lysp_type_enum {
310 const char *name; /**< name (mandatory) */
311 const char *dsc; /**< description statement */
312 const char *ref; /**< reference statement */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200313 int64_t value; /**< enum's value or bit's position */
Radek Krejci151a5b72018-10-19 14:21:44 +0200314 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200315 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200316 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE
317 values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200318};
319
320/**
321 * @brief YANG type-stmt
322 *
323 * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first
324 */
325struct lysp_type {
326 const char *name; /**< name of the type (mandatory) */
327 struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */
328 struct lysp_restr *length; /**< allowed length of the value - string, binary */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200329 struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */
330 struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */
331 struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200332 const char *path; /**< path - leafref */
Radek Krejci151a5b72018-10-19 14:21:44 +0200333 const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200334 struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */
335 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200336
Radek Krejci2167ee12018-11-02 16:09:07 +0100337 struct lysc_type *compiled; /**< pointer to the compiled type */
338
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200339 uint8_t fraction_digits; /**< number of fraction digits - decimal64 */
340 uint8_t require_instance; /**< require-instance flag - leafref, instance */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100341 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200342};
343
344/**
345 * @brief YANG typedef-stmt
346 */
347struct lysp_tpdf {
348 const char *name; /**< name of the newly defined type (mandatory) */
349 const char *units; /**< units of the newly defined type */
350 const char *dflt; /**< default value of the newly defined type */
351 const char *dsc; /**< description statement */
352 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200353 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200354 struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100355 uint16_t flags; /**< [schema node flags](@ref spnodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200356};
357
358/**
359 * @brief YANG grouping-stmt
360 */
361struct lysp_grp {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100362 struct lysp_node *parent; /**< parent node (NULL if this is a top-level grouping) */
363 uint16_t nodetype; /**< LYS_GROUPING */
364 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200365 const char *name; /**< grouping name (mandatory) */
366 const char *dsc; /**< description statement */
367 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200368 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
369 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200370 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200371 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
372 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
373 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200374};
375
376/**
377 * @brief YANG when-stmt
378 */
379struct lysp_when {
380 const char *cond; /**< specified condition (mandatory) */
381 const char *dsc; /**< description statement */
382 const char *ref; /**< reference statement */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200383 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200384};
385
386/**
387 * @brief YANG refine-stmt
388 */
389struct lysp_refine {
390 const char *nodeid; /**< target descendant schema nodeid (mandatory) */
391 const char *dsc; /**< description statement */
392 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200393 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200394 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200395 const char *presence; /**< presence description */
Radek Krejci151a5b72018-10-19 14:21:44 +0200396 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200397 uint32_t min; /**< min-elements constraint */
398 uint32_t max; /**< max-elements constraint, 0 means unbounded */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200399 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200400 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
401};
402
403/**
404 * @brief YANG uses-augment-stmt and augment-stmt
405 */
406struct lysp_augment {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100407 struct lysp_node *parent; /**< parent node (NULL if this is a top-level augment) */
408 uint16_t nodetype; /**< LYS_AUGMENT */
409 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200410 const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */
411 const char *dsc; /**< description statement */
412 const char *ref; /**< reference statement */
413 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200414 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200415 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200416 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
417 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
418 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200419};
420
421/**
422 * @defgroup deviatetypes Deviate types
423 * @{
424 */
425#define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */
426#define LYS_DEV_ADD 2 /**< deviate type add */
427#define LYS_DEV_DELETE 3 /**< deviate type delete */
428#define LYS_DEV_REPLACE 4 /**< deviate type replace */
429/** @} */
430
431/**
432 * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure
433 */
434struct lysp_deviate {
435 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
436 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200437 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200438};
439
440struct lysp_deviate_add {
441 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
442 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200443 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200444 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200445 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200446 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
447 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200448 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
449 uint32_t min; /**< min-elements constraint */
450 uint32_t max; /**< max-elements constraint, 0 means unbounded */
451};
452
453struct lysp_deviate_del {
454 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
455 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200456 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200457 const char *units; /**< units of the values */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200458 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200459 const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */
460 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200461 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200462};
463
464struct lysp_deviate_rpl {
465 uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */
466 struct lysp_deviate *next; /**< next deviate structure in the list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200467 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200468 struct lysp_type *type; /**< type of the node */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200469 const char *units; /**< units of the values */
470 const char *dflt; /**< default value */
471 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
472 uint32_t min; /**< min-elements constraint */
473 uint32_t max; /**< max-elements constraint, 0 means unbounded */
474};
475
476struct lysp_deviation {
Michal Vaskob55f6c12018-09-12 11:13:15 +0200477 const char *nodeid; /**< target absolute schema nodeid (mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200478 const char *dsc; /**< description statement */
479 const char *ref; /**< reference statement */
480 struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200481 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200482};
483
Radek Krejci4f28eda2018-11-12 11:46:16 +0100484/**
485 * @defgroup spnodeflags Parsed schema nodes flags
486 * @ingroup snodeflags
487 *
488 * Various flags for parsed schema nodes.
489 *
490 * 1 - container 6 - anydata/anyxml 11 - output 16 - grouping 21 - enum
491 * 2 - choice 7 - case 12 - feature 17 - uses 22 - type
492 * 3 - leaf 8 - notification 13 - identity 18 - refine
493 * 4 - leaflist 9 - rpc 14 - extension 19 - augment
494 * 5 - list 10 - input 15 - typedef 20 - deviate
495 *
496 * 1 1 1 1 1 1 1 1 1 1 2 2 2
497 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
498 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
499 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | |
500 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
501 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | | | | | | | | |x| |x| | |
502 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
503 * 3 LYS_STATUS_CURR |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| |
504 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
505 * 4 LYS_STATUS_DEPRC |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| |
506 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
507 * 5 LYS_STATUS_OBSLT |x|x|x|x|x|x|x|x|x| | |x|x|x|x|x|x| |x|x|x| |
508 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
509 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | | | | |x| |x| | |
510 * LYS_ORDBY_SYSTEM | | | |x|x| | | | | | | | | | | | | | | | | |
511 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
512 * 7 LYS_MAND_FALSE | |x|x| | |x| | | | | | | | | | | |x| |x| | |
513 * LYS_ORDBY_USER | | | |x|x| | | | | | | | | | | | | | | | | |
514 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
515 * 8 LYS_YINELEM_TRUE | | | | | | | | | | | | | |x| | | | | | | | |
516 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
517 * 9 LYS_YINELEM_FALSE| | | | | | | | | | | | | |x| | | | | | | | |
518 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
519 * 10 LYS_SET_VALUE | | | | | | | | | | | | | | | | | | | | |x| |
520 * LYS_SET_REQINST | | | | | | | | | | | | | | | | | | | | | |x|
521 * LYS_SET_MIN | | | |x|x| | | | | | | | | | | | |x| |x| | |
522 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
523 * 11 LYS_SET_MAX | | | |x|x| | | | | | | | | | | | |x| |x| | |
524 * LYS_TYPE_MODIFIED| | | | | | | | | | | | | | | | | | | | | |x|
525 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
526 *
527 */
528
529/**
530 * @defgroup scnodeflags Compiled schema nodes flags
531 * @ingroup snodeflags
532 *
533 * Various flags for compiled schema nodes.
534 *
535 * 1 - container 6 - anydata/anyxml 11 - output
536 * 2 - choice 7 - case 12 - feature
537 * 3 - leaf 8 - notification 13 - identity
538 * 4 - leaflist 9 - rpc 14 - extension
539 * 5 - list 10 - input
540 *
541 * 1 1 1 1 1
542 * bit name 1 2 3 4 5 6 7 8 9 0 1 2 3 4
543 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
544 * 1 LYS_CONFIG_W |x|x|x|x|x|x|x| | |x| | | | |
545 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
546 * 2 LYS_CONFIG_R |x|x|x|x|x|x|x| | | |x| | | |
547 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
548 * 3 LYS_PRESENCE |x| | | | | | | | | | | | | |
549 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
550 * 4 LYS_UNIQUE | | |x| | | | | | | | | | | |
551 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
552 * 5 LYS_FENABLED | | | | | | | | | | | |x| | |
553 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
554 * 6 LYS_MAND_TRUE | |x|x| | |x| | | | | | | | |
555 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
556 * 7 LYS_ORDBY_USER | | | |x|x| | | | | | | | | |
557 * ---------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
558 *
559 */
560
561/**
562 * @defgroup snodeflags Schema nodes flags
563 * @ingroup schematree
564 * @{
565 */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200566#define LYS_CONFIG_W 0x01 /**< config true; */
567#define LYS_CONFIG_R 0x02 /**< config false; */
568#define LYS_CONFIG_MASK 0x03 /**< mask for config value */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100569#define LYS_STATUS_CURR 0x04 /**< status current; */
570#define LYS_STATUS_DEPRC 0x08 /**< status deprecated; */
571#define LYS_STATUS_OBSLT 0x10 /**< status obsolete; */
572#define LYS_STATUS_MASK 0x1C /**< mask for status value */
573#define LYS_MAND_TRUE 0x20 /**< mandatory true; applicable only to ::lysp_node_choice/::lysc_node_choice,
574 ::lysp_node_leaf/::lysc_node_leaf and ::lysp_node_anydata/::lysc_node_anydata */
575#define LYS_MAND_FALSE 0x40 /**< mandatory false; applicable only to
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200576 ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf
577 and ::lysp_node_anydata/::lysc_node_anydata */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100578#define LYS_MAND_MASK 0x60 /**< mask for mandatory values */
579#define LYS_PRESENCE 0x04 /**< flag for presence property of a container, applicable only to ::lysc_node_container */
580#define LYS_UNIQUE 0x08 /**< flag for leafs being part of a unique set, applicable only to ::lysc_node_leaf */
581#define LYS_FENABLED 0x10 /**< feature enabled flag, applicable only to ::lysc_feature */
582#define LYS_ORDBY_SYSTEM 0x20 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
583 ::lysc_node_list/::lysp_node_list */
584#define LYS_ORDBY_USER 0x40 /**< ordered-by user lists, applicable only to ::lysc_node_leaflist/::lysp_node_leaflist and
585 ::lysc_node_list/::lysp_node_list */
586#define LYS_ORDBY_MASK 0x60 /**< mask for ordered-by values */
587#define LYS_YINELEM_TRUE 0x80 /**< yin-element true for extension's argument */
588#define LYS_YINELEM_FALSE 0x100 /**< yin-element false for extension's argument */
589#define LYS_YINELEM_MASK 0x180 /**< mask for yin-element value */
590#define LYS_SET_VALUE 0x200 /**< value attribute is set */
591#define LYS_SET_REQINST 0x200 /**< require_instance attribute is set */
592#define LYS_SET_MIN 0x200 /**< min attribute is set */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200593#define LYS_SET_MAX 0x400 /**< max attribute is set */
Radek Krejci4f28eda2018-11-12 11:46:16 +0100594#define LYS_TYPE_MODIFIED 0x400 /**< referenced type has been modified by a restriction */
595/** @} */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200596
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200597/**
598 * @brief Generic YANG data node
599 */
600struct lysp_node {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100601 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200602 uint16_t nodetype; /**< type of the node (mandatory) */
603 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100604 struct lysp_node *next; /**< next sibling node (NULL if there is no one) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200605 const char *name; /**< node name (mandatory) */
606 const char *dsc; /**< description statement */
607 const char *ref; /**< reference statement */
608 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200609 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200610 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200611};
612
613/**
614 * @brief Extension structure of the lysp_node for YANG container
615 */
616struct lysp_node_container {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100617 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200618 uint16_t nodetype; /**< LYS_CONTAINER */
619 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
620 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
621 const char *name; /**< node name (mandatory) */
622 const char *dsc; /**< description statement */
623 const char *ref; /**< reference statement */
624 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200625 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200626 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200627
628 /* container */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200629 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200630 const char *presence; /**< presence description */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200631 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
632 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200633 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200634 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
635 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200636};
637
638struct lysp_node_leaf {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100639 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200640 uint16_t nodetype; /**< LYS_LEAF */
641 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
642 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
643 const char *name; /**< node name (mandatory) */
644 const char *dsc; /**< description statement */
645 const char *ref; /**< reference statement */
646 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200647 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200648 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200649
650 /* leaf */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200651 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200652 struct lysp_type type; /**< type of the leaf node (mandatory) */
653 const char *units; /**< units of the leaf's type */
654 const char *dflt; /**< default value */
655};
656
657struct lysp_node_leaflist {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100658 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200659 uint16_t nodetype; /**< LYS_LEAFLIST */
660 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
661 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
662 const char *name; /**< node name (mandatory) */
663 const char *dsc; /**< description statement */
664 const char *ref; /**< reference statement */
665 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200666 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200667 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200668
669 /* leaf-list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200670 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200671 struct lysp_type type; /**< type of the leaf node (mandatory) */
672 const char *units; /**< units of the leaf's type */
Radek Krejci151a5b72018-10-19 14:21:44 +0200673 const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200674 uint32_t min; /**< min-elements constraint */
675 uint32_t max; /**< max-elements constraint, 0 means unbounded */
676};
677
678struct lysp_node_list {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100679 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200680 uint16_t nodetype; /**< LYS_LIST */
681 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
682 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
683 const char *name; /**< node name (mandatory) */
684 const char *dsc; /**< description statement */
685 const char *ref; /**< reference statement */
686 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200687 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200688 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200689
690 /* list */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200691 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200692 const char *key; /**< keys specification */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200693 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
694 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200695 struct lysp_node *child; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200696 struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
697 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200698 const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200699 uint32_t min; /**< min-elements constraint */
700 uint32_t max; /**< max-elements constraint, 0 means unbounded */
701};
702
703struct lysp_node_choice {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100704 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200705 uint16_t nodetype; /**< LYS_CHOICE */
706 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
707 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
708 const char *name; /**< node name (mandatory) */
709 const char *dsc; /**< description statement */
710 const char *ref; /**< reference statement */
711 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200712 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200713 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200714
715 /* choice */
716 struct lysp_node *child; /**< list of data nodes (linked list) */
717 const char* dflt; /**< default case */
718};
719
720struct lysp_node_case {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100721 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200722 uint16_t nodetype; /**< LYS_CASE */
723 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
724 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
725 const char *name; /**< node name (mandatory) */
726 const char *dsc; /**< description statement */
727 const char *ref; /**< reference statement */
728 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200729 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200730 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200731
732 /* case */
733 struct lysp_node *child; /**< list of data nodes (linked list) */
734};
735
736struct lysp_node_anydata {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100737 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200738 uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */
739 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
740 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
741 const char *name; /**< node name (mandatory) */
742 const char *dsc; /**< description statement */
743 const char *ref; /**< reference statement */
744 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200745 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200746 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200747
748 /* anyxml/anydata */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200749 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200750};
751
752struct lysp_node_uses {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100753 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200754 uint16_t nodetype; /**< LYS_USES */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200755 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
756 struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */
757 const char *name; /**< grouping name reference (mandatory) */
758 const char *dsc; /**< description statement */
759 const char *ref; /**< reference statement */
760 struct lysp_when *when; /**< when statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200761 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200762 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200763
764 /* uses */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200765 struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */
766 struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200767};
768
769/**
770 * @brief YANG input-stmt and output-stmt
771 */
772struct lysp_action_inout {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100773 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
774 uint16_t nodetype; /**< LYS_INOUT */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200775 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
776 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
777 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200778 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200779 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200780};
781
782/**
783 * @brief YANG rpc-stmt and action-stmt
784 */
785struct lysp_action {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100786 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
787 uint16_t nodetype; /**< LYS_ACTION */
788 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200789 const char *name; /**< grouping name reference (mandatory) */
790 const char *dsc; /**< description statement */
791 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200792 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200793 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
794 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Michal Vaskob55f6c12018-09-12 11:13:15 +0200795 struct lysp_action_inout *input; /**< RPC's/Action's input */
796 struct lysp_action_inout *output;/**< RPC's/Action's output */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200797 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200798};
799
800/**
801 * @brief YANG notification-stmt
802 */
803struct lysp_notif {
Radek Krejci6d9b9b52018-11-02 12:43:39 +0100804 struct lysp_node *parent; /**< parent node (NULL if this is a top-level node) */
805 uint16_t nodetype; /**< LYS_NOTIF */
806 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200807 const char *name; /**< grouping name reference (mandatory) */
808 const char *dsc; /**< description statement */
809 const char *ref; /**< reference statement */
Radek Krejci151a5b72018-10-19 14:21:44 +0200810 const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200811 struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
812 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
813 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200814 struct lysp_node *data; /**< list of data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200815 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200816};
817
818/**
Radek Krejcif0fceb62018-09-05 14:58:45 +0200819 * @brief supported YANG schema version values
820 */
821typedef enum LYS_VERSION {
822 LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */
823 LYS_VERSION_1_0 = 1, /**< YANG 1.0 */
824 LYS_VERSION_1_1 = 2 /**< YANG 1.1 */
825} LYS_VERSION;
826
827/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200828 * @brief Printable YANG schema tree structure representing YANG module.
829 *
830 * Simple structure corresponding to the YANG format. The schema is only syntactically validated.
831 */
832struct lysp_module {
833 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
834 const char *name; /**< name of the module (mandatory) */
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100835 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200836 union {
837 /* module */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200838 const char *ns; /**< namespace of the module (module - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200839 /* submodule */
Michal Vaskod5927ca2018-09-07 15:05:32 +0200840 const char *belongsto; /**< belongs to parent module (submodule - mandatory) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200841 };
Michal Vaskod5927ca2018-09-07 15:05:32 +0200842 const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */
Radek Krejcib7db73a2018-10-24 14:18:40 +0200843 struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision
844 in the list is always the last (newest) revision of the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200845 struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
846 struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200847 const char *org; /**< party/company responsible for the module */
848 const char *contact; /**< contact information for the module */
849 const char *dsc; /**< description of the module */
850 const char *ref; /**< cross-reference for the module */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200851 struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */
852 struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
853 struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
854 struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */
855 struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200856 struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200857 struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */
858 struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
859 struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
860 struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */
861 struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200862
Radek Krejcif0fceb62018-09-05 14:58:45 +0200863 uint8_t submodule:1; /**< flag to distinguish main modules and submodules */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200864 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
Radek Krejci086c7132018-10-26 15:29:04 +0200865 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
866 1 - the latest revision in searchdirs was not searched yet and this is the
867 latest revision in the current context
868 2 - searchdirs were searched and this is the latest available revision */
869 uint8_t parsing:1; /**< flag for circular check */
870 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200871};
872
873/**
Radek Krejci3f5e3db2018-10-11 15:57:47 +0200874 * @brief Free the printable YANG schema tree structure.
875 *
876 * @param[in] module Printable YANG schema tree structure to free.
877 */
878void lysp_module_free(struct lysp_module *module);
879
880/**
Radek Krejcice8c1592018-10-29 15:35:51 +0100881 * @brief YANG extension instance
882 */
883struct lysc_ext_instance {
884 struct lyext_plugin *plugin; /**< pointer to the plugin implementing the extension (if present) */
885 void *parent; /**< pointer to the parent element holding the extension instance(s), use
886 ::lysc_ext_instance#parent_type to access the schema element */
887 const char *argument; /**< optional value of the extension's argument */
888 LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */
889 uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times,
890 this identifies the index of the substatement for this extension instance */
Radek Krejci2a408df2018-10-29 16:32:26 +0100891 LYEXT_PARENT parent_type; /**< type of the parent structure */
Radek Krejcice8c1592018-10-29 15:35:51 +0100892#if 0
Radek Krejcice8c1592018-10-29 15:35:51 +0100893 uint8_t ext_type; /**< extension type (#LYEXT_TYPE) */
894 uint8_t padding; /**< 32b padding */
Radek Krejcice8c1592018-10-29 15:35:51 +0100895 struct lys_module *module; /**< pointer to the extension instance's module (mandatory) */
896 LYS_NODE nodetype; /**< LYS_EXT */
897#endif
Radek Krejci2a408df2018-10-29 16:32:26 +0100898 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
899 void *priv; /**< private caller's data, not used by libyang */
Radek Krejcice8c1592018-10-29 15:35:51 +0100900};
901
902/**
Radek Krejcibd8d9ba2018-11-02 16:06:26 +0100903 * @brief Compiled YANG if-feature-stmt
904 */
905struct lysc_iffeature {
906 uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */
907 struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */
908};
909
910/**
Radek Krejci151a5b72018-10-19 14:21:44 +0200911 * @brief YANG import-stmt
912 */
913struct lysc_import {
Radek Krejci6d6e4e42018-10-29 13:28:19 +0100914 struct lys_module *module; /**< link to the imported module */
Radek Krejci151a5b72018-10-19 14:21:44 +0200915 const char *prefix; /**< prefix for the data from the imported schema (mandatory) */
Radek Krejcice8c1592018-10-29 15:35:51 +0100916 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200917};
918
919/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200920 * @brief YANG when-stmt
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200921 */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200922struct lysc_when {
923 struct lyxp_expr *cond; /**< XPath when condition */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200924 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200925};
926
927/**
Radek Krejci2a408df2018-10-29 16:32:26 +0100928 * @brief YANG identity-stmt
929 */
930struct lysc_ident {
931 const char *name; /**< identity name (mandatory), including possible prefix */
932 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
933 struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */
934 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
935 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */
936};
937
938/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200939 * @brief YANG feature-stmt
940 */
941struct lysc_feature {
942 const char *name; /**< feature name (mandatory) */
Radek Krejci151a5b72018-10-19 14:21:44 +0200943 struct lysc_feature **depfeatures;/**< list of pointers to other features depending on this one ([sized array](@ref sizedarrays)) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +0200944 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +0100945 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +0200946 uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and
947 #LYS_FENABLED values allowed */
948};
949
Radek Krejci151a5b72018-10-19 14:21:44 +0200950/**
951 * @defgroup ifftokens if-feature expression tokens
952 * Tokens of if-feature expression used in ::lysc_iffeature#expr
953 *
954 * @{
955 */
956#define LYS_IFF_NOT 0x00 /**< operand "not" */
957#define LYS_IFF_AND 0x01 /**< operand "and" */
958#define LYS_IFF_OR 0x02 /**< operand "or" */
959#define LYS_IFF_F 0x03 /**< feature */
960/**
961 * @}
962 */
963
964/**
Radek Krejcib7db73a2018-10-24 14:18:40 +0200965 * @brief Compiled YANG revision statement
966 */
967struct lysc_revision {
968 char date[LY_REV_SIZE]; /**< revision-date (mandatory) */
969 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
970};
971
Radek Krejci2167ee12018-11-02 16:09:07 +0100972struct lysc_default {
973 struct lys_module *module; /**< module where the default was defined */
974 const char *value; /**< default value (with possible prefixes from the module where defined) */
975};
976
977struct lysc_range {
Radek Krejci4f28eda2018-11-12 11:46:16 +0100978 struct lysc_range_part {
Radek Krejci2167ee12018-11-02 16:09:07 +0100979 union { /**< min boundary TODO decimal */
980 int64_t min_64; /**< for int8, int16, int32 and int64 */
981 uint64_t min_u64; /**< for uint8, uint16, uint32 and uint64 */
982 };
983 union { /**< max boundary TODO decimal */
984 int64_t max_64; /**< for int8, int16, int32 and int64 */
985 uint64_t max_u64; /**< for uint8, uint16, uint32 and uint64 */
986 };
Radek Krejci4f28eda2018-11-12 11:46:16 +0100987 } *parts; /**< compiled range expression ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +0100988 const char *emsg; /**< error-message */
989 const char *eapptag; /**< error-app-tag value */
990 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
991};
992
993struct lysc_pattern {
994 pcre *expr; /**< compiled regular expression */
995 pcre_extra *expr_extra; /**< additional information to speed up matching */
996 const char *emsg; /**< error-message */
997 const char *eapptag; /**< error-app-tag value */
998 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
999 uint8_t inverted; /**< invert-match flag */
1000};
1001
1002struct lysc_must {
1003 struct lys_module *module; /**< module where the must was defined */
1004 struct lyxp_expr *cond; /**< XPath when condition */
1005 const char *emsg; /**< error-message */
1006 const char *eapptag; /**< error-app-tag value */
1007 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1008};
1009
1010struct lysc_type {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001011 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001012 LY_DATA_TYPE basetype; /**< Base type of the type */
1013 uint32_t refcount; /**< reference counter for type sharing */
1014};
1015
1016struct lysc_type_num {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001017 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001018 LY_DATA_TYPE basetype; /**< Base type of the type */
1019 uint32_t refcount; /**< reference counter for type sharing */
1020 struct lysc_range *range; /**< Optional range limitation */
1021};
1022
1023struct lysc_type_dec {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001024 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001025 LY_DATA_TYPE basetype; /**< Base type of the type */
1026 uint32_t refcount; /**< reference counter for type sharing */
1027 uint64_t fraction_digits:1; /**< fraction digits specification */
1028 uint64_t div:63; /**< value for moving decimal point (dividing the stored value to get the real value) */
1029 struct lysc_range *range; /**< Optional range limitation */
1030};
1031
1032struct lysc_type_str {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001033 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001034 LY_DATA_TYPE basetype; /**< Base type of the type */
1035 uint32_t refcount; /**< reference counter for type sharing */
1036 struct lysc_range *length; /**< Optional length limitation */
1037 struct lysc_pattern *patterns; /**< Optional list of pattern limitations ([sized array](@ref sizedarrays)) */
1038};
1039
1040struct lysc_type_enum {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001041 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001042 LY_DATA_TYPE basetype; /**< Base type of the type */
1043 uint32_t refcount; /**< reference counter for type sharing */
1044 struct {
1045 const char *name; /**< enumeration identifier */
1046 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1047 int32_t value; /**< integer value associated with the enumeration */
1048 } *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1049};
1050
1051struct lysc_type_leafref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001052 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001053 LY_DATA_TYPE basetype; /**< Base type of the type */
1054 uint32_t refcount; /**< reference counter for type sharing */
1055 struct lysc_node* target; /**< Target schema node */
1056 uint8_t require_instance; /**< require-instance flag */
1057};
1058
1059struct lysc_type_identityref {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001060 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001061 LY_DATA_TYPE basetype; /**< Base type of the type */
1062 uint32_t refcount; /**< reference counter for type sharing */
1063 struct lysc_ident **base; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
1064 mandatory (at least 1 item) */
1065};
1066
1067struct lysc_type_instanceid {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001068 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001069 LY_DATA_TYPE basetype; /**< Base type of the type */
1070 uint32_t refcount; /**< reference counter for type sharing */
1071 uint8_t require_instance; /**< require-instance flag */
1072};
1073
1074struct lysc_type_bits {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001075 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001076 LY_DATA_TYPE basetype; /**< Base type of the type */
1077 uint32_t refcount; /**< reference counter for type sharing */
1078 struct {
1079 const char *name; /**< bit identifier */
1080 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1081 uint32_t position; /**< non-negative integer value associated with the bit */
1082 } *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1083};
1084
1085struct lysc_type_union {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001086 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001087 LY_DATA_TYPE basetype; /**< Base type of the type */
1088 uint32_t refcount; /**< reference counter for type sharing */
1089 struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
1090};
1091
1092struct lysc_type_bin {
Radek Krejci4f28eda2018-11-12 11:46:16 +01001093 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejci2167ee12018-11-02 16:09:07 +01001094 LY_DATA_TYPE basetype; /**< Base type of the type */
1095 uint32_t refcount; /**< reference counter for type sharing */
1096 struct lysc_range *length; /**< Optional length limitation */
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001097};
1098
1099/**
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001100 * @brief Compiled YANG data node
1101 */
1102struct lysc_node {
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001103 uint16_t nodetype; /**< type of the node (mandatory) */
1104 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001105 struct lys_module *module; /**< module structure */
1106 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1107 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1108 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1109 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1110 never NULL. If there is no sibling node, pointer points to the node
1111 itself. In case of the first node, this pointer points to the last
1112 node in the list. */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001113 const char *name; /**< node name (mandatory) */
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001114 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001115};
1116
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001117struct lysc_node_container {
1118 uint16_t nodetype; /**< LYS_CONTAINER */
1119 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1120 struct lys_module *module; /**< module structure */
1121 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1122 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1123 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1124 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1125 never NULL. If there is no sibling node, pointer points to the node
1126 itself. In case of the first node, this pointer points to the last
1127 node in the list. */
1128 const char *name; /**< node name (mandatory) */
1129 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1130
Radek Krejci4f28eda2018-11-12 11:46:16 +01001131 struct lysc_when *when; /**< when statement */
1132 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1133
1134 struct lysc_node *child; /**< first child node (linked list) */
1135 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1136 struct lysc_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */
1137 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001138};
1139
1140struct lysc_node_choice {
1141 uint16_t nodetype; /**< LYS_CHOICE */
1142 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1143 struct lys_module *module; /**< module structure */
1144 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1145 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1146 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1147 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1148 never NULL. If there is no sibling node, pointer points to the node
1149 itself. In case of the first node, this pointer points to the last
1150 node in the list. */
1151 const char *name; /**< node name (mandatory) */
1152 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1153
1154 struct lysc_node *child;
1155};
1156
1157struct lysc_node_leaf {
1158 uint16_t nodetype; /**< LYS_LEAF */
1159 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1160 struct lys_module *module; /**< module structure */
1161 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1162 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1163 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1164 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1165 never NULL. If there is no sibling node, pointer points to the node
1166 itself. In case of the first node, this pointer points to the last
1167 node in the list. */
1168 const char *name; /**< node name (mandatory) */
1169 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1170
Radek Krejci4f28eda2018-11-12 11:46:16 +01001171 struct lysc_when *when; /**< when statement */
1172 struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
1173
1174 struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
1175 struct lysc_type *type; /**< type of the leaf node (mandatory) */
1176 const char *units; /**< units of the leaf's type */
1177 const char *dflt; /**< default value */
Radek Krejcibd8d9ba2018-11-02 16:06:26 +01001178};
1179
1180struct lysc_node_leaflist {
1181 uint16_t nodetype; /**< LYS_LEAFLIST */
1182 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1183 struct lys_module *module; /**< module structure */
1184 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1185 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1186 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1187 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1188 never NULL. If there is no sibling node, pointer points to the node
1189 itself. In case of the first node, this pointer points to the last
1190 node in the list. */
1191 const char *name; /**< node name (mandatory) */
1192 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1193
1194};
1195
1196struct lysc_node_list {
1197 uint16_t nodetype; /**< LYS_LIST */
1198 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1199 struct lys_module *module; /**< module structure */
1200 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1201 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1202 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1203 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1204 never NULL. If there is no sibling node, pointer points to the node
1205 itself. In case of the first node, this pointer points to the last
1206 node in the list. */
1207 const char *name; /**< node name (mandatory) */
1208 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1209
1210 struct lysc_node *child;
1211};
1212
1213struct lysc_node_anydata {
1214 uint16_t nodetype; /**< LYS_ANYXML or LYS_ANYDATA */
1215 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1216 struct lys_module *module; /**< module structure */
1217 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1218 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1219 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1220 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1221 never NULL. If there is no sibling node, pointer points to the node
1222 itself. In case of the first node, this pointer points to the last
1223 node in the list. */
1224 const char *name; /**< node name (mandatory) */
1225 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1226
1227};
1228
1229struct lysc_node_case {
1230 uint16_t nodetype; /**< LYS_CASE */
1231 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1232 struct lys_module *module; /**< module structure */
1233 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1234 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1235 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1236 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1237 never NULL. If there is no sibling node, pointer points to the node
1238 itself. In case of the first node, this pointer points to the last
1239 node in the list. */
1240 const char *name; /**< node name (mandatory) */
1241 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1242
1243 struct lysc_node *child;
1244};
1245
1246struct lysc_node_uses {
1247 uint16_t nodetype; /**< LYS_CHOICE */
1248 uint16_t flags; /**< [schema node flags](@ref snodeflags) */
1249 struct lys_module *module; /**< module structure */
1250 struct lysp_node *sp; /**< simply parsed (SP) original of the node, NULL if the SP schema was removed or in case of implicit case node. */
1251 struct lysc_node *parent; /**< parent node (NULL in case of top level node) */
1252 struct lysc_node *next; /**< next sibling node (NULL if there is no one) */
1253 struct lysc_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is
1254 never NULL. If there is no sibling node, pointer points to the node
1255 itself. In case of the first node, this pointer points to the last
1256 node in the list. */
1257 const char *name; /**< node name (mandatory) */
1258 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
1259
1260 struct lysc_node *child;
1261};
1262
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001263/**
1264 * @brief Compiled YANG schema tree structure representing YANG module.
1265 *
1266 * Semantically validated YANG schema tree for data tree parsing.
1267 * Contains only the necessary information for the data validation.
1268 */
1269struct lysc_module {
1270 struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */
1271 const char *name; /**< name of the module (mandatory) */
Radek Krejci6d6e4e42018-10-29 13:28:19 +01001272 const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001273 const char *ns; /**< namespace of the module (mandatory) */
1274 const char *prefix; /**< module prefix (mandatory) */
Radek Krejcif8f882a2018-10-31 14:51:15 +01001275 const char *revision; /**< the revision of the module */
Radek Krejci151a5b72018-10-19 14:21:44 +02001276 struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001277
Radek Krejcie53a8dc2018-10-17 12:52:40 +02001278 struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */
Radek Krejci2a408df2018-10-29 16:32:26 +01001279 struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */
1280 struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */
1281 struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */
1282 struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */
Radek Krejcice8c1592018-10-29 15:35:51 +01001283 struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001284
1285 uint8_t implemented:1; /**< flag if the module is implemented, not just imported */
Radek Krejcifaa1eac2018-10-30 14:34:55 +01001286 uint8_t latest_revision:2; /**< flag to mark the latest available revision:
1287 1 - the latest revision in searchdirs was not searched yet and this is the
1288 latest revision in the current context
1289 2 - searchdirs were searched and this is the latest available revision */
Radek Krejci086c7132018-10-26 15:29:04 +02001290 uint8_t version; /**< yang-version (LYS_VERSION values) */
Radek Krejci0af5f5d2018-09-07 15:00:30 +02001291};
1292
1293/**
Radek Krejci151a5b72018-10-19 14:21:44 +02001294 * @brief Get how the if-feature statement currently evaluates.
1295 *
1296 * @param[in] iff Compiled if-feature statement to evaluate.
1297 * @return If the statement evaluates to true, 1 is returned. 0 is returned when the statement evaluates to false.
1298 */
1299int lysc_iffeature_value(const struct lysc_iffeature *iff);
1300
1301/**
1302 * @brief Get the current status of the provided feature.
1303 *
1304 * @param[in] feature Compiled feature statement to examine.
1305 * @return
1306 * - 1 if feature is enabled,
1307 * - 0 if feature is disabled,
1308 * - -1 in case of error (invalid argument)
1309 */
1310int lysc_feature_value(const struct lysc_feature *feature);
1311
1312/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001313 * @brief Available YANG schema tree structures representing YANG module.
1314 */
1315struct lys_module {
1316 struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */
1317 struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing */
1318};
1319
Radek Krejci151a5b72018-10-19 14:21:44 +02001320/**
1321 * @brief Enable specified feature in the module
1322 *
1323 * By default, when the module is loaded by libyang parser, all features are disabled.
1324 *
Radek Krejcica3db002018-11-01 10:31:01 +01001325 * If all features are being enabled, it must be possible respecting their if-feature conditions. For example,
1326 * enabling all features on the following feature set will fail since it is not possible to enable both features
1327 * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature
1328 * is untouched.
1329 *
1330 * feature f1;
1331 * feature f2 { if-feature 'not f1';}
1332 *
Radek Krejci151a5b72018-10-19 14:21:44 +02001333 * @param[in] module Module where the feature will be enabled.
1334 * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character.
1335 * @return LY_ERR value.
1336 */
1337LY_ERR lys_feature_enable(struct lys_module *module, const char *feature);
1338
1339/**
1340 * @brief Disable specified feature in the module
1341 *
1342 * By default, when the module is loaded by libyang parser, all features are disabled.
1343 *
1344 * @param[in] module Module where the feature will be disabled.
1345 * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character.
1346 * @return LY_ERR value
1347 */
1348LY_ERR lys_feature_disable(struct lys_module *module, const char *feature);
1349
1350/**
1351 * @brief Get the current status of the specified feature in the module.
1352 *
1353 * @param[in] module Module where the feature is defined.
1354 * @param[in] feature Name of the feature to inspect.
1355 * @return
1356 * - 1 if feature is enabled,
1357 * - 0 if feature is disabled,
1358 * - -1 in case of error (e.g. feature is not defined or invalid arguments)
1359 */
1360int lys_feature_value(const struct lys_module *module, const char *feature);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001361
1362/**
Radek Krejci86d106e2018-10-18 09:53:19 +02001363 * @brief Load a schema into the specified context.
1364 *
1365 * @param[in] ctx libyang context where to process the data model.
1366 * @param[in] data The string containing the dumped data model in the specified
1367 * format.
1368 * @param[in] format Format of the input data (YANG or YIN).
1369 * @return Pointer to the data model structure or NULL on error.
1370 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001371struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001372
1373/**
1374 * @brief Read a schema from file descriptor into the specified context.
1375 *
1376 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
1377 *
1378 * @param[in] ctx libyang context where to process the data model.
1379 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
1380 * in the specified format.
1381 * @param[in] format Format of the input data (YANG or YIN).
1382 * @return Pointer to the data model structure or NULL on error.
1383 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001384struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001385
1386/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001387 * @brief Read a schema into the specified context from a file.
Radek Krejci86d106e2018-10-18 09:53:19 +02001388 *
1389 * @param[in] ctx libyang context where to process the data model.
1390 * @param[in] path Path to the file with the model in the specified format.
1391 * @param[in] format Format of the input data (YANG or YIN).
1392 * @return Pointer to the data model structure or NULL on error.
1393 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001394struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
Radek Krejci86d106e2018-10-18 09:53:19 +02001395
1396/**
Radek Krejcid33273d2018-10-25 14:55:52 +02001397 * @brief Search for the schema file in the specified searchpaths.
1398 *
1399 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
1400 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
1401 * result of the ly_ctx_get_searchdirs().
1402 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
1403 * @param[in] name Name of the schema to find.
1404 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
1405 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
1406 * complying the provided restriction is found, NULL is set.
1407 * @param[out] format Optional output variable containing expected format of the schema document according to the
1408 * file suffix.
1409 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
1410 */
1411LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
1412
1413/**
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001414 * @defgroup scflags Schema compile flags
1415 * @ingroup schematree
1416 *
1417 * @{
1418 */
1419#define LYSC_OPT_FREE_SP 1 /**< Free the input printable schema */
1420
1421/**
1422 * @}
1423 */
1424
1425/**
1426 * @brief Compile printable schema into a validated schema linking all the references.
1427 *
Radek Krejcif8f882a2018-10-31 14:51:15 +01001428 * @param[in, out] mod Schema structure holding pointers to both schema structure types. The ::lys_module#parsed
1429 * member is used as input and ::lys_module#compiled is used to hold the result of the compilation.
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001430 * @param[in] options Various options to modify compiler behavior, see [compile flags](@ref scflags).
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001431 * @return LY_ERR value.
1432 */
Radek Krejcid14e9692018-11-01 11:00:37 +01001433LY_ERR lys_compile(struct lys_module *mod, int options);
Radek Krejcidd4e8d42018-10-16 14:55:43 +02001434
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001435/** @} */
1436
Radek Krejci70853c52018-10-15 14:46:16 +02001437#ifdef __cplusplus
1438}
1439#endif
1440
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001441#endif /* LY_TREE_SCHEMA_H_ */