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