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