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