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