Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file tree_data.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief libyang representation of YANG data trees. |
| 5 | * |
| 6 | * Copyright (c) 2015 - 2019 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_DATA_H_ |
| 16 | #define LY_TREE_DATA_H_ |
| 17 | |
| 18 | #include <stddef.h> |
| 19 | #include <stdint.h> |
| 20 | |
| 21 | #include "log.h" |
| 22 | #include "tree.h" |
| 23 | #include "tree_schema.h" |
| 24 | |
| 25 | struct ly_ctx; |
| 26 | |
| 27 | #ifdef __cplusplus |
| 28 | extern "C" { |
| 29 | #endif |
| 30 | |
| 31 | /** |
| 32 | * @defgroup datatree Data Tree |
| 33 | * @{ |
| 34 | * |
| 35 | * Data structures and functions to manipulate and access instance data tree. |
| 36 | */ |
| 37 | |
| 38 | /** |
| 39 | * @brief Macro to iterate via all elements in a data tree. This is the opening part |
| 40 | * to the #LYD_TREE_DFS_END - they always have to be used together. |
| 41 | * |
| 42 | * The function follows deep-first search algorithm: |
| 43 | * <pre> |
| 44 | * 1 |
| 45 | * / \ |
| 46 | * 2 4 |
| 47 | * / / \ |
| 48 | * 3 5 6 |
| 49 | * </pre> |
| 50 | * |
| 51 | * Use the same parameters for #LY_TREE_DFS_BEGIN and #LY_TREE_DFS_END. While |
| 52 | * START can be any of the lyd_node* types, NEXT and ELEM variables are expected |
| 53 | * to be pointers to a generic struct lyd_node. |
| 54 | * |
| 55 | * Since the next node is selected as part of #LYD_TREE_DFS_END, do not use |
| 56 | * continue statement between the #LYD_TREE_DFS_BEGIN and #LYD_TREE_DFS_END. |
| 57 | * |
| 58 | * Use with opening curly bracket '{' after the macro. |
| 59 | * |
| 60 | * @param START Pointer to the starting element processed first. |
| 61 | * @param NEXT Temporary storage, do not use. |
| 62 | * @param ELEM Iterator intended for use in the block. |
| 63 | */ |
| 64 | #define LYD_TREE_DFS_BEGIN(START, NEXT, ELEM) \ |
| 65 | for ((ELEM) = (NEXT) = (START); \ |
| 66 | (ELEM); \ |
| 67 | (ELEM) = (NEXT)) |
| 68 | |
| 69 | /** |
| 70 | * @brief Macro to iterate via all elements in a tree. This is the closing part |
| 71 | * to the #LYD_TREE_DFS_BEGIN - they always have to be used together. |
| 72 | * |
| 73 | * Use the same parameters for #LYD_TREE_DFS_BEGIN and #LYD_TREE_DFS_END. While |
| 74 | * START can be any of the lyd_node* types, NEXT and ELEM variables are expected |
| 75 | * to be pointers to a generic struct lyd_node. |
| 76 | * |
| 77 | * Use with closing curly bracket '}' after the macro. |
| 78 | * |
| 79 | * @param START Pointer to the starting element processed first. |
| 80 | * @param NEXT Temporary storage, do not use. |
| 81 | * @param ELEM Iterator intended for use in the block. |
| 82 | */ |
| 83 | |
| 84 | #define LYD_TREE_DFS_END(START, NEXT, ELEM) \ |
| 85 | /* select element for the next run - children first */ \ |
| 86 | (NEXT) = (struct lyd_node*)lyd_node_children((struct lyd_node*)ELEM); \ |
| 87 | if (!(NEXT)) { \ |
| 88 | /* no children */ \ |
| 89 | if ((ELEM) == (struct lyd_node*)(START)) { \ |
| 90 | /* we are done, (START) has no children */ \ |
| 91 | break; \ |
| 92 | } \ |
| 93 | /* try siblings */ \ |
| 94 | (NEXT) = (ELEM)->next; \ |
| 95 | } \ |
| 96 | while (!(NEXT)) { \ |
| 97 | /* parent is already processed, go to its sibling */ \ |
| 98 | (ELEM) = (struct lyd_node*)(ELEM)->parent; \ |
| 99 | /* no siblings, go back through parents */ \ |
| 100 | if ((ELEM)->parent == (START)->parent) { \ |
| 101 | /* we are done, no next element to process */ \ |
| 102 | break; \ |
| 103 | } \ |
| 104 | (NEXT) = (ELEM)->next; \ |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * @brief Data input/output formats supported by libyang [parser](@ref howtodataparsers) and |
| 109 | * [printer](@ref howtodataprinters) functions. |
| 110 | */ |
| 111 | typedef enum { |
| 112 | LYD_UNKNOWN = 0, /**< unknown format, used as return value in case of error */ |
| 113 | LYD_XML, /**< XML format of the instance data */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 114 | LYD_JSON, /**< JSON format of the instance data */ |
Radek Krejci | 355bf4f | 2019-07-16 17:14:16 +0200 | [diff] [blame] | 115 | #if 0 |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 116 | LYD_LYB, /**< LYB format of the instance data */ |
| 117 | #endif |
| 118 | } LYD_FORMAT; |
| 119 | |
| 120 | /** |
| 121 | * @brief List of possible value types stored in ::lyd_node_anydata. |
| 122 | */ |
| 123 | typedef enum { |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 124 | LYD_ANYDATA_DATATREE = 0x01, /**< Value is a pointer to lyd_node structure (first sibling). When provided as input parameter, the pointer |
| 125 | is directly connected into the anydata node without duplication, caller is supposed to not manipulate |
| 126 | with the data after a successful call (including calling lyd_free() on the provided data) */ |
| 127 | LYD_ANYDATA_STRING = 0x02, /**< Value is a generic string without any knowledge about its format (e.g. anyxml value in JSON encoded |
| 128 | as string). XML sensitive characters (such as & or \>) are automatically escaped when the anydata |
| 129 | is printed in XML format. */ |
| 130 | LYD_ANYDATA_XML = 0x04, /**< Value is a string containing the serialized XML data. */ |
| 131 | LYD_ANYDATA_JSON = 0x08, /**< Value is a string containing the data modeled by YANG and encoded as I-JSON. */ |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 132 | #if 0 /* TODO LYB format */ |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 133 | LYD_ANYDATA_LYB = 0x10, /**< Value is a memory chunk with the serialized data tree in LYB format. */ |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 134 | #endif |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 135 | } LYD_ANYDATA_VALUETYPE; |
| 136 | |
| 137 | /** @} */ |
| 138 | |
| 139 | /** |
| 140 | * @brief YANG data representation |
| 141 | */ |
| 142 | struct lyd_value { |
Radek Krejci | 74a3e23 | 2019-07-16 10:46:05 +0200 | [diff] [blame] | 143 | const char *canonized; /**< Canonical string representation of value (for comparison, printing,...), canonized according to the |
| 144 | rules implemented in the type's canonization callback (if any). Note that not all the types |
| 145 | have a canonical representation, so this value can be even NULL (identityref or instance-identifiers |
| 146 | are built-in examples of such a case). The lyd_value::realtype's print callback provides possibility |
| 147 | to get correct string representation of the value for the specific data format. */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 148 | union { |
| 149 | const char *string; /**< original, non-canonized string value. Useful for example for unions where the type (and therefore |
Radek Krejci | 8dc4f2d | 2019-07-16 12:24:00 +0200 | [diff] [blame] | 150 | the canonization rules) can change by changing value (e.g. leafref target) somewhere else. */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 151 | int8_t boolean; /**< 0 as false, 1 as true */ |
| 152 | int64_t dec64; /**< decimal64: value = dec64 / 10^fraction-digits */ |
Radek Krejci | 8dc4f2d | 2019-07-16 12:24:00 +0200 | [diff] [blame] | 153 | int8_t int8; /**< 8-bit signed integer */ |
| 154 | int16_t int16; /**< 16-bit signed integer */ |
| 155 | int32_t int32; /**< 32-bit signed integer */ |
| 156 | int64_t int64; /**< 64-bit signed integer */ |
| 157 | uint8_t uint8; /**< 8-bit unsigned integer */ |
| 158 | uint16_t uint16; /**< 16-bit signed integer */ |
| 159 | uint32_t uint32; /**< 32-bit signed integer */ |
| 160 | uint64_t uint64; /**< 64-bit signed integer */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 161 | struct lysc_type_bitenum_item *enum_item; /**< pointer to the definition of the enumeration value */ |
Radek Krejci | 849a62a | 2019-05-22 15:29:05 +0200 | [diff] [blame] | 162 | struct lysc_type_bitenum_item **bits_items; /**< list of set pointers to the specification of the set bits ([sized array](@ref sizedarrays)) */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 163 | struct lysc_ident *ident; /**< pointer to the schema definition of the identityref value */ |
Radek Krejci | efbb392 | 2019-07-15 12:58:00 +0200 | [diff] [blame] | 164 | |
| 165 | struct lyd_value_subvalue { |
| 166 | struct lyd_value_prefix { |
| 167 | const char *prefix; /**< prefix string used in the canonized string to identify the mod of the YANG schema */ |
| 168 | const struct lys_module *mod; /**< YANG schema module identified by the prefix string */ |
| 169 | } *prefixes; /**< list of mappings between prefix in canonized value to a YANG schema ([sized array](@ref sizedarrays)) */ |
Radek Krejci | 8dc4f2d | 2019-07-16 12:24:00 +0200 | [diff] [blame] | 170 | struct lyd_value *value; /**< representation of the value according to the selected union's subtype (stored as lyd_value::realpath |
| 171 | here, in subvalue structure */ |
| 172 | } *subvalue; /**< data to represent data with multiple types (union). Original value is stored in the main |
| 173 | lyd_value:canonized while the lyd_value_subvalue::value contains representation according to the |
| 174 | one of the union's type. The lyd_value_subvalue:prefixes provides (possible) mappings from prefixes |
| 175 | in original value to YANG modules. These prefixes are necessary to parse original value to the union's |
| 176 | subtypes. */ |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 177 | |
| 178 | struct lyd_value_path { |
Radek Krejci | 8dc4f2d | 2019-07-16 12:24:00 +0200 | [diff] [blame] | 179 | const struct lysc_node *node; /**< Schema node representing the path segment */ |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 180 | struct lyd_value_path_predicate { |
| 181 | union { |
| 182 | struct { |
Radek Krejci | 8dc4f2d | 2019-07-16 12:24:00 +0200 | [diff] [blame] | 183 | const struct lysc_node *key; /**< key node of the predicate, in case of the leaf-list-predicate, it is the leaf-list node itself */ |
| 184 | struct lyd_value *value; /**< value representation according to the key's type */ |
| 185 | }; /**< key-value pair for leaf-list-predicate and key-predicate (type 1 and 2) */ |
| 186 | uint64_t position; /**< position value for the position-predicate (type 0) */ |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 187 | }; |
Radek Krejci | 8dc4f2d | 2019-07-16 12:24:00 +0200 | [diff] [blame] | 188 | uint8_t type; /**< Predicate types (see YANG ABNF): 0 - position, 1 - key-predicate, 2 - leaf-list-predicate */ |
| 189 | } *predicates; /**< [Sized array](@ref sizedarrays) of the path segment's predicates */ |
| 190 | } *target; /**< [Sized array](@ref sizedarrays) of (instance-identifier's) path segments. */ |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 191 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 192 | void *ptr; /**< generic data type structure used to store the data */ |
Radek Krejci | 8dc4f2d | 2019-07-16 12:24:00 +0200 | [diff] [blame] | 193 | }; /**< The union is just a list of shorthands to possible values stored by a type's plugin. libyang itself uses the lyd_value::realtype |
| 194 | plugin's callbacks to work with the data. */ |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 195 | |
Radek Krejci | 62903c3 | 2019-07-15 14:42:05 +0200 | [diff] [blame] | 196 | struct lysc_type *realtype; /**< pointer to the real type of the data stored in the value structure. This type can differ from the type |
| 197 | in the schema node of the data node since the type's store plugin can use other types/plugins for |
| 198 | storing data. Speaking about built-in types, this is the case of leafref which stores data as its |
| 199 | target type. In contrast, union type also use its subtype's callbacks, but inside an internal data |
| 200 | lyd_value::subvalue structure, so here is the pointer to the union type. |
| 201 | In general, this type is used to get free callback for this lyd_value structure, so it must reflect |
| 202 | the type used to store data directly in the same lyd_value instance. */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | /** |
| 206 | * @brief Attribute structure. |
| 207 | * |
| 208 | * The structure provides information about attributes of a data element. Such attributes must map to |
| 209 | * annotations as specified in RFC 7952. The only exception is the filter type (in NETCONF get operations) |
| 210 | * and edit-config's operation attributes. In XML, they are represented as standard XML attributes. In JSON, |
| 211 | * they are represented as JSON elements starting with the '@' character (for more information, see the |
| 212 | * YANG metadata RFC. |
| 213 | * |
| 214 | */ |
| 215 | struct lyd_attr { |
| 216 | struct lyd_node *parent; /**< data node where the attribute is placed */ |
| 217 | struct lyd_attr *next; /**< pointer to the next attribute of the same element */ |
| 218 | void *annotation; /**< TODO pointer to the attribute/annotation's definition */ |
| 219 | const char *name; /**< attribute name */ |
| 220 | struct lyd_value value; /**< attribute's value representation */ |
| 221 | }; |
| 222 | |
| 223 | |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame^] | 224 | #define LYD_NODE_INNER (LYS_CONTAINER|LYS_LIST|LYS_ACTION|LYS_NOTIF) /**< Schema nodetype mask for lyd_node_inner */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 225 | #define LYD_NODE_TERM (LYS_LEAF|LYS_LEAFLIST) /**< Schema nodetype mask for lyd_node_term */ |
| 226 | #define LYD_NODE_ANY (LYS_ANYDATA) /**< Schema nodetype mask for lyd_node_any */ |
| 227 | |
| 228 | /** |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 229 | * @defgroup dnodeflags Data nodes flags |
| 230 | * @ingroup datatree |
| 231 | * @{ |
| 232 | * |
| 233 | * Various flags of data nodes. |
| 234 | * |
| 235 | * 1 - container 5 - anydata/anyxml |
| 236 | * 2 - list 6 - rpc/action |
| 237 | * 3 - leaf 7 - notification |
| 238 | * 4 - leaflist |
| 239 | * |
| 240 | * bit name 1 2 3 4 5 6 7 |
| 241 | * ---------------------+-+-+-+-+-+-+-+ |
| 242 | * 1 LYD_DEFAULT |x| |x|x| | | | |
| 243 | * +-+-+-+-+-+-+-+ |
| 244 | * 2 | | | | | | | | |
| 245 | * ---------------------+-+-+-+-+-+-+-+ |
| 246 | * |
| 247 | */ |
| 248 | |
| 249 | #define LYD_DEFAULT 0x01 /**< default (implicit) node; */ |
| 250 | /** @} */ |
| 251 | |
| 252 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 253 | * @brief Generic structure for a data node. |
| 254 | */ |
| 255 | struct lyd_node { |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 256 | uint32_t hash; /**< hash of this particular node (module name + schema name + key string values if list or |
| 257 | hashes of all nodes of subtree in case of keyless list). Note that while hash can be |
| 258 | used to get know that nodes are not equal, it cannot be used to decide that the |
| 259 | nodes are equal due to possible collisions. */ |
| 260 | uint32_t flags; /**< [data node flags](@ref dnodeflags) */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 261 | const struct lysc_node *schema; /**< pointer to the schema definition of this node */ |
| 262 | struct lyd_node_inner *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 263 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 264 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 265 | never NULL. If there is no sibling node, pointer points to the node |
| 266 | itself. In case of the first node, this pointer points to the last |
| 267 | node in the list. */ |
| 268 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 269 | |
| 270 | #ifdef LY_ENABLED_LYD_PRIV |
| 271 | void *priv; /**< private user data, not used by libyang */ |
| 272 | #endif |
| 273 | }; |
| 274 | |
| 275 | /** |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame^] | 276 | * @brief Data node structure for the inner data tree nodes - containers, lists, RPCs, actions and Notifications. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 277 | */ |
| 278 | struct lyd_node_inner { |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 279 | uint32_t hash; /**< hash of this particular node (module name + schema name + key string values if list or |
| 280 | hashes of all nodes of subtree in case of keyless list). Note that while hash can be |
| 281 | used to get know that nodes are not equal, it cannot be used to decide that the |
| 282 | nodes are equal due to possible collisions. */ |
| 283 | uint32_t flags; /**< [data node flags](@ref dnodeflags) */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 284 | const struct lysc_node *schema; /**< pointer to the schema definition of this node */ |
| 285 | struct lyd_node_inner *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 286 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 287 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 288 | never NULL. If there is no sibling node, pointer points to the node |
| 289 | itself. In case of the first node, this pointer points to the last |
| 290 | node in the list. */ |
| 291 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 292 | |
| 293 | #ifdef LY_ENABLED_LYD_PRIV |
| 294 | void *priv; /**< private user data, not used by libyang */ |
| 295 | #endif |
| 296 | |
| 297 | struct lyd_node *child; /**< pointer to the first child node. */ |
| 298 | struct hash_table *children_ht; /**< hash table with all the direct children (except keys for a list, lists without keys) */ |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 299 | #define LYD_HT_MIN_ITEMS 4 /**< minimal number of children to create lyd_node_inner::children_ht hash table. */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | /** |
| 303 | * @brief Data node structure for the terminal data tree nodes - leafs and leaf-lists. |
| 304 | */ |
| 305 | struct lyd_node_term { |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 306 | uint32_t hash; /**< hash of this particular node (module name + schema name + key string values if list or |
| 307 | hashes of all nodes of subtree in case of keyless list). Note that while hash can be |
| 308 | used to get know that nodes are not equal, it cannot be used to decide that the |
| 309 | nodes are equal due to possible collisions. */ |
| 310 | uint32_t flags; /**< [data node flags](@ref dnodeflags) */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 311 | const struct lysc_node *schema; /**< pointer to the schema definition of this node */ |
| 312 | struct lyd_node_inner *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 313 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 314 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 315 | never NULL. If there is no sibling node, pointer points to the node |
| 316 | itself. In case of the first node, this pointer points to the last |
| 317 | node in the list. */ |
| 318 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 319 | |
| 320 | #ifdef LY_ENABLED_LYD_PRIV |
| 321 | void *priv; /**< private user data, not used by libyang */ |
| 322 | #endif |
| 323 | |
| 324 | struct lyd_value value; /**< node's value representation */ |
| 325 | }; |
| 326 | |
| 327 | /** |
| 328 | * @brief Data node structure for the anydata data tree nodes - anydatas and anyxmls. |
| 329 | */ |
| 330 | struct lyd_node_any { |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 331 | uint32_t hash; /**< hash of this particular node (module name + schema name + key string values if list or |
| 332 | hashes of all nodes of subtree in case of keyless list). Note that while hash can be |
| 333 | used to get know that nodes are not equal, it cannot be used to decide that the |
| 334 | nodes are equal due to possible collisions. */ |
| 335 | uint32_t flags; /**< [data node flags](@ref dnodeflags) */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 336 | const struct lysc_node *schema; /**< pointer to the schema definition of this node */ |
| 337 | struct lyd_node_inner *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 338 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 339 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 340 | never NULL. If there is no sibling node, pointer points to the node |
| 341 | itself. In case of the first node, this pointer points to the last |
| 342 | node in the list. */ |
| 343 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 344 | |
| 345 | #ifdef LY_ENABLED_LYD_PRIV |
| 346 | void *priv; /**< private user data, not used by libyang */ |
| 347 | #endif |
| 348 | |
Radek Krejci | ee4cab2 | 2019-07-17 17:07:47 +0200 | [diff] [blame] | 349 | union { |
| 350 | struct lyd_node *tree; /**< data tree */ |
| 351 | const char *str; /**< Generic string data */ |
| 352 | const char *xml; /**< Serialized XML data */ |
| 353 | const char *json; /**< I-JSON encoded string */ |
| 354 | char *mem; /**< LYD_ANYDATA_LYB memory chunk */ |
| 355 | } value; /**< pointer to the stored value representation of the anydata/anyxml node */ |
| 356 | LYD_ANYDATA_VALUETYPE value_type;/**< type of the data stored as lyd_node_any::value */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | /** |
| 360 | * @defgroup dataparseroptions Data parser options |
| 361 | * @ingroup datatree |
| 362 | * |
| 363 | * Various options to change the data tree parsers behavior. |
| 364 | * |
| 365 | * Default behavior: |
| 366 | * - in case of XML, parser reads all data from its input (file, memory, XML tree) including the case of not well-formed |
| 367 | * XML document (multiple top-level elements) and if there is an unknown element, it is skipped including its subtree |
| 368 | * (see the next point). This can be changed by the #LYD_OPT_NOSIBLINGS option which make parser to read only a single |
| 369 | * tree (with a single root element) from its input. |
| 370 | * - parser silently ignores the data without a matching node in schema trees. If the caller want to stop |
| 371 | * parsing in case of presence of unknown data, the #LYD_OPT_STRICT can be used. The strict mode is useful for |
| 372 | * NETCONF servers, since NETCONF clients should always send data according to the capabilities announced by the server. |
| 373 | * On the other hand, the default non-strict mode is useful for clients receiving data from NETCONF server since |
| 374 | * clients are not required to understand everything the server does. Of course, the optimal strategy for clients is |
| 375 | * to use filtering to get only the required data. Having an unknown element of the known namespace is always an error. |
| 376 | * The behavior can be changed by #LYD_OPT_STRICT option. |
| 377 | * - using obsolete statements (status set to obsolete) just generates a warning, but the processing continues. The |
| 378 | * behavior can be changed by #LYD_OPT_OBSOLETE option. |
| 379 | * - parser expects that the provided data provides complete datastore content (both the configuration and state data) |
| 380 | * and performs data validation according to all YANG rules. This can be a problem in case of representing NETCONF's |
| 381 | * subtree filter data, edit-config's data or other type of data set - such data do not represent a complete data set |
| 382 | * and some of the validation rules can fail. Therefore there are other options (within lower 8 bits) to make parser |
| 383 | * to accept such a data. |
| 384 | * - when parser evaluates when-stmt condition to false, a validation error is raised. If the |
| 385 | * #LYD_OPT_WHENAUTODEL is used, the invalid node is silently removed instead of an error. The option (and also this default |
| 386 | * behavior) takes effect only in case of #LYD_OPT_DATA or #LYD_OPT_CONFIG type of data. |
| 387 | * @{ |
| 388 | */ |
| 389 | |
| 390 | #define LYD_OPT_DATA 0x00 /**< Default type of data - complete datastore content with configuration as well as |
| 391 | state data. To handle possibly missing (but by default required) ietf-yang-library |
| 392 | data, use #LYD_OPT_DATA_NO_YANGLIB or #LYD_OPT_DATA_ADD_YANGLIB options. */ |
| 393 | #define LYD_OPT_CONFIG 0x01 /**< A configuration datastore - complete datastore without state data. |
| 394 | Validation modifications: |
| 395 | - status data are not allowed */ |
| 396 | #define LYD_OPT_GET 0x02 /**< Data content from a NETCONF reply message to the NETCONF \<get\> operation. |
| 397 | Validation modifications: |
| 398 | - mandatory nodes can be omitted |
| 399 | - leafrefs and instance-identifier resolution is allowed to fail |
| 400 | - list's keys/unique nodes are not required (so duplication is not checked) |
| 401 | - must and when evaluation skipped */ |
| 402 | #define LYD_OPT_GETCONFIG 0x04 /**< Data content from a NETCONF reply message to the NETCONF \<get-config\> operation |
| 403 | Validation modifications: |
| 404 | - mandatory nodes can be omitted |
| 405 | - leafrefs and instance-identifier resolution is allowed to fail |
| 406 | - list's keys/unique nodes are not required (so duplication is not checked) |
| 407 | - must and when evaluation skipped |
| 408 | - status data are not allowed */ |
| 409 | #define LYD_OPT_EDIT 0x08 /**< Content of the NETCONF \<edit-config\>'s config element. |
| 410 | Validation modifications: |
| 411 | - mandatory nodes can be omitted |
| 412 | - leafrefs and instance-identifier resolution is allowed to fail |
| 413 | - must and when evaluation skipped |
| 414 | - status data are not allowed */ |
| 415 | #define LYD_OPT_RPC 0x10 /**< Data represents RPC or action input parameters. */ |
| 416 | #define LYD_OPT_RPCREPLY 0x20 /**< Data represents RPC or action output parameters (maps to NETCONF <rpc-reply> data). */ |
| 417 | #define LYD_OPT_NOTIF 0x40 /**< Data represents an event notification data. */ |
| 418 | #define LYD_OPT_NOTIF_FILTER 0x80 /**< Data represents a filtered event notification data. |
| 419 | Validation modification: |
| 420 | - the only requirement is that the data tree matches the schema tree */ |
| 421 | #define LYD_OPT_TYPEMASK 0x10000ff /**< Mask to filter data type options. Always only a single data type option (only |
| 422 | single bit from the lower 8 bits) can be set. */ |
| 423 | |
| 424 | /* 0x100 reserved, used internally */ |
| 425 | #define LYD_OPT_STRICT 0x0200 /**< Instead of silent ignoring data without schema definition, raise an error. */ |
| 426 | #define LYD_OPT_DESTRUCT 0x0400 /**< Free the provided XML tree during parsing the data. With this option, the |
| 427 | provided XML tree is affected and all successfully parsed data are freed. |
| 428 | This option is applicable only to lyd_parse_xml() function. */ |
| 429 | #define LYD_OPT_OBSOLETE 0x0800 /**< Raise an error when an obsolete statement (status set to obsolete) is used. */ |
| 430 | #define LYD_OPT_NOSIBLINGS 0x1000 /**< Parse only a single XML tree from the input. This option applies only to |
| 431 | XML input data. */ |
| 432 | #define LYD_OPT_TRUSTED 0x2000 /**< Data comes from a trusted source and it is not needed to validate them. Data |
| 433 | are connected with the schema, but the most validation checks (mandatory nodes, |
| 434 | list instance uniqueness, etc.) are not performed. This option does not make |
| 435 | sense for lyd_validate() so it is ignored by this function. */ |
| 436 | #define LYD_OPT_WHENAUTODEL 0x4000 /**< Automatically delete subtrees with false when-stmt condition. The flag is |
| 437 | applicable only in combination with #LYD_OPT_DATA and #LYD_OPT_CONFIG flags. |
| 438 | If used, libyang will not generate a validation error. */ |
| 439 | #define LYD_OPT_NOEXTDEPS 0x8000 /**< Allow external dependencies (external leafrefs, instance-identifiers, must, |
| 440 | and when) to not be resolved/satisfied during validation. */ |
| 441 | #define LYD_OPT_DATA_NO_YANGLIB 0x10000 /**< Ignore (possibly) missing ietf-yang-library data. Applicable only with #LYD_OPT_DATA. */ |
| 442 | #define LYD_OPT_DATA_ADD_YANGLIB 0x20000 /**< Add missing ietf-yang-library data into the validated data tree. Applicable |
| 443 | only with #LYD_OPT_DATA. If some ietf-yang-library data are present, they are |
| 444 | preserved and option is ignored. */ |
| 445 | #define LYD_OPT_VAL_DIFF 0x40000 /**< Flag only for validation, store all the data node changes performed by the validation |
| 446 | in a diff structure. */ |
| 447 | #define LYD_OPT_DATA_TEMPLATE 0x1000000 /**< Data represents YANG data template. */ |
| 448 | |
| 449 | /**@} dataparseroptions */ |
| 450 | |
| 451 | /** |
| 452 | * @brief Get the node's children list if any. |
| 453 | * |
| 454 | * Decides the node's type and in case it has a children list, returns it. |
| 455 | * @param[in] node Node to check. |
| 456 | * @return Pointer to the first child node (if any) of the \p node. |
| 457 | */ |
| 458 | const struct lyd_node *lyd_node_children(const struct lyd_node *node); |
| 459 | |
| 460 | /** |
| 461 | * @brief Find the node, in the list, satisfying the given restrictions. |
| 462 | * |
| 463 | * @param[in] first Starting child node for search. |
| 464 | * @param[in] module Module of the node to find (mandatory argument). |
| 465 | * @param[in] name Name of the node to find (mandatory argument). |
| 466 | * @param[in] name_len Optional length of the @p name argument in case it is not NULL-terminated string. |
| 467 | * @param[in] nodetype Optional mask for the nodetype of the node to find, 0 is understood as all nodetypes. |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 468 | * @param[in] value Optional restriction for lyd_node_term nodes to select node with the specific value. Note that this |
| 469 | * search restriction is limited to compare canonical representation of the type. Some of the types have no canonical |
| 470 | * representation and 2 different strings can represent the same value (e.g. different prefixes of the same namespace in instance-identifiers). |
| 471 | * In this case there is more advanced lyd_value_compare() to check if the values matches. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 472 | * @param[in] value_len Optional length of the @p value argument in case it is not NULL-terminated string. |
| 473 | * @return The sibling node of the @p first (or itself), satisfying the given restrictions. |
| 474 | * @return NULL in case there is no node satisfying the restrictions. |
| 475 | */ |
| 476 | const struct lyd_node *lyd_search(const struct lyd_node *first, const struct lys_module *module, |
| 477 | const char *name, size_t name_len, uint16_t nodetype, const char *value, size_t value_len); |
| 478 | |
| 479 | /** |
| 480 | * @brief Parse (and validate) data from memory. |
| 481 | * |
| 482 | * In case of LY_XML format, the data string is parsed completely. It means that when it contains |
| 483 | * a non well-formed XML with multiple root elements, all those sibling XML trees are parsed. The |
| 484 | * returned data node is a root of the first tree with other trees connected via the next pointer. |
| 485 | * This behavior can be changed by #LYD_OPT_NOSIBLINGS option. |
| 486 | * |
| 487 | * @param[in] ctx Context to connect with the data tree being built here. |
| 488 | * @param[in] data Serialized data in the specified format. |
| 489 | * @param[in] format Format of the input data to be parsed. |
| 490 | * @param[in] options Parser options, see @ref parseroptions. \p format LYD_LYB uses #LYD_OPT_TRUSTED implicitly. |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame^] | 491 | * @param[in] trees ([Sized array](@ref sizedarrays)) of data trees (e.g. when validating RPC/Notification) where the required |
| 492 | * data instances (leafref target, instance-identifier, when, must) can be placed. To simply prepare this structure, |
| 493 | * use lyd_trees_new(). In case of parsing RPC/action reply (LYD_OPT_RPCREPLY), the first tree in the array MUST be |
| 494 | * complete RPC/action data tree (the source request) for the reply. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 495 | * @return Pointer to the built data tree or NULL in case of empty \p data. To free the returned structure, |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame^] | 496 | * use lyd_free_all(). |
| 497 | * @return NULL in case of error. The error information can be then obtained using ly_err* functions. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 498 | */ |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame^] | 499 | struct lyd_node *lyd_parse_mem(struct ly_ctx *ctx, const char *data, LYD_FORMAT format, int options, const struct lyd_node **trees); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 500 | |
| 501 | /** |
| 502 | * @brief Read (and validate) data from the given file descriptor. |
| 503 | * |
| 504 | * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc. |
| 505 | * |
| 506 | * In case of LY_XML format, the file content is parsed completely. It means that when it contains |
| 507 | * a non well-formed XML with multiple root elements, all those sibling XML trees are parsed. The |
| 508 | * returned data node is a root of the first tree with other trees connected via the next pointer. |
| 509 | * This behavior can be changed by #LYD_OPT_NOSIBLINGS option. |
| 510 | * |
| 511 | * @param[in] ctx Context to connect with the data tree being built here. |
| 512 | * @param[in] fd The standard file descriptor of the file containing the data tree in the specified format. |
| 513 | * @param[in] format Format of the input data to be parsed. |
| 514 | * @param[in] options Parser options, see @ref parseroptions. \p format LYD_LYB uses #LYD_OPT_TRUSTED implicitly. |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame^] | 515 | * @param[in] trees ([Sized array](@ref sizedarrays)) of data trees (e.g. when validating RPC/Notification) where the required |
| 516 | * data instances (leafref target, instance-identifier, when, must) can be placed. To simply prepare this structure, |
| 517 | * use lyd_trees_new(). In case of parsing RPC/action reply (LYD_OPT_RPCREPLY), the first tree in the array MUST be |
| 518 | * complete RPC/action data tree (the source request) for the reply. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 519 | * @return Pointer to the built data tree or NULL in case of empty file. To free the returned structure, |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame^] | 520 | * use lyd_free_all(). |
| 521 | * @return NULL in case of error. The error information can be then obtained using ly_err* functions. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 522 | */ |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame^] | 523 | struct lyd_node *lyd_parse_fd(struct ly_ctx *ctx, int fd, LYD_FORMAT format, int options, const struct lyd_node **trees); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 524 | |
| 525 | /** |
| 526 | * @brief Read (and validate) data from the given file path. |
| 527 | * |
| 528 | * In case of LY_XML format, the file content is parsed completely. It means that when it contains |
| 529 | * a non well-formed XML with multiple root elements, all those sibling XML trees are parsed. The |
| 530 | * returned data node is a root of the first tree with other trees connected via the next pointer. |
| 531 | * This behavior can be changed by #LYD_OPT_NOSIBLINGS option. |
| 532 | * |
| 533 | * @param[in] ctx Context to connect with the data tree being built here. |
| 534 | * @param[in] path Path to the file containing the data tree in the specified format. |
| 535 | * @param[in] format Format of the input data to be parsed. |
| 536 | * @param[in] options Parser options, see @ref parseroptions. \p format LYD_LYB uses #LYD_OPT_TRUSTED implicitly. |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame^] | 537 | * @param[in] trees ([Sized array](@ref sizedarrays)) of data trees (e.g. when validating RPC/Notification) where the required |
| 538 | * data instances (leafref target, instance-identifier, when, must) can be placed. To simply prepare this structure, |
| 539 | * use lyd_trees_new(). In case of parsing RPC/action reply (LYD_OPT_RPCREPLY), the first tree in the array MUST be |
| 540 | * complete RPC/action data tree (the source request) for the reply. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 541 | * @return Pointer to the built data tree or NULL in case of empty file. To free the returned structure, |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame^] | 542 | * use lyd_free_all(). |
| 543 | * @return NULL in case of error. The error information can be then obtained using ly_err* functions. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 544 | */ |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame^] | 545 | struct lyd_node *lyd_parse_path(struct ly_ctx *ctx, const char *path, LYD_FORMAT format, int options, const struct lyd_node **trees); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 546 | |
| 547 | /** |
| 548 | * @brief Free all the nodes in the data tree. |
| 549 | * |
| 550 | * @param[in] node Any of the nodes inside the tree. |
| 551 | */ |
| 552 | void lyd_free_all(struct lyd_node *node); |
| 553 | |
| 554 | /** |
| 555 | * @brief Free (and unlink) the specified data (sub)tree. |
| 556 | * |
| 557 | * __PARTIAL CHANGE__ - validate after the final change on the data tree (see @ref howtodatamanipulators). |
| 558 | * |
| 559 | * @param[in] node Root of the (sub)tree to be freed. |
| 560 | */ |
| 561 | void lyd_free_tree(struct lyd_node *node); |
| 562 | |
| 563 | /** |
| 564 | * @brief Unlink the specified data subtree. All referenced namespaces are copied. |
| 565 | * |
| 566 | * Note, that the node's connection with the schema tree is kept. Therefore, in case of |
| 567 | * reconnecting the node to a data tree using lyd_paste() it is necessary to paste it |
| 568 | * to the appropriate place in the data tree following the schema. |
| 569 | * |
| 570 | * __PARTIAL CHANGE__ - validate after the final change on the data tree (see @ref howtodatamanipulators). |
| 571 | * |
| 572 | * @param[in] node Data tree node to be unlinked (together with all children). |
| 573 | * @return LY_SUCCESS for success |
| 574 | * @return LY_E* values in case of error |
| 575 | */ |
| 576 | LY_ERR lyd_unlink_tree(struct lyd_node *node); |
| 577 | |
| 578 | /** |
| 579 | * @brief Destroy data attribute. |
| 580 | * |
| 581 | * @param[in] ctx Context where the attribute was created. |
| 582 | * @param[in] attr Attribute to destroy |
| 583 | * @param[in] recursive Zero to destroy only the attribute (the attribute list is corrected), |
| 584 | * non-zero to destroy also all the subsequent attributes in the list. |
| 585 | */ |
| 586 | void lyd_free_attr(struct ly_ctx *ctx, struct lyd_attr *attr, int recursive); |
| 587 | |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 588 | /** |
Radek Krejci | 576b23f | 2019-07-12 14:06:32 +0200 | [diff] [blame] | 589 | * @brief Prepare ([sized array](@ref sizedarrays)) of data trees required by various (mostly validation) functions. |
| 590 | * |
| 591 | * @param[in] count Number of trees to include (including the mandatory @p tree). |
| 592 | * @param[in] tree First (and mandatory) tree to be included into the resulting ([sized array](@ref sizedarrays)). |
| 593 | * @return NULL in case of memory allocation failure or invalid argument, prepared ([sized array](@ref sizedarrays)) otherwise. |
| 594 | */ |
| 595 | const struct lyd_node **lyd_trees_new(size_t count, const struct lyd_node *tree, ...); |
| 596 | |
| 597 | /** |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame^] | 598 | * @brief Add tree into the ([sized array](@ref sizedarrays)) of data trees created by lyd_trees_new(), |
| 599 | * |
| 600 | * @param[in] trees Existing [sized array](@ref sizedarrays)) of data trees to be extended. |
| 601 | * @param[in] tree Data tree to be included into the provided @p trees ([sized array](@ref sizedarrays)). |
| 602 | * @return NULL in case of memory allocation failure or invalid argument, extended @p trees ([sized array](@ref sizedarrays)) otherwise. |
| 603 | */ |
| 604 | const struct lyd_node **lyd_trees_add(const struct lyd_node **trees, const struct lyd_node *tree); |
| 605 | |
| 606 | /** |
Radek Krejci | 576b23f | 2019-07-12 14:06:32 +0200 | [diff] [blame] | 607 | * @brief Free the trees ([sized array](@ref sizedarrays)). |
| 608 | * |
| 609 | * @param[in] trees ([Sized array](@ref sizedarrays)) of data trees. |
| 610 | * @param[in] free_data Flag to free also the particular trees in the @p trees ([sized array](@ref sizedarrays)). |
| 611 | * If set to zero, only the trees envelope is freed and data are untouched. |
| 612 | */ |
| 613 | void lyd_trees_free(const struct lyd_node **trees, int free_data); |
| 614 | |
| 615 | /** |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 616 | * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value. |
| 617 | * |
| 618 | * The given node is not modified in any way - it is just checked if the @p value can be set to the node. |
| 619 | * |
| 620 | * If there is no data node instance and you are fine with checking just the type's restrictions without the |
| 621 | * data tree context (e.g. for the case of require-instance restriction), use lys_value_validate(). |
| 622 | * |
| 623 | * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL) |
| 624 | * @param[in] node Data node for the @p value. |
| 625 | * @param[in] value String value to be checked. |
| 626 | * @param[in] value_len Length of the given @p value (mandatory). |
| 627 | * @param[in] get_prefix Callback function to resolve prefixes used in the @p value string. |
| 628 | * @param[in] get_prefix_data Private data for the @p get_prefix callback. |
| 629 | * @param[in] format Input format of the data. |
| 630 | * @param[in] trees ([Sized array](@ref sizedarrays)) of data trees (e.g. when validating RPC/Notification) where the required |
| 631 | * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete, |
Radek Krejci | 576b23f | 2019-07-12 14:06:32 +0200 | [diff] [blame] | 632 | * then LY_EINCOMPLETE can be returned. To simply prepare this structure, use lyd_trees_new(). |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 633 | * @return LY_SUCCESS on success |
| 634 | * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation (e.g. due to require-instance). |
| 635 | * @return LY_ERR value if an error occurred. |
| 636 | */ |
| 637 | LY_ERR lyd_value_validate(struct ly_ctx *ctx, const struct lyd_node_term *node, const char *value, size_t value_len, |
Radek Krejci | 576b23f | 2019-07-12 14:06:32 +0200 | [diff] [blame] | 638 | ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format, const struct lyd_node **trees); |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 639 | |
| 640 | /** |
| 641 | * @brief Compare the node's value with the given string value. The string value is first validated according to the node's type. |
| 642 | * |
| 643 | * @param[in] node Data node to compare. |
| 644 | * @param[in] value String value to be compared. It does not need to be in a canonical form - as part of the process, |
| 645 | * it is validated and canonized if possible. |
| 646 | * @param[in] value_len Length of the given @p value (mandatory). |
| 647 | * @param[in] get_prefix Callback function to resolve prefixes used in the @p value string. |
| 648 | * @param[in] get_prefix_data Private data for the @p get_prefix callback. |
| 649 | * @param[in] format Input format of the data. |
| 650 | * @param[in] trees ([Sized array](@ref sizedarrays)) of data trees (e.g. when validating RPC/Notification) where the required |
| 651 | * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete, |
Radek Krejci | 576b23f | 2019-07-12 14:06:32 +0200 | [diff] [blame] | 652 | * then LY_EINCOMPLETE can be returned in case the validation was not completed, but values matches. To simply prepare |
| 653 | * this structure, use lyd_trees_new(). To simply prepare this structure, use lyd_trees_new(). |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 654 | * @return LY_SUCCESS on success |
| 655 | * @return LY_EINCOMPLETE in case of success when the @p trees is not provided and it was needed to finish the validation of |
| 656 | * the given string @p value (e.g. due to require-instance). |
| 657 | * @return LY_ERR value if an error occurred. |
| 658 | */ |
| 659 | LY_ERR lyd_value_compare(const struct lyd_node_term *node, const char *value, size_t value_len, |
Radek Krejci | 576b23f | 2019-07-12 14:06:32 +0200 | [diff] [blame] | 660 | ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format, const struct lyd_node **trees); |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 661 | |
Radek Krejci | 576b23f | 2019-07-12 14:06:32 +0200 | [diff] [blame] | 662 | /** |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 663 | * @defgroup datacompareoptions Data compare options |
| 664 | * @ingroup datatree |
| 665 | * |
| 666 | * Various options to change the lyd_compare behavior. |
| 667 | */ |
| 668 | #define LYD_COMPARE_FULL_RECURSION 0x01 /* lists and containers are the same only in case all they children |
| 669 | (subtree, so direct as well as indirect children) are the same. By default, |
| 670 | containers are the same in case of the same schema node and lists are the same |
| 671 | in case of equal keys (keyless lists do the full recursion comparison all the time). */ |
| 672 | #define LYD_COMPARE_DEFAULTS 0x02 /* By default, implicit and explicit default nodes are considered to be equal. This flag |
| 673 | changes this behavior and implicit (automatically created default node) and explicit |
| 674 | (explicitly created node with the default value) default nodes are considered different. */ |
| 675 | /**@} dataparseroptions */ |
| 676 | |
| 677 | /** |
| 678 | * @brief Compare 2 data nodes if they are equivalent. |
| 679 | * |
| 680 | * @param[in] node1 The first node to compare. |
| 681 | * @param[in] node2 The second node to compare. |
| 682 | * @return LY_SUCCESS if the nodes are equivalent. |
| 683 | * @return LY_ENOT if the nodes are not equivalent. |
| 684 | */ |
| 685 | LY_ERR lyd_compare(const struct lyd_node *node1, const struct lyd_node *node2, int options); |
| 686 | |
| 687 | /** |
Radek Krejci | 576b23f | 2019-07-12 14:06:32 +0200 | [diff] [blame] | 688 | * @brief Resolve instance-identifier defined by lyd_value_path structure. |
| 689 | * |
| 690 | * @param[in] path Path structure specifying the instance-identifier target. |
| 691 | * @param[in] trees ([Sized array](@ref sizedarrays)) of data trees to be searched. |
| 692 | * To simply prepare this structure, use lyd_trees_new(). |
| 693 | * @return Target node of the instance-identifier present in the given data @p trees. |
| 694 | */ |
| 695 | const struct lyd_node_term *lyd_target(struct lyd_value_path *path, const struct lyd_node **trees); |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 696 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 697 | #ifdef __cplusplus |
| 698 | } |
| 699 | #endif |
| 700 | |
| 701 | #endif /* LY_TREE_DATA_H_ */ |