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 | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 20 | #ifdef __cplusplus |
| 21 | extern "C" { |
| 22 | #endif |
| 23 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 24 | /** |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 25 | * @brief XPath representation. |
| 26 | */ |
| 27 | struct lyxp_expr; |
| 28 | |
| 29 | /** |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 30 | * @brief Macro selector for other LY_ARRAY_* macros, do not use directly! |
| 31 | */ |
| 32 | #define LY_ARRAY_SELECT(_1, _2, NAME, ...) NAME |
| 33 | |
| 34 | /** |
| 35 | * @brief Get void pointer to the item on the INDEX in the ARRAY |
| 36 | */ |
| 37 | #define LY_ARRAY_INDEX1(ARRAY, INDEX) ((void*)((uint32_t*)((ARRAY) + INDEX) + 1)) |
| 38 | |
| 39 | /** |
| 40 | * @brief Get the TYPE pointer to the item on the INDEX in the ARRAY |
| 41 | */ |
| 42 | #define LY_ARRAY_INDEX2(ARRAY, INDEX, TYPE) ((TYPE*)((uint32_t*)((ARRAY) + INDEX) + 1)) |
| 43 | |
| 44 | /** |
| 45 | * @brief Helper macro to go through sized-arrays with a pointer iterator. |
| 46 | * |
| 47 | * Use with opening curly bracket (`{`). |
| 48 | * |
| 49 | * @param[in] ARRAY Array to go through |
| 50 | * @param[in] TYPE Type of the records in the ARRAY |
| 51 | * @param[out] ITER Iterating pointer to the item being processed in each loop |
| 52 | */ |
| 53 | #define LY_ARRAY_FOR_ITER(ARRAY, TYPE, ITER) \ |
| 54 | for (ITER = LY_ARRAY_INDEX1(ARRAY, 0); \ |
| 55 | (ARRAY) && ((void*)ITER - (void*)ARRAY - sizeof(uint32_t))/(sizeof(TYPE)) < (*(uint32_t*)(ARRAY)); \ |
| 56 | ITER = (void*)((TYPE*)ITER + 1)) |
| 57 | |
| 58 | /** |
| 59 | * @brief Helper macro to go through sized-arrays with a numeric iterator. |
| 60 | * |
| 61 | * Use with opening curly bracket (`{`). |
| 62 | * |
| 63 | * To access an item with the INDEX value, use always LY_ARRAY_INDEX macro! |
| 64 | * |
| 65 | * @param[in] ARRAY Array to go through |
| 66 | * @param[out] INDEX Iterating index of the item being processed in each loop |
| 67 | */ |
| 68 | #define LY_ARRAY_FOR_INDEX(ARRAY, INDEX) \ |
| 69 | for (INDEX = 0; \ |
| 70 | ARRAY && INDEX < (*((uint32_t*)(ARRAY))); \ |
| 71 | ++INDEX) |
| 72 | |
| 73 | /** |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 74 | * @defgroup schematree Schema Tree |
| 75 | * @{ |
| 76 | * |
| 77 | * Data structures and functions to manipulate and access schema tree. |
| 78 | */ |
| 79 | |
Radek Krejci | 0af5f5d | 2018-09-07 15:00:30 +0200 | [diff] [blame] | 80 | /** |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 81 | * @brief Get (optionally TYPEd) pointer to the item on the INDEX in the ARRAY |
Radek Krejci | 5fac359 | 2018-10-12 15:23:45 +0200 | [diff] [blame] | 82 | * |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 83 | * LY_ARRAY_INDEX(ARRAY, INDEX [, TYPE]) |
Radek Krejci | 5fac359 | 2018-10-12 15:23:45 +0200 | [diff] [blame] | 84 | */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 85 | #define LY_ARRAY_INDEX(ARRAY, ...) LY_ARRAY_SELECT(__VA_ARGS__, LY_ARRAY_INDEX2, LY_ARRAY_INDEX1)(ARRAY, __VA_ARGS__) |
| 86 | |
| 87 | /** |
| 88 | * @brief Get a number of records in the ARRAY. |
| 89 | */ |
| 90 | #define LY_ARRAY_SIZE(ARRAY) (*((uint32_t*)(ARRAY))) |
| 91 | |
| 92 | /** |
| 93 | * @brief Sized-array iterator (for-loop). |
| 94 | * |
| 95 | * Use with opening curly bracket (`{`). |
| 96 | * |
| 97 | * There are 2 variants: |
| 98 | * |
| 99 | * LY_ARRAY_FOR(ARRAY, TYPE, ITER) |
| 100 | * |
| 101 | * 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 |
| 102 | * providing the items of the ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_ITER macro |
| 103 | * |
| 104 | * LY_ARRAY_FOR(ARRAY, INDEX) |
| 105 | * |
| 106 | * The ARRAY is again a sized-array to go through, the INDEX is a variable (unsigned integer) for storing iterating ARRAY's index |
| 107 | * to access the items of ARRAY in the loops. The INDEX is supposed to be used via LY_ARRAY_INDEX macro which can provide the item |
| 108 | * in the loop body. This functionality is provided by LY_ARRAY_FOR_INDEX macro. |
| 109 | */ |
| 110 | #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] | 111 | |
| 112 | /** |
| 113 | * @brief Macro to iterate via all sibling elements without affecting the list itself |
| 114 | * |
| 115 | * Works for all types of nodes despite it is data or schema tree, but all the |
| 116 | * parameters must be pointers to the same type. |
| 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 ELEM Iterator. |
| 122 | */ |
| 123 | #define LY_LIST_FOR(START, ELEM) \ |
| 124 | for ((ELEM) = (START); \ |
| 125 | (ELEM); \ |
| 126 | (ELEM) = (ELEM)->next) |
| 127 | |
| 128 | /** |
| 129 | * @ingroup datatree |
| 130 | * @brief Macro to iterate via all sibling elements allowing to modify the list itself (e.g. removing elements) |
| 131 | * |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 132 | * 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] | 133 | * |
| 134 | * @param START Pointer to the starting element. |
| 135 | * @param NEXT Temporary storage to allow removing of the current iterator content. |
| 136 | * @param ELEM Iterator. |
| 137 | */ |
| 138 | #define LY_LIST_FOR_SAFE(START, NEXT, ELEM) \ |
| 139 | for ((ELEM) = (START); \ |
| 140 | (ELEM) ? (NEXT = (ELEM)->next, 1) : 0; \ |
| 141 | (ELEM) = (NEXT)) |
| 142 | |
| 143 | /** |
Radek Krejci | 0af5f5d | 2018-09-07 15:00:30 +0200 | [diff] [blame] | 144 | * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers). |
| 145 | */ |
| 146 | typedef enum { |
| 147 | LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */ |
| 148 | LYS_IN_YANG = 1, /**< YANG schema input format */ |
| 149 | LYS_IN_YIN = 2 /**< YIN schema input format */ |
| 150 | } LYS_INFORMAT; |
| 151 | |
| 152 | /** |
| 153 | * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters). |
| 154 | */ |
| 155 | typedef enum { |
| 156 | LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */ |
| 157 | LYS_OUT_YANG = 1, /**< YANG schema output format */ |
| 158 | LYS_OUT_YIN = 2, /**< YIN schema output format */ |
| 159 | LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */ |
| 160 | LYS_OUT_INFO, /**< Info schema output format, for more information see the [printers](@ref howtoschemasprinters) page */ |
| 161 | LYS_OUT_JSON, /**< JSON schema output format, reflecting YIN format with conversion of attributes to object's members */ |
| 162 | } LYS_OUTFORMAT; |
| 163 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 164 | #define LY_REV_SIZE 11 /**< revision data string length (including terminating NULL byte) */ |
| 165 | |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 166 | #define LYS_UNKNOWN 0x0000 /**< uninitalized unknown statement node */ |
| 167 | #define LYS_CONTAINER 0x0001 /**< container statement node */ |
| 168 | #define LYS_CHOICE 0x0002 /**< choice statement node */ |
| 169 | #define LYS_LEAF 0x0004 /**< leaf statement node */ |
| 170 | #define LYS_LEAFLIST 0x0008 /**< leaf-list statement node */ |
| 171 | #define LYS_LIST 0x0010 /**< list statement node */ |
| 172 | #define LYS_ANYXML 0x0020 /**< anyxml statement node */ |
| 173 | #define LYS_CASE 0x0040 /**< case statement node */ |
| 174 | #define LYS_USES 0x0080 /**< uses statement node */ |
| 175 | #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] | 176 | |
| 177 | /** |
| 178 | * @brief YANG import-stmt |
| 179 | */ |
| 180 | struct lysp_import { |
Michal Vasko | d5927ca | 2018-09-07 15:05:32 +0200 | [diff] [blame] | 181 | const char *name; /**< name of the module to import (mandatory) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 182 | const char *prefix; /**< prefix for the data from the imported schema (mandatory) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 183 | const char *dsc; /**< description */ |
| 184 | const char *ref; /**< reference */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 185 | 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] | 186 | char rev[LY_REV_SIZE]; /**< revision-date of the imported module */ |
| 187 | }; |
| 188 | |
| 189 | /** |
| 190 | * @brief YANG include-stmt |
| 191 | */ |
| 192 | struct lysp_include { |
Michal Vasko | d5927ca | 2018-09-07 15:05:32 +0200 | [diff] [blame] | 193 | const char *name; /**< name of the submodule to include (mandatory) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 194 | const char *dsc; /**< description */ |
| 195 | const char *ref; /**< reference */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 196 | 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] | 197 | char rev[LY_REV_SIZE]; /**< revision-date of the included submodule */ |
| 198 | }; |
| 199 | |
| 200 | /** |
| 201 | * @brief YANG extension-stmt |
| 202 | */ |
| 203 | struct lysp_ext { |
| 204 | const char *name; /**< extension name */ |
| 205 | const char *argument; /**< argument name, NULL if not specified */ |
| 206 | const char *dsc; /**< description statement */ |
| 207 | const char *ref; /**< reference statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 208 | 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] | 209 | uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM values (@ref snodeflags) */ |
| 210 | }; |
| 211 | |
| 212 | /** |
| 213 | * @brief Helper structure for generic storage of the extension instances content. |
| 214 | */ |
| 215 | struct lysp_stmt { |
| 216 | const char *stmt; /**< identifier of the statement */ |
| 217 | const char *arg; /**< statement's argument */ |
| 218 | struct lysp_stmt *next; /**< link to the next statement */ |
Michal Vasko | bc2559f | 2018-09-07 10:17:50 +0200 | [diff] [blame] | 219 | struct lysp_stmt *child; /**< list of the statement's substatements (linked list) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 220 | }; |
| 221 | |
| 222 | /** |
Michal Vasko | d92e42a | 2018-09-07 08:35:02 +0200 | [diff] [blame] | 223 | * @brief Enum of substatements in which extension instances can appear. |
| 224 | */ |
| 225 | typedef enum { |
| 226 | LYEXT_SUBSTMT_SELF = 0, /**< extension of the structure itself, not substatement's */ |
| 227 | LYEXT_SUBSTMT_ARGUMENT, /**< extension of the argument statement, can appear in lys_ext */ |
| 228 | LYEXT_SUBSTMT_BASE, /**< extension of the base statement, can appear (repeatedly) in lys_type and lys_ident */ |
| 229 | LYEXT_SUBSTMT_BELONGSTO, /**< extension of the belongs-to statement, can appear in lys_submodule */ |
| 230 | LYEXT_SUBSTMT_CONTACT, /**< extension of the contact statement, can appear in lys_module */ |
| 231 | LYEXT_SUBSTMT_DEFAULT, /**< extension of the default statement, can appear in lys_node_leaf, lys_node_leaflist, |
| 232 | lys_node_choice and lys_deviate */ |
| 233 | LYEXT_SUBSTMT_DESCRIPTION, /**< extension of the description statement, can appear in lys_module, lys_submodule, |
| 234 | lys_node, lys_import, lys_include, lys_ext, lys_feature, lys_tpdf, lys_restr, |
| 235 | lys_ident, lys_deviation, lys_type_enum, lys_type_bit, lys_when and lys_revision */ |
| 236 | LYEXT_SUBSTMT_ERRTAG, /**< extension of the error-app-tag statement, can appear in lys_restr */ |
| 237 | LYEXT_SUBSTMT_ERRMSG, /**< extension of the error-message statement, can appear in lys_restr */ |
| 238 | LYEXT_SUBSTMT_KEY, /**< extension of the key statement, can appear in lys_node_list */ |
| 239 | LYEXT_SUBSTMT_NAMESPACE, /**< extension of the namespace statement, can appear in lys_module */ |
| 240 | LYEXT_SUBSTMT_ORGANIZATION, /**< extension of the organization statement, can appear in lys_module and lys_submodule */ |
| 241 | LYEXT_SUBSTMT_PATH, /**< extension of the path statement, can appear in lys_type */ |
| 242 | LYEXT_SUBSTMT_PREFIX, /**< extension of the prefix statement, can appear in lys_module, lys_submodule (for |
| 243 | belongs-to's prefix) and lys_import */ |
| 244 | LYEXT_SUBSTMT_PRESENCE, /**< extension of the presence statement, can appear in lys_node_container */ |
| 245 | LYEXT_SUBSTMT_REFERENCE, /**< extension of the reference statement, can appear in lys_module, lys_submodule, |
| 246 | lys_node, lys_import, lys_include, lys_revision, lys_tpdf, lys_restr, lys_ident, |
| 247 | lys_ext, lys_feature, lys_deviation, lys_type_enum, lys_type_bit and lys_when */ |
| 248 | LYEXT_SUBSTMT_REVISIONDATE, /**< extension of the revision-date statement, can appear in lys_import and lys_include */ |
| 249 | LYEXT_SUBSTMT_UNITS, /**< extension of the units statement, can appear in lys_tpdf, lys_node_leaf, |
| 250 | lys_node_leaflist and lys_deviate */ |
| 251 | LYEXT_SUBSTMT_VALUE, /**< extension of the value statement, can appear in lys_type_enum */ |
| 252 | LYEXT_SUBSTMT_VERSION, /**< extension of the yang-version statement, can appear in lys_module and lys_submodule */ |
| 253 | LYEXT_SUBSTMT_MODIFIER, /**< extension of the modifier statement, can appear in lys_restr */ |
| 254 | LYEXT_SUBSTMT_REQINSTANCE, /**< extension of the require-instance statement, can appear in lys_type */ |
| 255 | LYEXT_SUBSTMT_YINELEM, /**< extension of the yin-element statement, can appear in lys_ext */ |
| 256 | LYEXT_SUBSTMT_CONFIG, /**< extension of the config statement, can appear in lys_node and lys_deviate */ |
| 257 | LYEXT_SUBSTMT_MANDATORY, /**< extension of the mandatory statement, can appear in lys_node_leaf, lys_node_choice, |
| 258 | lys_node_anydata and lys_deviate */ |
| 259 | LYEXT_SUBSTMT_ORDEREDBY, /**< extension of the ordered-by statement, can appear in lys_node_list and lys_node_leaflist */ |
| 260 | LYEXT_SUBSTMT_STATUS, /**< extension of the status statement, can appear in lys_tpdf, lys_node, lys_ident, |
| 261 | lys_ext, lys_feature, lys_type_enum and lys_type_bit */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 262 | LYEXT_SUBSTMT_FRACDIGITS, /**< extension of the fraction-digits statement, can appear in lys_type */ |
Michal Vasko | d92e42a | 2018-09-07 08:35:02 +0200 | [diff] [blame] | 263 | LYEXT_SUBSTMT_MAX, /**< extension of the max-elements statement, can appear in lys_node_list, |
| 264 | lys_node_leaflist and lys_deviate */ |
| 265 | LYEXT_SUBSTMT_MIN, /**< extension of the min-elements statement, can appear in lys_node_list, |
| 266 | lys_node_leaflist and lys_deviate */ |
| 267 | LYEXT_SUBSTMT_POSITION, /**< extension of the position statement, can appear in lys_type_bit */ |
| 268 | LYEXT_SUBSTMT_UNIQUE, /**< extension of the unique statement, can appear in lys_node_list and lys_deviate */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 269 | LYEXT_SUBSTMT_IFFEATURE, /**< extension of the if-feature statement */ |
Michal Vasko | d92e42a | 2018-09-07 08:35:02 +0200 | [diff] [blame] | 270 | } LYEXT_SUBSTMT; |
| 271 | |
| 272 | /** |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 273 | * @brief YANG extension instance |
| 274 | */ |
| 275 | struct lysp_ext_instance { |
| 276 | const char *name; /**< extension identifier, including possible prefix */ |
| 277 | const char *argument; /**< optional value of the extension's argument */ |
Michal Vasko | d92e42a | 2018-09-07 08:35:02 +0200 | [diff] [blame] | 278 | LYEXT_SUBSTMT insubstmt; /**< value identifying placement of the extension instance */ |
| 279 | uint32_t insubstmt_index; /**< in case the instance is in a substatement, this identifies |
| 280 | the index of that substatement */ |
Michal Vasko | bc2559f | 2018-09-07 10:17:50 +0200 | [diff] [blame] | 281 | struct lysp_stmt *child; /**< list of the extension's substatements (linked list) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 282 | }; |
| 283 | |
| 284 | /** |
| 285 | * @brief YANG feature-stmt |
| 286 | */ |
| 287 | struct lysp_feature { |
| 288 | const char *name; /**< feature name (mandatory) */ |
| 289 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
| 290 | const char *dsc; /**< description statement */ |
| 291 | const char *ref; /**< reference statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 292 | 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] | 293 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */ |
| 294 | }; |
| 295 | |
| 296 | /** |
| 297 | * @brief YANG identity-stmt |
| 298 | */ |
| 299 | struct lysp_ident { |
| 300 | const char *name; /**< identity name (mandatory), including possible prefix */ |
| 301 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
| 302 | const char **bases; /**< list of base identifiers (NULL-terminated) */ |
| 303 | const char *dsc; /**< description statement */ |
| 304 | const char *ref; /**< reference statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 305 | 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] | 306 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ values are allowed */ |
| 307 | }; |
| 308 | |
Michal Vasko | 71e64ca | 2018-09-07 16:30:29 +0200 | [diff] [blame] | 309 | /** |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 310 | * @brief Covers restrictions: range, length, pattern, must |
| 311 | */ |
| 312 | struct lysp_restr { |
| 313 | const char *arg; /**< The restriction expression/value (mandatory); |
| 314 | in case of pattern restriction, the first byte has a special meaning: |
| 315 | 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match */ |
| 316 | const char *emsg; /**< error-message */ |
| 317 | const char *eapptag; /**< error-app-tag value */ |
| 318 | const char *dsc; /**< description */ |
| 319 | const char *ref; /**< reference */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 320 | 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] | 321 | }; |
| 322 | |
| 323 | /** |
Michal Vasko | 71e64ca | 2018-09-07 16:30:29 +0200 | [diff] [blame] | 324 | * @brief YANG revision-stmt |
| 325 | */ |
| 326 | struct lysp_revision { |
| 327 | char rev[LY_REV_SIZE]; /**< revision date (madatory) */ |
| 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_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Michal Vasko | 71e64ca | 2018-09-07 16:30:29 +0200 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | /** |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 334 | * @brief Enumeration/Bit value definition |
| 335 | */ |
| 336 | struct lysp_type_enum { |
| 337 | const char *name; /**< name (mandatory) */ |
| 338 | const char *dsc; /**< description statement */ |
| 339 | const char *ref; /**< reference statement */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 340 | int64_t value; /**< enum's value or bit's position */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 341 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 342 | 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] | 343 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_ and LYS_SET_VALUE |
| 344 | values are allowed */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 345 | }; |
| 346 | |
| 347 | /** |
| 348 | * @brief YANG type-stmt |
| 349 | * |
| 350 | * Some of the items in the structure may be mandatory, but it is necessary to resolve the type's base type first |
| 351 | */ |
| 352 | struct lysp_type { |
| 353 | const char *name; /**< name of the type (mandatory) */ |
| 354 | struct lysp_restr *range; /**< allowed values range - numerical, decimal64 */ |
| 355 | struct lysp_restr *length; /**< allowed length of the value - string, binary */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 356 | struct lysp_restr *patterns; /**< list of patterns ([sized array](@ref sizedarrays)) - string */ |
| 357 | struct lysp_type_enum *enums; /**< list of enum-stmts ([sized array](@ref sizedarrays)) - enum */ |
| 358 | 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] | 359 | const char *path; /**< path - leafref */ |
| 360 | const char **bases; /**< list of base identifiers (NULL-terminated) - identityref */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 361 | struct lysp_type *types; /**< list of sub-types ([sized array](@ref sizedarrays)) - union */ |
| 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 | |
| 364 | uint8_t fraction_digits; /**< number of fraction digits - decimal64 */ |
| 365 | uint8_t require_instance; /**< require-instance flag - leafref, instance */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 366 | 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] | 367 | }; |
| 368 | |
| 369 | /** |
| 370 | * @brief YANG typedef-stmt |
| 371 | */ |
| 372 | struct lysp_tpdf { |
| 373 | const char *name; /**< name of the newly defined type (mandatory) */ |
| 374 | const char *units; /**< units of the newly defined type */ |
| 375 | const char *dflt; /**< default value of the newly defined type */ |
| 376 | const char *dsc; /**< description statement */ |
| 377 | const char *ref; /**< reference statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 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 | struct lysp_type type; /**< base type from which the typedef is derived (mandatory) */ |
| 380 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values allowed */ |
| 381 | }; |
| 382 | |
| 383 | /** |
| 384 | * @brief YANG grouping-stmt |
| 385 | */ |
| 386 | struct lysp_grp { |
| 387 | const char *name; /**< grouping name (mandatory) */ |
| 388 | const char *dsc; /**< description statement */ |
| 389 | const char *ref; /**< reference statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 390 | struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */ |
| 391 | struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 392 | struct lysp_node *data; /**< list of data nodes (linked list) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 393 | struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */ |
| 394 | struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */ |
| 395 | 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] | 396 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */ |
| 397 | }; |
| 398 | |
| 399 | /** |
| 400 | * @brief YANG when-stmt |
| 401 | */ |
| 402 | struct lysp_when { |
| 403 | const char *cond; /**< specified condition (mandatory) */ |
| 404 | const char *dsc; /**< description statement */ |
| 405 | const char *ref; /**< reference statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 406 | 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] | 407 | }; |
| 408 | |
| 409 | /** |
| 410 | * @brief YANG refine-stmt |
| 411 | */ |
| 412 | struct lysp_refine { |
| 413 | const char *nodeid; /**< target descendant schema nodeid (mandatory) */ |
| 414 | const char *dsc; /**< description statement */ |
| 415 | const char *ref; /**< reference statement */ |
| 416 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 417 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 418 | const char *presence; /**< presence description */ |
| 419 | const char **dflts; /**< list of default values (NULL-terminated) */ |
| 420 | uint32_t min; /**< min-elements constraint */ |
| 421 | uint32_t max; /**< max-elements constraint, 0 means unbounded */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 422 | 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] | 423 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 424 | }; |
| 425 | |
| 426 | /** |
| 427 | * @brief YANG uses-augment-stmt and augment-stmt |
| 428 | */ |
| 429 | struct lysp_augment { |
| 430 | const char *nodeid; /**< target schema nodeid (mandatory) - absolute for global augments, descendant for uses's augments */ |
| 431 | const char *dsc; /**< description statement */ |
| 432 | const char *ref; /**< reference statement */ |
| 433 | struct lysp_when *when; /**< when statement */ |
| 434 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
| 435 | struct lysp_node *child; /**< list of data nodes (linked list) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 436 | struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */ |
| 437 | struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */ |
| 438 | 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] | 439 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */ |
| 440 | }; |
| 441 | |
| 442 | /** |
| 443 | * @defgroup deviatetypes Deviate types |
| 444 | * @{ |
| 445 | */ |
| 446 | #define LYS_DEV_NOT_SUPPORTED 1 /**< deviate type not-supported */ |
| 447 | #define LYS_DEV_ADD 2 /**< deviate type add */ |
| 448 | #define LYS_DEV_DELETE 3 /**< deviate type delete */ |
| 449 | #define LYS_DEV_REPLACE 4 /**< deviate type replace */ |
| 450 | /** @} */ |
| 451 | |
| 452 | /** |
| 453 | * @brief Generic deviate structure to get type and cast to lysp_deviate_* structure |
| 454 | */ |
| 455 | struct lysp_deviate { |
| 456 | uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */ |
| 457 | struct lysp_deviate *next; /**< next deviate structure in the list */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 458 | 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] | 459 | }; |
| 460 | |
| 461 | struct lysp_deviate_add { |
| 462 | uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */ |
| 463 | struct lysp_deviate *next; /**< next deviate structure in the list */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 464 | 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] | 465 | const char *units; /**< units of the values */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 466 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 467 | const char **uniques; /**< list of uniques specifications (NULL-terminated) */ |
| 468 | const char **dflts; /**< list of default values (NULL-terminated) */ |
| 469 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 470 | uint32_t min; /**< min-elements constraint */ |
| 471 | uint32_t max; /**< max-elements constraint, 0 means unbounded */ |
| 472 | }; |
| 473 | |
| 474 | struct lysp_deviate_del { |
| 475 | uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */ |
| 476 | struct lysp_deviate *next; /**< next deviate structure in the list */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 477 | 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] | 478 | const char *units; /**< units of the values */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 479 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 480 | const char **uniques; /**< list of uniques specifications (NULL-terminated) */ |
| 481 | const char **dflts; /**< list of default values (NULL-terminated) */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 482 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 483 | }; |
| 484 | |
| 485 | struct lysp_deviate_rpl { |
| 486 | uint8_t mod; /**< [type](@ref deviatetypes) of the deviate modification */ |
| 487 | struct lysp_deviate *next; /**< next deviate structure in the list */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 488 | 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] | 489 | struct lysp_type *type; /**< type of the node */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 490 | const char *units; /**< units of the values */ |
| 491 | const char *dflt; /**< default value */ |
| 492 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 493 | uint32_t min; /**< min-elements constraint */ |
| 494 | uint32_t max; /**< max-elements constraint, 0 means unbounded */ |
| 495 | }; |
| 496 | |
| 497 | struct lysp_deviation { |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 498 | const char *nodeid; /**< target absolute schema nodeid (mandatory) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 499 | const char *dsc; /**< description statement */ |
| 500 | const char *ref; /**< reference statement */ |
| 501 | struct lysp_deviate* deviates; /**< list of deviate specifications (linked list) */ |
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 | |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 505 | #define LYS_CONFIG_W 0x01 /**< config true; */ |
| 506 | #define LYS_CONFIG_R 0x02 /**< config false; */ |
| 507 | #define LYS_CONFIG_MASK 0x03 /**< mask for config value */ |
| 508 | #define LYS_STATUS_CURR 0x08 /**< status current; */ |
| 509 | #define LYS_STATUS_DEPRC 0x10 /**< status deprecated; */ |
| 510 | #define LYS_STATUS_OBSLT 0x20 /**< status obsolete; */ |
| 511 | #define LYS_STATUS_MASK 0x38 /**< mask for status value */ |
| 512 | #define LYS_MAND_TRUE 0x40 /**< mandatory true; applicable only to |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 513 | ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf |
| 514 | and ::lysp_node_anydata/::lysc_node_anydata */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 515 | #define LYS_MAND_FALSE 0x80 /**< mandatory false; applicable only to |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 516 | ::lysp_node_choice/::lysc_node_choice, ::lysp_node_leaf/::lysc_node_leaf |
| 517 | and ::lysp_node_anydata/::lysc_node_anydata */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 518 | #define LYS_MAND_MASK 0xc0 /**< mask for mandatory values */ |
| 519 | #define LYS_ORDBY_SYSTEM 0x100 /**< ordered-by system lists, applicable only to |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 520 | ::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] | 521 | #define LYS_ORDBY_USER 0x200 /**< ordered-by user lists, applicable only to |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 522 | ::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] | 523 | #define LYS_ORDBY_MASK 0x300 /**< mask for ordered-by flags */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 524 | #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] | 525 | #define LYS_AUTOASSIGNED 0x01 /**< value was auto-assigned, applicable only to |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 526 | ::lysp_type/::lysc_type enum and bits flags */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 527 | #define LYS_YINELEM_TRUE 0x01 /**< yin-element true for extension's argument */ |
| 528 | #define LYS_YINELEM_FALSE 0x02 /**< yin-element false for extension's argument */ |
| 529 | #define LYS_YINELEM_MASK 0x03 /**< mask for yin-element value */ |
| 530 | #define LYS_SET_VALUE 0x01 /**< value attribute is set */ |
| 531 | #define LYS_SET_MAX 0x400 /**< max attribute is set */ |
| 532 | #define LYS_SET_MIN 0x800 /**< min attribute is set */ |
| 533 | #define LYS_SET_REQINST 0x01 /**< require_instance attribute is set */ |
| 534 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 535 | /** |
| 536 | * @brief Generic YANG data node |
| 537 | */ |
| 538 | struct lysp_node { |
| 539 | uint16_t nodetype; /**< type of the node (mandatory) */ |
| 540 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 541 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 542 | const char *name; /**< node name (mandatory) */ |
| 543 | const char *dsc; /**< description statement */ |
| 544 | const char *ref; /**< reference statement */ |
| 545 | struct lysp_when *when; /**< when statement */ |
| 546 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 547 | 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] | 548 | }; |
| 549 | |
| 550 | /** |
| 551 | * @brief Extension structure of the lysp_node for YANG container |
| 552 | */ |
| 553 | struct lysp_node_container { |
| 554 | uint16_t nodetype; /**< LYS_CONTAINER */ |
| 555 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 556 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 557 | const char *name; /**< node name (mandatory) */ |
| 558 | const char *dsc; /**< description statement */ |
| 559 | const char *ref; /**< reference statement */ |
| 560 | struct lysp_when *when; /**< when statement */ |
| 561 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 562 | 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] | 563 | |
| 564 | /* container */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 565 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 566 | const char *presence; /**< presence description */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 567 | struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */ |
| 568 | struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 569 | struct lysp_node *child; /**< list of data nodes (linked list) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 570 | struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */ |
| 571 | struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 572 | }; |
| 573 | |
| 574 | struct lysp_node_leaf { |
| 575 | uint16_t nodetype; /**< LYS_LEAF */ |
| 576 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 577 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 578 | const char *name; /**< node name (mandatory) */ |
| 579 | const char *dsc; /**< description statement */ |
| 580 | const char *ref; /**< reference statement */ |
| 581 | struct lysp_when *when; /**< when statement */ |
| 582 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 583 | 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] | 584 | |
| 585 | /* leaf */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 586 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 587 | struct lysp_type type; /**< type of the leaf node (mandatory) */ |
| 588 | const char *units; /**< units of the leaf's type */ |
| 589 | const char *dflt; /**< default value */ |
| 590 | }; |
| 591 | |
| 592 | struct lysp_node_leaflist { |
| 593 | uint16_t nodetype; /**< LYS_LEAFLIST */ |
| 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 */ |
| 600 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
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 | /* leaf-list */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 604 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 605 | struct lysp_type type; /**< type of the leaf node (mandatory) */ |
| 606 | const char *units; /**< units of the leaf's type */ |
| 607 | const char **dflts; /**< list of default values (NULL-terminated) */ |
| 608 | uint32_t min; /**< min-elements constraint */ |
| 609 | uint32_t max; /**< max-elements constraint, 0 means unbounded */ |
| 610 | }; |
| 611 | |
| 612 | struct lysp_node_list { |
| 613 | uint16_t nodetype; /**< LYS_LIST */ |
| 614 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 615 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 616 | const char *name; /**< node name (mandatory) */ |
| 617 | const char *dsc; /**< description statement */ |
| 618 | const char *ref; /**< reference statement */ |
| 619 | struct lysp_when *when; /**< when statement */ |
| 620 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 621 | 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] | 622 | |
| 623 | /* list */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 624 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 625 | const char *key; /**< keys specification */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 626 | struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */ |
| 627 | struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 628 | struct lysp_node *child; /**< list of data nodes (linked list) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 629 | struct lysp_action *actions; /**< list of actions ([sized array](@ref sizedarrays)) */ |
| 630 | struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 631 | const char **uniques; /**< list of uniques specifications (NULL-terminated) */ |
| 632 | uint32_t min; /**< min-elements constraint */ |
| 633 | uint32_t max; /**< max-elements constraint, 0 means unbounded */ |
| 634 | }; |
| 635 | |
| 636 | struct lysp_node_choice { |
| 637 | uint16_t nodetype; /**< LYS_CHOICE */ |
| 638 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 639 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 640 | const char *name; /**< node name (mandatory) */ |
| 641 | const char *dsc; /**< description statement */ |
| 642 | const char *ref; /**< reference statement */ |
| 643 | struct lysp_when *when; /**< when statement */ |
| 644 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 645 | 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] | 646 | |
| 647 | /* choice */ |
| 648 | struct lysp_node *child; /**< list of data nodes (linked list) */ |
| 649 | const char* dflt; /**< default case */ |
| 650 | }; |
| 651 | |
| 652 | struct lysp_node_case { |
| 653 | uint16_t nodetype; /**< LYS_CASE */ |
| 654 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 655 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 656 | const char *name; /**< node name (mandatory) */ |
| 657 | const char *dsc; /**< description statement */ |
| 658 | const char *ref; /**< reference statement */ |
| 659 | struct lysp_when *when; /**< when statement */ |
| 660 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
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 | |
| 663 | /* case */ |
| 664 | struct lysp_node *child; /**< list of data nodes (linked list) */ |
| 665 | }; |
| 666 | |
| 667 | struct lysp_node_anydata { |
| 668 | uint16_t nodetype; /**< LYS_ANYXML || LYS_ANYDATA */ |
| 669 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 670 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 671 | const char *name; /**< node name (mandatory) */ |
| 672 | const char *dsc; /**< description statement */ |
| 673 | const char *ref; /**< reference statement */ |
| 674 | struct lysp_when *when; /**< when statement */ |
| 675 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 676 | 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] | 677 | |
| 678 | /* anyxml/anydata */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 679 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 680 | }; |
| 681 | |
| 682 | struct lysp_node_uses { |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 683 | uint16_t nodetype; /**< LYS_USES */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 684 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 685 | struct lysp_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 686 | const char *name; /**< grouping name reference (mandatory) */ |
| 687 | const char *dsc; /**< description statement */ |
| 688 | const char *ref; /**< reference statement */ |
| 689 | struct lysp_when *when; /**< when statement */ |
| 690 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 691 | 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] | 692 | |
| 693 | /* uses */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 694 | struct lysp_refine *refines; /**< list of uses's refines ([sized array](@ref sizedarrays)) */ |
| 695 | 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] | 696 | }; |
| 697 | |
| 698 | /** |
| 699 | * @brief YANG input-stmt and output-stmt |
| 700 | */ |
| 701 | struct lysp_action_inout { |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 702 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
| 703 | struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */ |
| 704 | struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 705 | struct lysp_node *data; /**< list of data nodes (linked list) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 706 | 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] | 707 | }; |
| 708 | |
| 709 | /** |
| 710 | * @brief YANG rpc-stmt and action-stmt |
| 711 | */ |
| 712 | struct lysp_action { |
| 713 | const char *name; /**< grouping name reference (mandatory) */ |
| 714 | const char *dsc; /**< description statement */ |
| 715 | const char *ref; /**< reference statement */ |
| 716 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 717 | struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */ |
| 718 | struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */ |
Michal Vasko | b55f6c1 | 2018-09-12 11:13:15 +0200 | [diff] [blame] | 719 | struct lysp_action_inout *input; /**< RPC's/Action's input */ |
| 720 | struct lysp_action_inout *output;/**< RPC's/Action's output */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 721 | 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] | 722 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 723 | }; |
| 724 | |
| 725 | /** |
| 726 | * @brief YANG notification-stmt |
| 727 | */ |
| 728 | struct lysp_notif { |
| 729 | const char *name; /**< grouping name reference (mandatory) */ |
| 730 | const char *dsc; /**< description statement */ |
| 731 | const char *ref; /**< reference statement */ |
| 732 | const char **iffeatures; /**< list of if-feature expressions (NULL-terminated) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 733 | struct lysp_restr *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */ |
| 734 | struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */ |
| 735 | struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 736 | struct lysp_node *data; /**< list of data nodes (linked list) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 737 | 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] | 738 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* values are allowed */ |
| 739 | }; |
| 740 | |
| 741 | /** |
Radek Krejci | f0fceb6 | 2018-09-05 14:58:45 +0200 | [diff] [blame] | 742 | * @brief supported YANG schema version values |
| 743 | */ |
| 744 | typedef enum LYS_VERSION { |
| 745 | LYS_VERSION_UNDEF = 0, /**< no specific version, YANG 1.0 as default */ |
| 746 | LYS_VERSION_1_0 = 1, /**< YANG 1.0 */ |
| 747 | LYS_VERSION_1_1 = 2 /**< YANG 1.1 */ |
| 748 | } LYS_VERSION; |
| 749 | |
| 750 | /** |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 751 | * @brief Printable YANG schema tree structure representing YANG module. |
| 752 | * |
| 753 | * Simple structure corresponding to the YANG format. The schema is only syntactically validated. |
| 754 | */ |
| 755 | struct lysp_module { |
| 756 | struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */ |
| 757 | const char *name; /**< name of the module (mandatory) */ |
| 758 | const char *filepath; /**< path, if the schema was read from a file, NULL in case of reading from memory */ |
| 759 | union { |
| 760 | /* module */ |
Michal Vasko | d5927ca | 2018-09-07 15:05:32 +0200 | [diff] [blame] | 761 | const char *ns; /**< namespace of the module (module - mandatory) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 762 | /* submodule */ |
Michal Vasko | d5927ca | 2018-09-07 15:05:32 +0200 | [diff] [blame] | 763 | const char *belongsto; /**< belongs to parent module (submodule - mandatory) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 764 | }; |
Michal Vasko | d5927ca | 2018-09-07 15:05:32 +0200 | [diff] [blame] | 765 | const char *prefix; /**< module prefix or submodule belongsto prefix of main module (mandatory) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 766 | struct lysp_import *imports; /**< list of imported modules ([sized array](@ref sizedarrays)) */ |
| 767 | struct lysp_include *includes; /**< list of included submodules ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 768 | const char *org; /**< party/company responsible for the module */ |
| 769 | const char *contact; /**< contact information for the module */ |
| 770 | const char *dsc; /**< description of the module */ |
| 771 | const char *ref; /**< cross-reference for the module */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 772 | struct lysp_revision *revs; /**< list of the module revisions ([sized array](@ref sizedarrays)), the first revision |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 773 | in the list is always the last (newest) revision of the module */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 774 | struct lysp_ext *extensions; /**< list of extension statements ([sized array](@ref sizedarrays)) */ |
| 775 | struct lysp_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */ |
| 776 | struct lysp_ident *identities; /**< list of identities ([sized array](@ref sizedarrays)) */ |
| 777 | struct lysp_tpdf *typedefs; /**< list of typedefs ([sized array](@ref sizedarrays)) */ |
| 778 | struct lysp_grp *groupings; /**< list of groupings ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 779 | 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^] | 780 | struct lysp_augment *augments; /**< list of augments ([sized array](@ref sizedarrays)) */ |
| 781 | struct lysp_action *rpcs; /**< list of RPCs ([sized array](@ref sizedarrays)) */ |
| 782 | struct lysp_notif *notifs; /**< list of notifications ([sized array](@ref sizedarrays)) */ |
| 783 | struct lysp_deviation *deviations; /**< list of deviations ([sized array](@ref sizedarrays)) */ |
| 784 | 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] | 785 | |
Radek Krejci | f0fceb6 | 2018-09-05 14:58:45 +0200 | [diff] [blame] | 786 | uint8_t submodule:1; /**< flag to distinguish main modules and submodules */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 787 | uint8_t implemented:1; /**< flag if the module is implemented, not just imported */ |
| 788 | uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is |
| 789 | the latest revision found */ |
Radek Krejci | f0fceb6 | 2018-09-05 14:58:45 +0200 | [diff] [blame] | 790 | uint8_t version:4; /**< yang-version (LYS_VERSION values) */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 791 | }; |
| 792 | |
| 793 | /** |
Radek Krejci | 3f5e3db | 2018-10-11 15:57:47 +0200 | [diff] [blame] | 794 | * @brief Free the printable YANG schema tree structure. |
| 795 | * |
| 796 | * @param[in] module Printable YANG schema tree structure to free. |
| 797 | */ |
| 798 | void lysp_module_free(struct lysp_module *module); |
| 799 | |
| 800 | /** |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 801 | * @brief YANG when-stmt |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 802 | */ |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 803 | struct lysc_when { |
| 804 | struct lyxp_expr *cond; /**< XPath when condition */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 805 | 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] | 806 | }; |
| 807 | |
| 808 | /** |
| 809 | * @brief YANG feature-stmt |
| 810 | */ |
| 811 | struct lysc_feature { |
| 812 | const char *name; /**< feature name (mandatory) */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 813 | struct lysc_feature *depfeatures;/**< list of other features depending on this one ([sized array](@ref sizedarrays)) */ |
| 814 | struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
| 815 | struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 816 | uint16_t flags; /**< [schema node flags](@ref snodeflags) - only LYS_STATUS_* and |
| 817 | #LYS_FENABLED values allowed */ |
| 818 | }; |
| 819 | |
| 820 | struct lysc_iffeature { |
| 821 | struct lysc_feature *features; /**< array of pointers to the features used in expression, size depends on content of expr */ |
| 822 | uint32_t expr[]; /**< 2bits array describing the if-feature expression in prefix format */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 823 | }; |
| 824 | |
| 825 | /** |
Radek Krejci | 0af5f5d | 2018-09-07 15:00:30 +0200 | [diff] [blame] | 826 | * @brief Compiled YANG data node |
| 827 | */ |
| 828 | struct lysc_node { |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 829 | uint16_t nodetype; /**< type of the node (mandatory) */ |
| 830 | uint16_t flags; /**< [schema node flags](@ref snodeflags) */ |
| 831 | struct lysp_node *sp; /**< link to the simply parsed (SP) original of the node, NULL if the SP schema was removed. */ |
| 832 | struct lysc_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 833 | const char *name; /**< node name (mandatory) */ |
| 834 | struct lysc_when *when; /**< when statement */ |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 835 | struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */ |
| 836 | 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] | 837 | }; |
| 838 | |
| 839 | /** |
| 840 | * @brief Compiled YANG schema tree structure representing YANG module. |
| 841 | * |
| 842 | * Semantically validated YANG schema tree for data tree parsing. |
| 843 | * Contains only the necessary information for the data validation. |
| 844 | */ |
| 845 | struct lysc_module { |
| 846 | struct ly_ctx *ctx; /**< libyang context of the module (mandatory) */ |
| 847 | const char *name; /**< name of the module (mandatory) */ |
| 848 | const char *ns; /**< namespace of the module (mandatory) */ |
| 849 | const char *prefix; /**< module prefix (mandatory) */ |
| 850 | |
| 851 | |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame^] | 852 | struct lysc_feature *features; /**< list of feature definitions ([sized array](@ref sizedarrays)) */ |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 853 | |
| 854 | |
| 855 | uint8_t implemented:1; /**< flag if the module is implemented, not just imported */ |
| 856 | uint8_t latest_revision:1; /**< flag if the module was loaded without specific revision and is |
| 857 | the latest revision found */ |
| 858 | uint8_t version:4; /**< yang-version (LYS_VERSION values) */ |
Radek Krejci | 0af5f5d | 2018-09-07 15:00:30 +0200 | [diff] [blame] | 859 | }; |
| 860 | |
| 861 | /** |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 862 | * @brief Available YANG schema tree structures representing YANG module. |
| 863 | */ |
| 864 | struct lys_module { |
| 865 | struct lysp_module *parsed; /**< Simply parsed (unresolved) YANG schema tree */ |
| 866 | struct lysc_module *compiled; /**< Compiled and fully validated YANG schema tree for data parsing */ |
| 867 | }; |
| 868 | |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 869 | |
| 870 | /** |
| 871 | * @defgroup scflags Schema compile flags |
| 872 | * @ingroup schematree |
| 873 | * |
| 874 | * @{ |
| 875 | */ |
| 876 | #define LYSC_OPT_FREE_SP 1 /**< Free the input printable schema */ |
| 877 | |
| 878 | /** |
| 879 | * @} |
| 880 | */ |
| 881 | |
| 882 | /** |
| 883 | * @brief Compile printable schema into a validated schema linking all the references. |
| 884 | * |
| 885 | * @param[in] sp Simple parsed printable schema to compile. Can be changed according to the provided options. |
| 886 | * @param[in] options Various options to modify compiler behavior, see [compile flags](@ref scflags). |
| 887 | * @param[out] sc Resulting compiled schema structure. |
| 888 | * @return LY_ERR value. |
| 889 | */ |
| 890 | LY_ERR lys_compile(struct lysp_module *sp, int options, struct lysc_module **sc); |
| 891 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 892 | /** @} */ |
| 893 | |
Radek Krejci | 70853c5 | 2018-10-15 14:46:16 +0200 | [diff] [blame] | 894 | #ifdef __cplusplus |
| 895 | } |
| 896 | #endif |
| 897 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 898 | #endif /* LY_TREE_SCHEMA_H_ */ |