Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 1 | /** |
| 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 Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 20 | #include "extensions.h" |
| 21 | |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 26 | /** |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 27 | * @brief XPath representation. |
| 28 | */ |
| 29 | struct lyxp_expr; |
| 30 | |
| 31 | /** |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 32 | * @brief Macro selector for other LY_ARRAY_* macros, do not use directly! |
| 33 | */ |
| 34 | #define LY_ARRAY_SELECT(_1, _2, NAME, ...) NAME |
| 35 | |
| 36 | /** |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 37 | * @brief Helper macro to go through sized-arrays with a pointer iterator. |
| 38 | * |
| 39 | * Use with opening curly bracket (`{`). |
| 40 | * |
| 41 | * @param[in] ARRAY Array to go through |
| 42 | * @param[in] TYPE Type of the records in the ARRAY |
| 43 | * @param[out] ITER Iterating pointer to the item being processed in each loop |
| 44 | */ |
| 45 | #define LY_ARRAY_FOR_ITER(ARRAY, TYPE, ITER) \ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 46 | for (ITER = ARRAY; \ |
| 47 | (ARRAY) && ((void*)ITER - (void*)ARRAY)/(sizeof(TYPE)) < (*((uint32_t*)(ARRAY) - 1)); \ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 48 | ITER = (void*)((TYPE*)ITER + 1)) |
| 49 | |
| 50 | /** |
| 51 | * @brief Helper macro to go through sized-arrays with a numeric iterator. |
| 52 | * |
| 53 | * Use with opening curly bracket (`{`). |
| 54 | * |
| 55 | * To access an item with the INDEX value, use always LY_ARRAY_INDEX macro! |
| 56 | * |
| 57 | * @param[in] ARRAY Array to go through |
| 58 | * @param[out] INDEX Iterating index of the item being processed in each loop |
| 59 | */ |
| 60 | #define LY_ARRAY_FOR_INDEX(ARRAY, INDEX) \ |
| 61 | for (INDEX = 0; \ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 62 | ARRAY && INDEX < (*((uint32_t*)(ARRAY) - 1)); \ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 63 | ++INDEX) |
| 64 | |
| 65 | /** |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 66 | * @defgroup schematree Schema Tree |
| 67 | * @{ |
| 68 | * |
| 69 | * Data structures and functions to manipulate and access schema tree. |
| 70 | */ |
| 71 | |
Radek Krejci | 0af5f5d | 2018-09-07 15:00:30 +0200 | [diff] [blame] | 72 | /** |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 73 | * @brief Get a number of records in the ARRAY. |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 74 | * |
| 75 | * Does not check if array exists! |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 76 | */ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 77 | #define LY_ARRAY_SIZE(ARRAY) (*((uint32_t*)(ARRAY) - 1)) |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * @brief Sized-array iterator (for-loop). |
| 81 | * |
| 82 | * Use with opening curly bracket (`{`). |
| 83 | * |
| 84 | * There are 2 variants: |
| 85 | * |
| 86 | * LY_ARRAY_FOR(ARRAY, TYPE, ITER) |
| 87 | * |
| 88 | * Where ARRAY is a sized-array to go through, TYPE is the type of the items in the ARRAY and ITER is a pointer variable |
| 89 | * providing the items of the ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_ITER macro |
| 90 | * |
| 91 | * LY_ARRAY_FOR(ARRAY, INDEX) |
| 92 | * |
| 93 | * The ARRAY is again a sized-array to go through, the INDEX is a variable (unsigned integer) for storing iterating ARRAY's index |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 94 | * to access the items of ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_INDEX macro. |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 95 | */ |
| 96 | #define LY_ARRAY_FOR(ARRAY, ...) LY_ARRAY_SELECT(__VA_ARGS__, LY_ARRAY_FOR_ITER, LY_ARRAY_FOR_INDEX)(ARRAY, __VA_ARGS__) |
Radek Krejci | 5fac359 | 2018-10-12 15:23:45 +0200 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * @brief Macro to iterate via all sibling elements without affecting the list itself |
| 100 | * |
| 101 | * Works for all types of nodes despite it is data or schema tree, but all the |
| 102 | * parameters must be pointers to the same type. |
| 103 | * |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 104 | * Use with opening curly bracket (`{`). All parameters must be of the same type. |
Radek Krejci | 5fac359 | 2018-10-12 15:23:45 +0200 | [diff] [blame] | 105 | * |
| 106 | * @param START Pointer to the starting element. |
| 107 | * @param ELEM Iterator. |
| 108 | */ |
| 109 | #define LY_LIST_FOR(START, ELEM) \ |
| 110 | for ((ELEM) = (START); \ |
| 111 | (ELEM); \ |
| 112 | (ELEM) = (ELEM)->next) |
| 113 | |
| 114 | /** |
| 115 | * @ingroup datatree |
| 116 | * @brief Macro to iterate via all sibling elements allowing to modify the list itself (e.g. removing elements) |
| 117 | * |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 118 | * Use with opening curly bracket (`{`). All parameters must be of the same type. |
Radek Krejci | 5fac359 | 2018-10-12 15:23:45 +0200 | [diff] [blame] | 119 | * |
| 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 Krejci | 0af5f5d | 2018-09-07 15:00:30 +0200 | [diff] [blame] | 130 | * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers). |
| 131 | */ |
| 132 | typedef 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 | */ |
| 141 | typedef 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 Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 150 | #define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */ |
| 151 | |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 152 | #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 Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 162 | |
| 163 | /** |
| 164 | * @brief YANG import-stmt |
| 165 | */ |
| 166 | struct lysp_import { |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 167 | struct lys_module *module; /**< pointer to the imported module |
| 168 | (mandatory, but resolved when the referring module is completely parsed) */ |
| 169 | const char *name; /**< name of the imported module (mandatory) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 170 | const char *prefix; /**< prefix for the data from the imported schema (mandatory) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 171 | const char *dsc; /**< description */ |
| 172 | const char *ref; /**< reference */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 173 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 174 | char rev[LY_REV_SIZE]; /**< revision-date of the imported module */ |
| 175 | }; |
| 176 | |
| 177 | /** |
| 178 | * @brief YANG include-stmt |
| 179 | */ |
| 180 | struct lysp_include { |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 181 | struct lysp_module *submodule; /**< pointer to the parsed submodule structure |
| 182 | (mandatory, but resolved when the referring module is completely parsed) */ |
| 183 | const char *name; /**< name of the included submodule (mandatory) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 184 | const char *dsc; /**< description */ |
| 185 | const char *ref; /**< reference */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 186 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 187 | char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */ |
| 188 | }; |
| 189 | |
| 190 | /** |
| 191 | * @brief YANG extension-stmt |
| 192 | */ |
| 193 | struct lysp_ext { |
| 194 | const char *name; /**< extension name */ |
| 195 | const char *argument; /**< argument name, NULL if not specified */ |
| 196 | const char *dsc; /**< description statement */ |
| 197 | const char *ref; /**< reference statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 198 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 199 | uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */ |
| 200 | }; |
| 201 | |
| 202 | /** |
| 203 | * @brief Helper structure for generic storage of the extension instances content. |
| 204 | */ |
| 205 | struct lysp_stmt { |
| 206 | const char *stmt; /**< identifier of the statement */ |
| 207 | const char *arg; /**< statement's argument */ |
| 208 | struct lysp_stmt *next; /**< link to the next statement */ |
Michal Vasko | bc2559f | 2018-09-07 10:17:50 +0200 | [diff] [blame] | 209 | struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | /** |
| 213 | * @brief YANG extension instance |
| 214 | */ |
| 215 | struct lysp_ext_instance { |
| 216 | const char *name; /**< extension identifier, including possible prefix */ |
| 217 | const char *argument; /**< optional value of the extension's argument */ |
Michal Vasko | d92e42a | 2018-09-07 08:35:02 +0200 | [diff] [blame] | 218 | LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */ |
| 219 | uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies |
| 220 | the index of that substatement */ |
Michal Vasko | bc2559f | 2018-09-07 10:17:50 +0200 | [diff] [blame] | 221 | struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | /** |
| 225 | * @brief YANG feature-stmt |
| 226 | */ |
| 227 | struct lysp_feature { |
| 228 | const char *name; /**< feature name (mandatory) */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 229 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 230 | const char *dsc; /**< description statement */ |
| 231 | const char *ref; /**< reference statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 232 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 233 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */ |
| 234 | }; |
| 235 | |
| 236 | /** |
| 237 | * @brief YANG identity-stmt |
| 238 | */ |
| 239 | struct lysp_ident { |
| 240 | const char *name; /**< identity name (mandatory), including possible prefix */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 241 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
| 242 | const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 243 | const char *dsc; /**< description statement */ |
| 244 | const char *ref; /**< reference statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 245 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 246 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */ |
| 247 | }; |
| 248 | |
Michal Vasko | 71e64ca | 2018-09-07 16:30:29 +0200 | [diff] [blame] | 249 | /** |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 250 | * @brief Covers restrictions: range, length, pattern, must |
| 251 | */ |
| 252 | struct lysp_restr { |
| 253 | const char *arg; /**< The restriction expression/value (mandatory); |
| 254 | in case of pattern restriction, the first byte has a special meaning: |
| 255 | 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */ |
| 256 | const char *emsg; /**< error-message */ |
| 257 | const char *eapptag; /**< error-app-tag value */ |
| 258 | const char *dsc; /**< description */ |
| 259 | const char *ref; /**< reference */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 260 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 261 | }; |
| 262 | |
| 263 | /** |
Michal Vasko | 71e64ca | 2018-09-07 16:30:29 +0200 | [diff] [blame] | 264 | * @brief YANG revision-stmt |
| 265 | */ |
| 266 | struct lysp_revision { |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 267 | char date[LY_REV_SIZE]; /**< revision date (madatory) */ |
Michal Vasko | 71e64ca | 2018-09-07 16:30:29 +0200 | [diff] [blame] | 268 | const char *dsc; /**< description statement */ |
| 269 | const char *ref; /**< reference statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 270 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Michal Vasko | 71e64ca | 2018-09-07 16:30:29 +0200 | [diff] [blame] | 271 | }; |
| 272 | |
| 273 | /** |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 274 | * @brief Enumeration/Bit value definition |
| 275 | */ |
| 276 | struct lysp_type_enum { |
| 277 | const char *name; /**< name (mandatory) */ |
| 278 | const char *dsc; /**< description statement */ |
| 279 | const char *ref; /**< reference statement */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 280 | int64_t value; /**< enum's value or bit's position */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 281 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 282 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 283 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE |
| 284 | values are allowed */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 285 | }; |
| 286 | |
| 287 | /** |
| 288 | * @brief YANG type-stmt |
| 289 | * |
| 290 | * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first |
| 291 | */ |
| 292 | struct lysp_type { |
| 293 | const char *name; /**< name of the type (mandatory) */ |
| 294 | struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */ |
| 295 | struct lysp_restr *length; /**< allowed length of the value - string, binary */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 296 | struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */ |
| 297 | struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */ |
| 298 | struct lysp_type_enum *bits; /**< list of bit-stmts ([sized array](@ref sizedarrays)) - bits */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 299 | const char *path; /**< path - leafref */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 300 | const char **bases; /**< list of base identifiers ([sized array](@ref sizedarrays)) - identityref */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 301 | struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */ |
| 302 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 303 | |
| 304 | uint8_t fraction_digits; /**< number of fraction digits - decimal64 */ |
| 305 | uint8_t require_instance; /**< require-instance flag - leafref, instance */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 306 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_SET_REQINST allowed */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 307 | }; |
| 308 | |
| 309 | /** |
| 310 | * @brief YANG typedef-stmt |
| 311 | */ |
| 312 | struct lysp_tpdf { |
| 313 | const char *name; /**< name of the newly defined type (mandatory) */ |
| 314 | const char *units; /**< units of the newly defined type */ |
| 315 | const char *dflt; /**< default value of the newly defined type */ |
| 316 | const char *dsc; /**< description statement */ |
| 317 | const char *ref; /**< reference statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 318 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 319 | struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */ |
| 320 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */ |
| 321 | }; |
| 322 | |
| 323 | /** |
| 324 | * @brief YANG grouping-stmt |
| 325 | */ |
| 326 | struct lysp_grp { |
| 327 | const char *name; /**< grouping name (mandatory) */ |
| 328 | const char *dsc; /**< description statement */ |
| 329 | const char *ref; /**< reference statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 330 | struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */ |
| 331 | struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 332 | struct lysp_node *data; /**< list of data nodes (linked list) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 333 | struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */ |
| 334 | struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */ |
| 335 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 336 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */ |
| 337 | }; |
| 338 | |
| 339 | /** |
| 340 | * @brief YANG when-stmt |
| 341 | */ |
| 342 | struct lysp_when { |
| 343 | const char *cond; /**< specified condition (mandatory) */ |
| 344 | const char *dsc; /**< description statement */ |
| 345 | const char *ref; /**< reference statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 346 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 347 | }; |
| 348 | |
| 349 | /** |
| 350 | * @brief YANG refine-stmt |
| 351 | */ |
| 352 | struct lysp_refine { |
| 353 | const char *nodeid; /**< target descendant schema nodeid (mandatory) */ |
| 354 | const char *dsc; /**< description statement */ |
| 355 | const char *ref; /**< reference statement */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 356 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 357 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 358 | const char *presence; /**< presence description */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 359 | const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 360 | uint32_t min; /**< min-elements constraint */ |
| 361 | uint32_t max; /**< max-elements constraint, 0 means unbounded */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 362 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 363 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 364 | }; |
| 365 | |
| 366 | /** |
| 367 | * @brief YANG uses-augment-stmt and augment-stmt |
| 368 | */ |
| 369 | struct lysp_augment { |
| 370 | const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */ |
| 371 | const char *dsc; /**< description statement */ |
| 372 | const char *ref; /**< reference statement */ |
| 373 | struct lysp_when *when; /**< when statement */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 374 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 375 | struct lysp_node *child; /**< list of data nodes (linked list) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 376 | struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */ |
| 377 | struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */ |
| 378 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 379 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */ |
| 380 | }; |
| 381 | |
| 382 | /** |
| 383 | * @defgroup deviatetypes Deviate types |
| 384 | * @{ |
| 385 | */ |
| 386 | #define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */ |
| 387 | #define LYS_DEV_ADD 2 /**< deviate type add */ |
| 388 | #define LYS_DEV_DELETE 3 /**< deviate type delete */ |
| 389 | #define LYS_DEV_REPLACE 4 /**< deviate type replace */ |
| 390 | /** @} */ |
| 391 | |
| 392 | /** |
| 393 | * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure |
| 394 | */ |
| 395 | struct lysp_deviate { |
| 396 | uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */ |
| 397 | struct lysp_deviate *next; /**< next deviate structure in the list */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 398 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 399 | }; |
| 400 | |
| 401 | struct lysp_deviate_add { |
| 402 | uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */ |
| 403 | struct lysp_deviate *next; /**< next deviate structure in the list */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 404 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 405 | const char *units; /**< units of the values */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 406 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 407 | const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */ |
| 408 | const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 409 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 410 | uint32_t min; /**< min-elements constraint */ |
| 411 | uint32_t max; /**< max-elements constraint, 0 means unbounded */ |
| 412 | }; |
| 413 | |
| 414 | struct lysp_deviate_del { |
| 415 | uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */ |
| 416 | struct lysp_deviate *next; /**< next deviate structure in the list */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 417 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 418 | const char *units; /**< units of the values */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 419 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 420 | const char **uniques; /**< list of uniques specifications ([sized array](@ref sizedarrays)) */ |
| 421 | const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 422 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 423 | }; |
| 424 | |
| 425 | struct lysp_deviate_rpl { |
| 426 | uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */ |
| 427 | struct lysp_deviate *next; /**< next deviate structure in the list */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 428 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 429 | struct lysp_type *type; /**< type of the node */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 430 | const char *units; /**< units of the values */ |
| 431 | const char *dflt; /**< default value */ |
| 432 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 433 | uint32_t min; /**< min-elements constraint */ |
| 434 | uint32_t max; /**< max-elements constraint, 0 means unbounded */ |
| 435 | }; |
| 436 | |
| 437 | struct lysp_deviation { |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 438 | const char *nodeid; /**< target absolute schema nodeid (mandatory) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 439 | const char *dsc; /**< description statement */ |
| 440 | const char *ref; /**< reference statement */ |
| 441 | struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 442 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 443 | }; |
| 444 | |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 445 | #define LYS_CONFIG_W 0x01 /**< config true; */ |
| 446 | #define LYS_CONFIG_R 0x02 /**< config false; */ |
| 447 | #define LYS_CONFIG_MASK 0x03 /**< mask for config value */ |
| 448 | #define LYS_STATUS_CURR 0x08 /**< status current; */ |
| 449 | #define LYS_STATUS_DEPRC 0x10 /**< status deprecated; */ |
| 450 | #define LYS_STATUS_OBSLT 0x20 /**< status obsolete; */ |
| 451 | #define LYS_STATUS_MASK 0x38 /**< mask for status value */ |
| 452 | #define LYS_MAND_TRUE 0x40 /**< mandatory true; applicable only to |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 453 | ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf |
| 454 | and ::lysp_node_anydata/::lysc_node_anydata */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 455 | #define LYS_MAND_FALSE 0x80 /**< mandatory false; applicable only to |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 456 | ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf |
| 457 | and ::lysp_node_anydata/::lysc_node_anydata */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 458 | #define LYS_MAND_MASK 0xc0 /**< mask for mandatory values */ |
| 459 | #define LYS_ORDBY_SYSTEM 0x100 /**< ordered-by system lists, applicable only to |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 460 | ::lysp_node_list/lysc_node_list and ::lysp_node_leaflist/::lysc_node_list */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 461 | #define LYS_ORDBY_USER 0x200 /**< ordered-by user lists, applicable only to |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 462 | ::lysp_node_list/lysc_node_list and ::lysp_node_leaflist/::lysc_node_list */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 463 | #define LYS_ORDBY_MASK 0x300 /**< mask for ordered-by flags */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 464 | #define LYS_FENABLED 0x100 /**< feature enabled flag, applicable only to ::lysp_feature/::lysc_feature */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 465 | #define LYS_AUTOASSIGNED 0x01 /**< value was auto-assigned, applicable only to |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 466 | ::lysp_type/::lysc_type enum and bits flags */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 467 | #define LYS_YINELEM_TRUE 0x01 /**< yin-element true for extension's argument */ |
| 468 | #define LYS_YINELEM_FALSE 0x02 /**< yin-element false for extension's argument */ |
| 469 | #define LYS_YINELEM_MASK 0x03 /**< mask for yin-element value */ |
| 470 | #define LYS_SET_VALUE 0x01 /**< value attribute is set */ |
| 471 | #define LYS_SET_MAX 0x400 /**< max attribute is set */ |
| 472 | #define LYS_SET_MIN 0x800 /**< min attribute is set */ |
| 473 | #define LYS_SET_REQINST 0x01 /**< require_instance attribute is set */ |
| 474 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 475 | /** |
| 476 | * @brief Generic YANG data node |
| 477 | */ |
| 478 | struct lysp_node { |
| 479 | uint16_t nodetype; /**< type of the node (mandatory) */ |
| 480 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 481 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 482 | const char *name; /**< node name (mandatory) */ |
| 483 | const char *dsc; /**< description statement */ |
| 484 | const char *ref; /**< reference statement */ |
| 485 | struct lysp_when *when; /**< when statement */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 486 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 487 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 488 | }; |
| 489 | |
| 490 | /** |
| 491 | * @brief Extension structure of the lysp_node for YANG container |
| 492 | */ |
| 493 | struct lysp_node_container { |
| 494 | uint16_t nodetype; /**< LYS_CONTAINER */ |
| 495 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 496 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 497 | const char *name; /**< node name (mandatory) */ |
| 498 | const char *dsc; /**< description statement */ |
| 499 | const char *ref; /**< reference statement */ |
| 500 | struct lysp_when *when; /**< when statement */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 501 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 502 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 503 | |
| 504 | /* container */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 505 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 506 | const char *presence; /**< presence description */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 507 | struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */ |
| 508 | struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 509 | struct lysp_node *child; /**< list of data nodes (linked list) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 510 | struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */ |
| 511 | struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 512 | }; |
| 513 | |
| 514 | struct lysp_node_leaf { |
| 515 | uint16_t nodetype; /**< LYS_LEAF */ |
| 516 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 517 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 518 | const char *name; /**< node name (mandatory) */ |
| 519 | const char *dsc; /**< description statement */ |
| 520 | const char *ref; /**< reference statement */ |
| 521 | struct lysp_when *when; /**< when statement */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 522 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 523 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 524 | |
| 525 | /* leaf */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 526 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 527 | struct lysp_type type; /**< type of the leaf node (mandatory) */ |
| 528 | const char *units; /**< units of the leaf's type */ |
| 529 | const char *dflt; /**< default value */ |
| 530 | }; |
| 531 | |
| 532 | struct lysp_node_leaflist { |
| 533 | uint16_t nodetype; /**< LYS_LEAFLIST */ |
| 534 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 535 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 536 | const char *name; /**< node name (mandatory) */ |
| 537 | const char *dsc; /**< description statement */ |
| 538 | const char *ref; /**< reference statement */ |
| 539 | struct lysp_when *when; /**< when statement */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 540 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 541 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 542 | |
| 543 | /* leaf-list */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 544 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 545 | struct lysp_type type; /**< type of the leaf node (mandatory) */ |
| 546 | const char *units; /**< units of the leaf's type */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 547 | const char **dflts; /**< list of default values ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 548 | uint32_t min; /**< min-elements constraint */ |
| 549 | uint32_t max; /**< max-elements constraint, 0 means unbounded */ |
| 550 | }; |
| 551 | |
| 552 | struct lysp_node_list { |
| 553 | uint16_t nodetype; /**< LYS_LIST */ |
| 554 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 555 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 556 | const char *name; /**< node name (mandatory) */ |
| 557 | const char *dsc; /**< description statement */ |
| 558 | const char *ref; /**< reference statement */ |
| 559 | struct lysp_when *when; /**< when statement */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 560 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 561 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 562 | |
| 563 | /* list */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 564 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 565 | const char *key; /**< keys specification */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 566 | struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */ |
| 567 | struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 568 | struct lysp_node *child; /**< list of data nodes (linked list) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 569 | struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */ |
| 570 | struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 571 | const char **uniques; /**< list of unique specifications ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 572 | uint32_t min; /**< min-elements constraint */ |
| 573 | uint32_t max; /**< max-elements constraint, 0 means unbounded */ |
| 574 | }; |
| 575 | |
| 576 | struct lysp_node_choice { |
| 577 | uint16_t nodetype; /**< LYS_CHOICE */ |
| 578 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 579 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 580 | const char *name; /**< node name (mandatory) */ |
| 581 | const char *dsc; /**< description statement */ |
| 582 | const char *ref; /**< reference statement */ |
| 583 | struct lysp_when *when; /**< when statement */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 584 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 585 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 586 | |
| 587 | /* choice */ |
| 588 | struct lysp_node *child; /**< list of data nodes (linked list) */ |
| 589 | const char* dflt; /**< default case */ |
| 590 | }; |
| 591 | |
| 592 | struct lysp_node_case { |
| 593 | uint16_t nodetype; /**< LYS_CASE */ |
| 594 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 595 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 596 | const char *name; /**< node name (mandatory) */ |
| 597 | const char *dsc; /**< description statement */ |
| 598 | const char *ref; /**< reference statement */ |
| 599 | struct lysp_when *when; /**< when statement */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 600 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 601 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 602 | |
| 603 | /* case */ |
| 604 | struct lysp_node *child; /**< list of data nodes (linked list) */ |
| 605 | }; |
| 606 | |
| 607 | struct lysp_node_anydata { |
| 608 | uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */ |
| 609 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 610 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 611 | const char *name; /**< node name (mandatory) */ |
| 612 | const char *dsc; /**< description statement */ |
| 613 | const char *ref; /**< reference statement */ |
| 614 | struct lysp_when *when; /**< when statement */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 615 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 616 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 617 | |
| 618 | /* anyxml/anydata */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 619 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 620 | }; |
| 621 | |
| 622 | struct lysp_node_uses { |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 623 | uint16_t nodetype; /**< LYS_USES */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 624 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 625 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 626 | const char *name; /**< grouping name reference (mandatory) */ |
| 627 | const char *dsc; /**< description statement */ |
| 628 | const char *ref; /**< reference statement */ |
| 629 | struct lysp_when *when; /**< when statement */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 630 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 631 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 632 | |
| 633 | /* uses */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 634 | struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */ |
| 635 | struct lysp_augment *augments; /**< list of uses's augment ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 636 | }; |
| 637 | |
| 638 | /** |
| 639 | * @brief YANG input-stmt and output-stmt |
| 640 | */ |
| 641 | struct lysp_action_inout { |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 642 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
| 643 | struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */ |
| 644 | struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 645 | struct lysp_node *data; /**< list of data nodes (linked list) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 646 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 647 | }; |
| 648 | |
| 649 | /** |
| 650 | * @brief YANG rpc-stmt and action-stmt |
| 651 | */ |
| 652 | struct lysp_action { |
| 653 | const char *name; /**< grouping name reference (mandatory) */ |
| 654 | const char *dsc; /**< description statement */ |
| 655 | const char *ref; /**< reference statement */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 656 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 657 | struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */ |
| 658 | struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 659 | struct lysp_action_inout *input; /**< RPC's/Action's input */ |
| 660 | struct lysp_action_inout *output;/**< RPC's/Action's output */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 661 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 662 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 663 | }; |
| 664 | |
| 665 | /** |
| 666 | * @brief YANG notification-stmt |
| 667 | */ |
| 668 | struct lysp_notif { |
| 669 | const char *name; /**< grouping name reference (mandatory) */ |
| 670 | const char *dsc; /**< description statement */ |
| 671 | const char *ref; /**< reference statement */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 672 | const char **iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 673 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
| 674 | struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */ |
| 675 | struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 676 | struct lysp_node *data; /**< list of data nodes (linked list) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 677 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 678 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */ |
| 679 | }; |
| 680 | |
| 681 | /** |
Radek Krejci | f0fceb6 | 2018-09-05 14:58:45 +0200 | [diff] [blame] | 682 | * @brief supported YANG schema version values |
| 683 | */ |
| 684 | typedef enum LYS_VERSION { |
| 685 | LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */ |
| 686 | LYS_VERSION_1_0 = 1, /**< YANG 1.0 */ |
| 687 | LYS_VERSION_1_1 = 2 /**< YANG 1.1 */ |
| 688 | } LYS_VERSION; |
| 689 | |
| 690 | /** |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 691 | * @brief Printable YANG schema tree structure representing YANG module. |
| 692 | * |
| 693 | * Simple structure corresponding to the YANG format. The schema is only syntactically validated. |
| 694 | */ |
| 695 | struct lysp_module { |
| 696 | struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */ |
| 697 | const char *name; /**< name of the module (mandatory) */ |
Radek Krejci | 6d6e4e4 | 2018-10-29 13:28:19 +0100 | [diff] [blame] | 698 | const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 699 | union { |
| 700 | /* module */ |
Michal Vasko | d5927ca | 2018-09-07 15:05:32 +0200 | [diff] [blame] | 701 | const char *ns; /**< namespace of the module (module - mandatory) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 702 | /* submodule */ |
Michal Vasko | d5927ca | 2018-09-07 15:05:32 +0200 | [diff] [blame] | 703 | const char *belongsto; /**< belongs to parent module (submodule - mandatory) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 704 | }; |
Michal Vasko | d5927ca | 2018-09-07 15:05:32 +0200 | [diff] [blame] | 705 | const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */ |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 706 | struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision |
| 707 | in the list is always the last (newest) revision of the module */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 708 | struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */ |
| 709 | struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 710 | const char *org; /**< party/company responsible for the module */ |
| 711 | const char *contact; /**< contact information for the module */ |
| 712 | const char *dsc; /**< description of the module */ |
| 713 | const char *ref; /**< cross-reference for the module */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 714 | struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */ |
| 715 | struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */ |
| 716 | struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */ |
| 717 | struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */ |
| 718 | struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 719 | struct lysp_node *data; /**< list of module's top-level data nodes (linked list) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 720 | struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */ |
| 721 | struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */ |
| 722 | struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */ |
| 723 | struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */ |
| 724 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 725 | |
Radek Krejci | f0fceb6 | 2018-09-05 14:58:45 +0200 | [diff] [blame] | 726 | uint8_t submodule:1; /**< flag to distinguish main modules and submodules */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 727 | uint8_t implemented:1; /**< flag if the module is implemented, not just imported */ |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 728 | uint8_t latest_revision:2; /**< flag to mark the latest available revision: |
| 729 | 1 - the latest revision in searchdirs was not searched yet and this is the |
| 730 | latest revision in the current context |
| 731 | 2 - searchdirs were searched and this is the latest available revision */ |
| 732 | uint8_t parsing:1; /**< flag for circular check */ |
| 733 | uint8_t version; /**< yang-version (LYS_VERSION values) */ |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 734 | uint16_t refcount; /**< 0 in modules, number of includes of a submodules */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 735 | }; |
| 736 | |
| 737 | /** |
Radek Krejci | 3f5e3db | 2018-10-11 15:57:47 +0200 | [diff] [blame] | 738 | * @brief Free the printable YANG schema tree structure. |
| 739 | * |
| 740 | * @param[in] module Printable YANG schema tree structure to free. |
| 741 | */ |
| 742 | void lysp_module_free(struct lysp_module *module); |
| 743 | |
| 744 | /** |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 745 | * @brief YANG extension instance |
| 746 | */ |
| 747 | struct lysc_ext_instance { |
| 748 | struct lyext_plugin *plugin; /**< pointer to the plugin implementing the extension (if present) */ |
| 749 | void *parent; /**< pointer to the parent element holding the extension instance(s), use |
| 750 | ::lysc_ext_instance#parent_type to access the schema element */ |
| 751 | const char *argument; /**< optional value of the extension's argument */ |
| 752 | LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */ |
| 753 | uint32_t insubstmt_index; /**< in case the instance is in a substatement that can appear multiple times, |
| 754 | this identifies the index of the substatement for this extension instance */ |
Radek Krejci | 2a408df | 2018-10-29 16:32:26 +0100 | [diff] [blame] | 755 | LYEXT_PARENT parent_type; /**< type of the parent structure */ |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 756 | #if 0 |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 757 | uint8_t ext_type; /**< extension type (#LYEXT_TYPE) */ |
| 758 | uint8_t padding; /**< 32b padding */ |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 759 | struct lys_module *module; /**< pointer to the extension instance's module (mandatory) */ |
| 760 | LYS_NODE nodetype; /**< LYS_EXT */ |
| 761 | #endif |
Radek Krejci | 2a408df | 2018-10-29 16:32:26 +0100 | [diff] [blame] | 762 | struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
| 763 | void *priv; /**< private caller's data, not used by libyang */ |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 764 | }; |
| 765 | |
| 766 | /** |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 767 | * @brief YANG import-stmt |
| 768 | */ |
| 769 | struct lysc_import { |
Radek Krejci | 6d6e4e4 | 2018-10-29 13:28:19 +0100 | [diff] [blame] | 770 | struct lys_module *module; /**< link to the imported module */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 771 | const char *prefix; /**< prefix for the data from the imported schema (mandatory) */ |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 772 | struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 773 | }; |
| 774 | |
| 775 | /** |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 776 | * @brief YANG when-stmt |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 777 | */ |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 778 | struct lysc_when { |
| 779 | struct lyxp_expr *cond; /**< XPath when condition */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 780 | struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 781 | }; |
| 782 | |
| 783 | /** |
Radek Krejci | 2a408df | 2018-10-29 16:32:26 +0100 | [diff] [blame] | 784 | * @brief YANG identity-stmt |
| 785 | */ |
| 786 | struct lysc_ident { |
| 787 | const char *name; /**< identity name (mandatory), including possible prefix */ |
| 788 | struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
| 789 | struct lysc_ident **derived; /**< list of (pointers to the) derived identities ([sized array](@ref sizedarrays)) */ |
| 790 | struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
| 791 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */ |
| 792 | }; |
| 793 | |
| 794 | /** |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 795 | * @brief YANG feature-stmt |
| 796 | */ |
| 797 | struct lysc_feature { |
| 798 | const char *name; /**< feature name (mandatory) */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 799 | struct lysc_feature **depfeatures;/**< list of pointers to other features depending on this one ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 800 | struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 801 | struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 802 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and |
| 803 | #LYS_FENABLED values allowed */ |
| 804 | }; |
| 805 | |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 806 | /** |
| 807 | * @defgroup ifftokens if-feature expression tokens |
| 808 | * Tokens of if-feature expression used in ::lysc_iffeature#expr |
| 809 | * |
| 810 | * @{ |
| 811 | */ |
| 812 | #define LYS_IFF_NOT 0x00 /**< operand "not" */ |
| 813 | #define LYS_IFF_AND 0x01 /**< operand "and" */ |
| 814 | #define LYS_IFF_OR 0x02 /**< operand "or" */ |
| 815 | #define LYS_IFF_F 0x03 /**< feature */ |
| 816 | /** |
| 817 | * @} |
| 818 | */ |
| 819 | |
| 820 | /** |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 821 | * @brief Compiled YANG revision statement |
| 822 | */ |
| 823 | struct lysc_revision { |
| 824 | char date[LY_REV_SIZE]; /**< revision-date (mandatory) */ |
| 825 | struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
| 826 | }; |
| 827 | |
| 828 | /** |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 829 | * @brief Compiled YANG if-feature-stmt |
| 830 | */ |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 831 | struct lysc_iffeature { |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 832 | uint8_t *expr; /**< 2bits array describing the if-feature expression in prefix format, see @ref ifftokens */ |
| 833 | struct lysc_feature **features; /**< array of pointers to the features used in expression ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 834 | }; |
| 835 | |
| 836 | /** |
Radek Krejci | 0af5f5d | 2018-09-07 15:00:30 +0200 | [diff] [blame] | 837 | * @brief Compiled YANG data node |
| 838 | */ |
| 839 | struct lysc_node { |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 840 | uint16_t nodetype; /**< type of the node (mandatory) */ |
| 841 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 842 | struct lysp_node *sp; /**< link to the simply parsed (SP) original of the node, NULL if the SP schema was removed. */ |
| 843 | struct lysc_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 844 | const char *name; /**< node name (mandatory) */ |
| 845 | struct lysc_when *when; /**< when statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 846 | struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
| 847 | struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 848 | }; |
| 849 | |
| 850 | /** |
| 851 | * @brief Compiled YANG schema tree structure representing YANG module. |
| 852 | * |
| 853 | * Semantically validated YANG schema tree for data tree parsing. |
| 854 | * Contains only the necessary information for the data validation. |
| 855 | */ |
| 856 | struct lysc_module { |
| 857 | struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */ |
| 858 | const char *name; /**< name of the module (mandatory) */ |
Radek Krejci | 6d6e4e4 | 2018-10-29 13:28:19 +0100 | [diff] [blame] | 859 | const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */ |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 860 | const char *ns; /**< namespace of the module (mandatory) */ |
| 861 | const char *prefix; /**< module prefix (mandatory) */ |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 862 | const char *revision; /**< the revision of the module */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 863 | struct lysc_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */ |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 864 | |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 865 | struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 2a408df | 2018-10-29 16:32:26 +0100 | [diff] [blame] | 866 | struct lysc_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */ |
| 867 | struct lysc_node *data; /**< list of module's top-level data nodes (linked list) */ |
| 868 | struct lysc_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */ |
| 869 | struct lysc_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */ |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 870 | struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 871 | |
| 872 | uint8_t implemented:1; /**< flag if the module is implemented, not just imported */ |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 873 | uint8_t latest_revision:2; /**< flag to mark the latest available revision: |
| 874 | 1 - the latest revision in searchdirs was not searched yet and this is the |
| 875 | latest revision in the current context |
| 876 | 2 - searchdirs were searched and this is the latest available revision */ |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 877 | uint8_t version; /**< yang-version (LYS_VERSION values) */ |
Radek Krejci | 0af5f5d | 2018-09-07 15:00:30 +0200 | [diff] [blame] | 878 | }; |
| 879 | |
| 880 | /** |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 881 | * @brief Get how the if-feature statement currently evaluates. |
| 882 | * |
| 883 | * @param[in] iff Compiled if-feature statement to evaluate. |
| 884 | * @return If the statement evaluates to true, 1 is returned. 0 is returned when the statement evaluates to false. |
| 885 | */ |
| 886 | int lysc_iffeature_value(const struct lysc_iffeature *iff); |
| 887 | |
| 888 | /** |
| 889 | * @brief Get the current status of the provided feature. |
| 890 | * |
| 891 | * @param[in] feature Compiled feature statement to examine. |
| 892 | * @return |
| 893 | * - 1 if feature is enabled, |
| 894 | * - 0 if feature is disabled, |
| 895 | * - -1 in case of error (invalid argument) |
| 896 | */ |
| 897 | int lysc_feature_value(const struct lysc_feature *feature); |
| 898 | |
| 899 | /** |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 900 | * @brief Available YANG schema tree structures representing YANG module. |
| 901 | */ |
| 902 | struct lys_module { |
| 903 | struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */ |
| 904 | struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing */ |
| 905 | }; |
| 906 | |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 907 | /** |
| 908 | * @brief Enable specified feature in the module |
| 909 | * |
| 910 | * By default, when the module is loaded by libyang parser, all features are disabled. |
| 911 | * |
Radek Krejci | ca3db00 | 2018-11-01 10:31:01 +0100 | [diff] [blame] | 912 | * If all features are being enabled, it must be possible respecting their if-feature conditions. For example, |
| 913 | * enabling all features on the following feature set will fail since it is not possible to enable both features |
| 914 | * (and it is unclear which of them should be enabled then). In this case the LY_EDENIED is returned and the feature |
| 915 | * is untouched. |
| 916 | * |
| 917 | * feature f1; |
| 918 | * feature f2 { if-feature 'not f1';} |
| 919 | * |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 920 | * @param[in] module Module where the feature will be enabled. |
| 921 | * @param[in] feature Name of the feature to enable. To enable all features at once, use asterisk (`*`) character. |
| 922 | * @return LY_ERR value. |
| 923 | */ |
| 924 | LY_ERR lys_feature_enable(struct lys_module *module, const char *feature); |
| 925 | |
| 926 | /** |
| 927 | * @brief Disable specified feature in the module |
| 928 | * |
| 929 | * By default, when the module is loaded by libyang parser, all features are disabled. |
| 930 | * |
| 931 | * @param[in] module Module where the feature will be disabled. |
| 932 | * @param[in] feature Name of the feature to disable. To disable all features at once, use asterisk (`*`) character. |
| 933 | * @return LY_ERR value |
| 934 | */ |
| 935 | LY_ERR lys_feature_disable(struct lys_module *module, const char *feature); |
| 936 | |
| 937 | /** |
| 938 | * @brief Get the current status of the specified feature in the module. |
| 939 | * |
| 940 | * @param[in] module Module where the feature is defined. |
| 941 | * @param[in] feature Name of the feature to inspect. |
| 942 | * @return |
| 943 | * - 1 if feature is enabled, |
| 944 | * - 0 if feature is disabled, |
| 945 | * - -1 in case of error (e.g. feature is not defined or invalid arguments) |
| 946 | */ |
| 947 | int lys_feature_value(const struct lys_module *module, const char *feature); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 948 | |
| 949 | /** |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 950 | * @brief Load a schema into the specified context. |
| 951 | * |
| 952 | * @param[in] ctx libyang context where to process the data model. |
| 953 | * @param[in] data The string containing the dumped data model in the specified |
| 954 | * format. |
| 955 | * @param[in] format Format of the input data (YANG or YIN). |
| 956 | * @return Pointer to the data model structure or NULL on error. |
| 957 | */ |
Radek Krejci | d14e969 | 2018-11-01 11:00:37 +0100 | [diff] [blame] | 958 | struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format); |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 959 | |
| 960 | /** |
| 961 | * @brief Read a schema from file descriptor into the specified context. |
| 962 | * |
| 963 | * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc. |
| 964 | * |
| 965 | * @param[in] ctx libyang context where to process the data model. |
| 966 | * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema |
| 967 | * in the specified format. |
| 968 | * @param[in] format Format of the input data (YANG or YIN). |
| 969 | * @return Pointer to the data model structure or NULL on error. |
| 970 | */ |
Radek Krejci | d14e969 | 2018-11-01 11:00:37 +0100 | [diff] [blame] | 971 | struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format); |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 972 | |
| 973 | /** |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 974 | * @brief Read a schema into the specified context from a file. |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 975 | * |
| 976 | * @param[in] ctx libyang context where to process the data model. |
| 977 | * @param[in] path Path to the file with the model in the specified format. |
| 978 | * @param[in] format Format of the input data (YANG or YIN). |
| 979 | * @return Pointer to the data model structure or NULL on error. |
| 980 | */ |
Radek Krejci | d14e969 | 2018-11-01 11:00:37 +0100 | [diff] [blame] | 981 | struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format); |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 982 | |
| 983 | /** |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 984 | * @brief Search for the schema file in the specified searchpaths. |
| 985 | * |
| 986 | * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working |
| 987 | * directory is searched automatically (but non-recursively if not in the provided list). Caller can use |
| 988 | * result of the ly_ctx_get_searchdirs(). |
| 989 | * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively). |
| 990 | * @param[in] name Name of the schema to find. |
| 991 | * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned. |
| 992 | * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema |
| 993 | * complying the provided restriction is found, NULL is set. |
| 994 | * @param[out] format Optional output variable containing expected format of the schema document according to the |
| 995 | * file suffix. |
| 996 | * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL). |
| 997 | */ |
| 998 | LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format); |
| 999 | |
| 1000 | /** |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 1001 | * @defgroup scflags Schema compile flags |
| 1002 | * @ingroup schematree |
| 1003 | * |
| 1004 | * @{ |
| 1005 | */ |
| 1006 | #define LYSC_OPT_FREE_SP 1 /**< Free the input printable schema */ |
| 1007 | |
| 1008 | /** |
| 1009 | * @} |
| 1010 | */ |
| 1011 | |
| 1012 | /** |
| 1013 | * @brief Compile printable schema into a validated schema linking all the references. |
| 1014 | * |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 1015 | * @param[in, out] mod Schema structure holding pointers to both schema structure types. The ::lys_module#parsed |
| 1016 | * member is used as input and ::lys_module#compiled is used to hold the result of the compilation. |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 1017 | * @param[in] options Various options to modify compiler behavior, see [compile flags](@ref scflags). |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 1018 | * @return LY_ERR value. |
| 1019 | */ |
Radek Krejci | d14e969 | 2018-11-01 11:00:37 +0100 | [diff] [blame] | 1020 | LY_ERR lys_compile(struct lys_module *mod, int options); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 1021 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 1022 | /** @} */ |
| 1023 | |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 1024 | #ifdef __cplusplus |
| 1025 | } |
| 1026 | #endif |
| 1027 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 1028 | #endif /* LY_TREE_SCHEMA_H_ */ |