Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file tree_data_internal.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief internal functions for YANG schema trees. |
| 5 | * |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 6 | * Copyright (c) 2015 - 2020 CESNET, z.s.p.o. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 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_INTERNAL_H_ |
| 16 | #define LY_TREE_DATA_INTERNAL_H_ |
| 17 | |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 18 | #include "lyb.h" |
Radek Krejci | aca7403 | 2019-06-04 08:53:06 +0200 | [diff] [blame] | 19 | #include "plugins_types.h" |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 20 | #include "set.h" |
| 21 | #include "tree_data.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 22 | |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 23 | #include <stddef.h> |
| 24 | |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 25 | struct ly_path_predicate; |
| 26 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 27 | /** |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 28 | * @brief Internal data parser flags. |
| 29 | */ |
| 30 | #define LYD_INTOPT_RPC 0x01 /**< RPC/action invocation is being parsed */ |
| 31 | #define LYD_INTOPT_NOTIF 0x02 /**< notification is being parsed */ |
| 32 | #define LYD_INTOPT_REPLY 0x04 /**< RPC/action reply is being parsed */ |
| 33 | |
| 34 | /** |
| 35 | * @brief Hash schema sibling to be used for LYB data. |
| 36 | * |
| 37 | * @param[in] sibling Sibling to hash. |
| 38 | * @param[in] collision_id Collision ID of the hash to generate. |
| 39 | * @return Generated hash. |
| 40 | */ |
| 41 | LYB_HASH lyb_hash(struct lysc_node *sibling, uint8_t collision_id); |
| 42 | |
| 43 | /** |
| 44 | * @brief Check whether a sibling module is in a module array. |
| 45 | * |
| 46 | * @param[in] sibling Sibling to check. |
| 47 | * @param[in] models Modules in a sized array. |
| 48 | * @return non-zero if the module was found, |
| 49 | * @return 0 if not found. |
| 50 | */ |
| 51 | int lyb_has_schema_model(const struct lysc_node *sibling, const struct lys_module **models); |
| 52 | |
| 53 | /** |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 54 | * @brief Check whether a node to be deleted is the first top-level sibling. |
| 55 | * |
| 56 | * @param[in] first First sibling. |
| 57 | * @param[in] to_del Node to be deleted. |
| 58 | */ |
| 59 | #define LYD_DEL_IS_ROOT(first, to_del) (((first) == (to_del)) && !(first)->parent && !(first)->prev->next) |
| 60 | |
| 61 | /** |
Michal Vasko | 5bfd4be | 2020-06-23 13:26:19 +0200 | [diff] [blame] | 62 | * @brief Shorthand for getting data children without its keys. |
| 63 | * |
| 64 | * @param[in] node Node, whose children to traverse. |
| 65 | * @return Node children, skipping any keys of a list. |
| 66 | */ |
| 67 | #define LYD_CHILD(node) lyd_node_children(node, LYD_CHILDREN_SKIP_KEYS) |
| 68 | |
| 69 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 70 | * @brief Get address of a node's child pointer if any. |
| 71 | * |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 72 | * @param[in] node Node to check. |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 73 | * @return Address of the node's child member, |
| 74 | * @return NULL if there is no child pointer. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 75 | */ |
| 76 | struct lyd_node **lyd_node_children_p(struct lyd_node *node); |
| 77 | |
| 78 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 79 | * @brief Create a term (leaf/leaf-list) node from a string value. |
| 80 | * |
| 81 | * Hash is calculated and new node flag is set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 82 | * |
| 83 | * @param[in] schema Schema node of the new data node. |
| 84 | * @param[in] value String value to be parsed. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 85 | * @param[in] value_len Length of @p value, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 86 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
| 87 | * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string. |
| 88 | * @param[in] prefix_data User data for @p get_prefix. |
| 89 | * @param[in] format Input format of @p value. |
| 90 | * @param[out] node Created node. |
| 91 | * @return LY_SUCCESS on success. |
| 92 | * @return LY_EINCOMPLETE in case data tree is needed to finish the validation. |
| 93 | * @return LY_ERR value if an error occurred. |
| 94 | */ |
| 95 | LY_ERR lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, int *dynamic, |
| 96 | ly_clb_resolve_prefix get_prefix, void *prefix_data, LYD_FORMAT format, struct lyd_node **node); |
| 97 | |
| 98 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 99 | * @brief Create a term (leaf/leaf-list) node from a parsed value by duplicating it. |
| 100 | * |
| 101 | * Hash is calculated and new node flag is set. |
| 102 | * |
| 103 | * @param[in] schema Schema node of the new data node. |
| 104 | * @param[in] val Parsed value to use. |
| 105 | * @param[out] node Created node. |
| 106 | * @return LY_SUCCESS on success. |
| 107 | * @return LY_ERR value if an error occurred. |
| 108 | */ |
| 109 | LY_ERR lyd_create_term2(const struct lysc_node *schema, const struct lyd_value *val, struct lyd_node **node); |
| 110 | |
| 111 | /** |
| 112 | * @brief Create an inner (container/list/RPC/action/notification) node. |
| 113 | * |
| 114 | * Hash is calculated and new node flag is set except |
| 115 | * for list with keys, when the hash is not calculated! |
| 116 | * Also, non-presence container has its default flag set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 117 | * |
| 118 | * @param[in] schema Schema node of the new data node. |
| 119 | * @param[out] node Created node. |
| 120 | * @return LY_SUCCESS on success. |
| 121 | * @return LY_ERR value if an error occurred. |
| 122 | */ |
| 123 | LY_ERR lyd_create_inner(const struct lysc_node *schema, struct lyd_node **node); |
| 124 | |
| 125 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 126 | * @brief Create a list with all its keys (cannot be used for key-less list). |
| 127 | * |
| 128 | * Hash is calculated and new node flag is set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 129 | * |
| 130 | * @param[in] schema Schema node of the new data node. |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 131 | * @param[in] predicates Compiled key list predicates. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 132 | * @param[out] node Created node. |
| 133 | * @return LY_SUCCESS on success. |
| 134 | * @return LY_ERR value if an error occurred. |
| 135 | */ |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 136 | LY_ERR lyd_create_list(const struct lysc_node *schema, const struct ly_path_predicate *predicates, struct lyd_node **node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 137 | |
| 138 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 139 | * @brief Create an anyxml/anydata node. |
| 140 | * |
| 141 | * Hash is calculated and flags are properly set based on @p is_valid. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 142 | * |
| 143 | * @param[in] schema Schema node of the new data node. |
| 144 | * @param[in] value Value of the any node, is directly assigned into the data node. |
| 145 | * @param[in] value_type Value type of the value. |
| 146 | * @param[out] node Created node. |
| 147 | * @return LY_SUCCESS on success. |
| 148 | * @return LY_ERR value if an error occurred. |
| 149 | */ |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 150 | LY_ERR lyd_create_any(const struct lysc_node *schema, const void *value, LYD_ANYDATA_VALUETYPE value_type, |
| 151 | struct lyd_node **node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 152 | |
| 153 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 154 | * @brief Create an opaque node. |
| 155 | * |
| 156 | * @param[in] ctx libyang context. |
| 157 | * @param[in] name Element name. |
| 158 | * @param[in] name_len Length of @p name, must be set correctly. |
| 159 | * @param[in] value String value to be parsed. |
| 160 | * @param[in] value_len Length of @p value, must be set correctly. |
| 161 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
| 162 | * @param[in] format Input format of @p value and @p ns. |
| 163 | * @param[in] val_prefs Possible value prefixes, array is spent. |
| 164 | * @param[in] prefix Element prefix. |
| 165 | * @param[in] pref_len Length of @p prefix, must be set correctly. |
| 166 | * @param[in] ns Node namespace, meaning depends on @p format. |
| 167 | * @param[out] node Created node. |
| 168 | * @return LY_SUCCESS on success. |
| 169 | * @return LY_ERR value if an error occurred. |
| 170 | */ |
| 171 | LY_ERR lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_len, const char *value, size_t value_len, |
| 172 | int *dynamic, LYD_FORMAT format, struct ly_prefix *val_prefs, const char *prefix, size_t pref_len, |
| 173 | const char *ns, struct lyd_node **node); |
| 174 | |
| 175 | /** |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 176 | * @brief Find the key after which to insert the new key. |
| 177 | * |
| 178 | * @param[in] first_sibling List first sibling. |
| 179 | * @param[in] new_key Key that will be inserted. |
| 180 | * @return Key to insert after. |
| 181 | * @return NULL if the new key should be first. |
| 182 | */ |
| 183 | struct lyd_node *lyd_get_prev_key_anchor(const struct lyd_node *first_sibling, const struct lysc_node *new_key); |
| 184 | |
| 185 | /** |
| 186 | * @brief Insert a node into parent/siblings. In case a key is being inserted into a list, the correct position |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 187 | * is found, inserted into, and if it is the last key, parent list hash is calculated. Also, in case we are inserting |
| 188 | * into top-level siblings, insert it as the last sibling of all the module data siblings. Otherwise it is inserted at |
| 189 | * the very last place. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 190 | * |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 191 | * @param[in] parent Parent to insert into, NULL for top-level sibling. |
| 192 | * @param[in,out] first_sibling First sibling, NULL if no top-level sibling exist yet. Can be also NULL if @p parent is set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 193 | * @param[in] node Individual node (without siblings) to insert. |
| 194 | */ |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 195 | void lyd_insert_node(struct lyd_node *parent, struct lyd_node **first_sibling, struct lyd_node *node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 196 | |
| 197 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 198 | * @brief Create and insert a metadata (last) into a parent. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 199 | * |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 200 | * @param[in] parent Parent of the metadata, can be NULL. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 201 | * @param[in,out] meta Metadata list to add at its end if @p parent is NULL, returned created attribute. |
| 202 | * @param[in] mod Metadata module (with the annotation definition). |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 203 | * @param[in] name Attribute name. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 204 | * @param[in] name_len Length of @p name, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 205 | * @param[in] value String value to be parsed. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 206 | * @param[in] value_len Length of @p value, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 207 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 208 | * @param[in] resolve_prefix Parser-specific getter to resolve prefixes used in the @p value string. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 209 | * @param[in] prefix_data User data for @p get_prefix. |
| 210 | * @param[in] format Input format of @p value. |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 211 | * @param[in] ctx_snode Context node for value resolution in schema. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 212 | * @return LY_SUCCESS on success. |
| 213 | * @return LY_EINCOMPLETE in case data tree is needed to finish the validation. |
| 214 | * @return LY_ERR value if an error occurred. |
| 215 | */ |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 216 | LY_ERR lyd_create_meta(struct lyd_node *parent, struct lyd_meta **meta, const struct lys_module *mod, const char *name, |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 217 | size_t name_len, const char *value, size_t value_len, int *dynamic, ly_clb_resolve_prefix resolve_prefix, |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 218 | void *prefix_data, LYD_FORMAT format, const struct lysc_node *ctx_snode); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 219 | |
| 220 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 221 | * @brief Create and insert a generic attribute (last) into a parent. |
| 222 | * |
| 223 | * @param[in] parent Parent of the attribute, can be NULL. |
| 224 | * @param[in,out] attr Attribute list to add at its end if @p parent is NULL, returned created attribute. |
| 225 | * @param[in] ctx libyang context. |
| 226 | * @param[in] name Attribute name. |
| 227 | * @param[in] name_len Length of @p name, must be set correctly. |
| 228 | * @param[in] value String value to be parsed. |
| 229 | * @param[in] value_len Length of @p value, must be set correctly. |
| 230 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
| 231 | * @param[in] format Input format of @p value and @p ns. |
| 232 | * @param[in] val_prefs Possible value prefixes, array is spent. |
| 233 | * @param[in] prefix Attribute prefix. |
| 234 | * @param[in] prefix_len Attribute prefix length. |
| 235 | * @param[in] ns Attribute namespace, meaning depends on @p format. |
| 236 | * @return LY_SUCCESS on success. |
| 237 | * @return LY_ERR value if an error occurred. |
| 238 | */ |
| 239 | LY_ERR ly_create_attr(struct lyd_node *parent, struct ly_attr **attr, const struct ly_ctx *ctx, const char *name, |
| 240 | size_t name_len, const char *value, size_t value_len, int *dynamic, LYD_FORMAT format, |
| 241 | struct ly_prefix *val_prefs, const char *prefix, size_t prefix_len, const char *ns); |
| 242 | |
| 243 | /** |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 244 | * @brief Validate, canonize and store the given @p value into the node according to the node's type's rules. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 245 | * |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 246 | * @param[in] node Data node for the @p value. |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 247 | * @param[in] value String value to be parsed, must not be NULL. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 248 | * @param[in] value_len Length of the give @p value, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 249 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
Radek Krejci | 3c9758d | 2019-07-11 16:49:10 +0200 | [diff] [blame] | 250 | * @param[in] second Flag for the second call after returning LY_EINCOMPLETE |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 251 | * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string. |
Radek Krejci | aca7403 | 2019-06-04 08:53:06 +0200 | [diff] [blame] | 252 | * @param[in] parser Parser's data for @p get_prefix |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 253 | * @param[in] format Input format of @p value. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 254 | * @param[in] tree Data tree (e.g. when validating RPC/Notification) where the required |
Radek Krejci | e553e6d | 2019-06-07 15:33:18 +0200 | [diff] [blame] | 255 | * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete, |
| 256 | * then LY_EINCOMPLETE can be returned. |
| 257 | * @return LY_SUCCESS on success |
| 258 | * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation. |
| 259 | * @return LY_ERR value if an error occurred. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 260 | */ |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 261 | LY_ERR lyd_value_parse(struct lyd_node_term *node, const char *value, size_t value_len, int *dynamic, int second, |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 262 | ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format, const struct lyd_node *tree); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 263 | |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 264 | /* similar to lyd_value_parse except can be used just to store the value, hence does also not support a second call */ |
| 265 | LY_ERR lyd_value_store(struct lyd_value *val, const struct lysc_node *schema, const char *value, size_t value_len, |
| 266 | int *dynamic, ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format); |
| 267 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 268 | /** |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 269 | * @brief Validate, canonize and store the given @p value into the metadata according to the annotation type's rules. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 270 | * |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 271 | * @param[in] ctx libyang context. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 272 | * @param[in] meta Metadata for the @p value. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 273 | * @param[in] value String value to be parsed, must not be NULL. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 274 | * @param[in] value_len Length of the give @p value, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 275 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 276 | * @param[in] second Flag for the second call after returning LY_EINCOMPLETE |
| 277 | * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string. |
| 278 | * @param[in] parser Parser's data for @p get_prefix |
| 279 | * @param[in] format Input format of the data. |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 280 | * @param[in] ctx_snode Context node for value resolution in schema. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 281 | * @param[in] tree Data tree (e.g. when validating RPC/Notification) where the required |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 282 | * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete, |
| 283 | * then LY_EINCOMPLETE can be returned. |
| 284 | * @return LY_SUCCESS on success |
| 285 | * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation. |
| 286 | * @return LY_ERR value if an error occurred. |
| 287 | */ |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 288 | LY_ERR lyd_value_parse_meta(struct ly_ctx *ctx, struct lyd_meta *meta, const char *value, size_t value_len, int *dynamic, |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 289 | int second, ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format, |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 290 | const struct lysc_node *ctx_snode, const struct lyd_node *tree); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 291 | |
| 292 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 293 | * @brief Parse XML string as YANG data tree. |
| 294 | * |
| 295 | * @param[in] ctx libyang context |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 296 | * @param[in] in Input structure. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 297 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 298 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 299 | * @param[out] tree Parsed data tree. Note that NULL can be a valid result. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 300 | * @return LY_ERR value. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 301 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 302 | LY_ERR lyd_parse_xml_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options, |
| 303 | struct lyd_node **tree); |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 304 | |
| 305 | /** |
| 306 | * @brief Parse XML string as YANG RPC/action invocation. |
| 307 | * |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 308 | * Optional \<rpc\> envelope element is accepted if present. It is [checked](https://tools.ietf.org/html/rfc6241#section-4.1) and all |
| 309 | * its XML attributes are parsed. As a content of the enveloper, an RPC data or \<action\> envelope element is expected. The \<action\> envelope element is |
| 310 | * also [checked](https://tools.ietf.org/html/rfc7950#section-7.15.2) and then an action data is expected as a content of this envelope. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 311 | * |
| 312 | * @param[in] ctx libyang context. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 313 | * @param[in] in Input structure. |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 314 | * @param[out] tree Parsed full RPC/action tree. |
Michal Vasko | cc048b2 | 2020-03-27 15:52:38 +0100 | [diff] [blame] | 315 | * @param[out] op Optional pointer to the actual operation. Useful mainly for action. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 316 | * @return LY_ERR value. |
| 317 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 318 | LY_ERR lyd_parse_xml_rpc(const struct ly_ctx *ctx, struct ly_in *in, struct lyd_node **tree, struct lyd_node **op); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 319 | |
| 320 | /** |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 321 | * @brief Parse XML string as YANG notification. |
| 322 | * |
| 323 | * Optional \<notification\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc5277#page-25) |
| 324 | * and parsed. Specifically, its namespace and the child \<eventTime\> element and its value. |
| 325 | * |
| 326 | * @param[in] ctx libyang context. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 327 | * @param[in] in Input structure. |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 328 | * @param[out] tree Parsed full notification tree. |
Michal Vasko | cc048b2 | 2020-03-27 15:52:38 +0100 | [diff] [blame] | 329 | * @param[out] op Optional pointer to the actual notification. Useful mainly for nested notifications. |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 330 | * @return LY_ERR value. |
| 331 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 332 | LY_ERR lyd_parse_xml_notif(const struct ly_ctx *ctx, struct ly_in *in, struct lyd_node **tree, struct lyd_node **ntf); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 333 | |
| 334 | /** |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 335 | * @brief Parse XML string as YANG RPC/action reply. |
| 336 | * |
| 337 | * Optional \<rpc-reply\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc6241#section-4.2) |
| 338 | * and all its XML attributes parsed. |
| 339 | * |
| 340 | * @param[in] request Data tree of the RPC/action request. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 341 | * @param[in] in Input structure. |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 342 | * @param[out] tree Parsed full reply tree. It always includes duplicated operation and parents of the @p request. |
| 343 | * @param[out] op Optional pointer to the reply operation. Useful mainly for action. |
| 344 | * @return LY_ERR value. |
| 345 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 346 | LY_ERR lyd_parse_xml_reply(const struct lyd_node *request, struct ly_in *in, struct lyd_node **tree, struct lyd_node **op); |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 347 | |
| 348 | /** |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 349 | * @brief Parse binary data as YANG data tree. |
| 350 | * |
| 351 | * @param[in] ctx libyang context |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 352 | * @param[in] in Input structure. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 353 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 354 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 355 | * @param[out] tree Parsed data tree. Note that NULL can be a valid result. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 356 | * @return LY_ERR value. |
| 357 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 358 | LY_ERR lyd_parse_lyb_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options, |
| 359 | struct lyd_node **tree); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 360 | |
| 361 | /** |
| 362 | * @brief Parse binary data as YANG RPC/action invocation. |
| 363 | * |
| 364 | * @param[in] ctx libyang context. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 365 | * @param[in] in Input structure. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 366 | * @param[out] tree Parsed full RPC/action tree. |
| 367 | * @param[out] op Optional pointer to the actual operation. Useful mainly for action. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 368 | * @return LY_ERR value. |
| 369 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 370 | LY_ERR lyd_parse_lyb_rpc(const struct ly_ctx *ctx, struct ly_in *in, struct lyd_node **tree, struct lyd_node **op); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 371 | |
| 372 | /** |
| 373 | * @brief Parse binary data as YANG notification. |
| 374 | * |
| 375 | * @param[in] ctx libyang context. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 376 | * @param[in] in Input structure. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 377 | * @param[out] tree Parsed full notification tree. |
| 378 | * @param[out] op Optional pointer to the actual notification. Useful mainly for nested notifications. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 379 | * @return LY_ERR value. |
| 380 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 381 | LY_ERR lyd_parse_lyb_notif(const struct ly_ctx *ctx, struct ly_in *in, struct lyd_node **tree, struct lyd_node **ntf); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 382 | |
| 383 | /** |
| 384 | * @brief Parse binary data as YANG RPC/action reply. |
| 385 | * |
| 386 | * @param[in] request Data tree of the RPC/action request. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 387 | * @param[in] in Input structure. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 388 | * @param[out] tree Parsed full reply tree. It always includes duplicated operation and parents of the @p request. |
| 389 | * @param[out] op Optional pointer to the reply operation. Useful mainly for action. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 390 | * @return LY_ERR value. |
| 391 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 392 | LY_ERR lyd_parse_lyb_reply(const struct lyd_node *request, struct ly_in *in, struct lyd_node **tree, struct lyd_node **op); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 393 | |
| 394 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 395 | * @defgroup datahash Data nodes hash manipulation |
| 396 | * @ingroup datatree |
| 397 | */ |
| 398 | |
| 399 | /** |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 400 | * @brief Generate hash for the node. |
| 401 | * |
| 402 | * @param[in] node Data node to (re)generate hash value. |
| 403 | * @return LY_ERR value. |
| 404 | */ |
| 405 | LY_ERR lyd_hash(struct lyd_node *node); |
| 406 | |
| 407 | /** |
| 408 | * @brief Insert hash of the node into the hash table of its parent. |
| 409 | * |
| 410 | * @param[in] node Data node which hash will be inserted into the lyd_node_inner::children_hash hash table of its parent. |
| 411 | * @return LY_ERR value. |
| 412 | */ |
| 413 | LY_ERR lyd_insert_hash(struct lyd_node *node); |
| 414 | |
| 415 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 416 | * @brief Maintain node's parent's children hash table when unlinking the node. |
| 417 | * |
| 418 | * When completely freeing data tree, it is expected to free the parent's children hash table first, at once. |
| 419 | * |
| 420 | * @param[in] node The data node being unlinked from its parent. |
| 421 | */ |
| 422 | void lyd_unlink_hash(struct lyd_node *node); |
| 423 | |
| 424 | /** @} datahash */ |
| 425 | |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 426 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 427 | * @brief Find the node, in the list, satisfying the given restrictions. |
| 428 | * Does **not** use hashes - should not be used unless necessary for best performance. |
| 429 | * |
| 430 | * @param[in] first Starting sibling node for search, only succeeding ones are searched. |
| 431 | * @param[in] schema Schema node of the data node to find. |
| 432 | * @param[in] key_or_value Expected value depends on the type of @p schema: |
| 433 | * LYS_CONTAINER: |
| 434 | * LYS_ANYXML: |
| 435 | * LYS_ANYDATA: |
| 436 | * LYS_NOTIF: |
| 437 | * LYS_RPC: |
| 438 | * LYS_ACTION: |
| 439 | * NULL should be always set, will be ignored. |
| 440 | * LYS_LEAF: |
| 441 | * LYS_LEAFLIST: |
| 442 | * Optional restriction on the specific leaf(-list) value. |
| 443 | * LYS_LIST: |
| 444 | * Optional keys values of the matching list instances in the form of "[key1='val1'][key2='val2']...". |
| 445 | * The keys do not have to be ordered and not all keys need to be specified. |
| 446 | * |
| 447 | * Note that any explicit values (leaf, leaf-list or list key values) will be canonized first |
| 448 | * before comparison. But values that do not have a canonical value are expected to be in the |
| 449 | * JSON format! |
| 450 | * @param[in] val_len Optional length of the @p key_or_value argument in case it is not NULL-terminated string. |
| 451 | * @param[out] match Can be NULL, otherwise the found data node. |
| 452 | * @return LY_SUCCESS on success, @p match set. |
| 453 | * @return LY_ENOTFOUND if not found, @p match set to NULL. |
| 454 | * @return LY_ERR value if another error occurred. |
| 455 | */ |
| 456 | LY_ERR lyd_find_sibling_next2(const struct lyd_node *first, const struct lysc_node *schema, const char *key_or_value, |
| 457 | size_t val_len, struct lyd_node **match); |
| 458 | |
| 459 | /** |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 460 | * @brief Iterate over implemented modules for functions that accept specific modules or the whole context. |
| 461 | * |
| 462 | * @param[in] tree Data tree. |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 463 | * @param[in] module Selected module, NULL for all. |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 464 | * @param[in] ctx Context, NULL for selected modules. |
| 465 | * @param[in,out] i Iterator, set to 0 on first call. |
| 466 | * @param[out] first First sibling of the returned module. |
| 467 | * @return Next module. |
| 468 | * @return NULL if all modules were traversed. |
| 469 | */ |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 470 | const struct lys_module *lyd_mod_next_module(struct lyd_node *tree, const struct lys_module *module, |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 471 | const struct ly_ctx *ctx, uint32_t *i, struct lyd_node **first); |
| 472 | |
| 473 | /** |
| 474 | * @brief Iterate over modules for functions that want to traverse all the top-level data. |
| 475 | * |
| 476 | * @param[in,out] next Pointer to the next module data, set to first top-level sibling on first call. |
| 477 | * @param[out] first First sibling of the returned module. |
| 478 | * @return Next module. |
| 479 | * @return NULL if all modules were traversed. |
| 480 | */ |
| 481 | const struct lys_module *lyd_data_next_module(struct lyd_node **next, struct lyd_node **first); |
| 482 | |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 483 | /** |
| 484 | * @brief Check that a list has all its keys. |
| 485 | * |
| 486 | * @param[in] node List to check. |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 487 | * @return LY_SUCCESS on success. |
| 488 | * @return LY_ENOT on a missing key. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 489 | */ |
| 490 | LY_ERR lyd_parse_check_keys(struct lyd_node *node); |
| 491 | |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 492 | /** |
| 493 | * @brief Set data flags for a newly parsed node. |
| 494 | * |
| 495 | * @param[in] node Node to use. |
| 496 | * @param[in] when_check Set of nodes with unresolved when. |
| 497 | * @param[in,out] meta Node metadata, may be removed from. |
| 498 | * @param[in] options Parse options. |
| 499 | */ |
| 500 | void lyd_parse_set_data_flags(struct lyd_node *node, struct ly_set *when_check, struct lyd_meta **meta, int options); |
| 501 | |
| 502 | /** |
| 503 | * @brief Free value prefixes. |
| 504 | * |
| 505 | * @param[in] ctx libyang context. |
| 506 | * @param[in] val_prefis Value prefixes to free, sized array (@ref sizedarrays). |
| 507 | */ |
| 508 | void ly_free_val_prefs(const struct ly_ctx *ctx, struct ly_prefix *val_prefs); |
| 509 | |
Michal Vasko | d59035b | 2020-07-08 12:00:06 +0200 | [diff] [blame^] | 510 | /** |
| 511 | * @brief Append all list key predicates to path. |
| 512 | * |
| 513 | * @param[in] node Node with keys to print. |
| 514 | * @param[in,out] buffer Buffer to print to. |
| 515 | * @param[in,out] buflen Current buffer length. |
| 516 | * @param[in,out] bufused Current number of characters used in @p buffer. |
| 517 | * @param[in] is_static Whether buffer is static or can be reallocated. |
| 518 | * @return LY_ERR |
| 519 | */ |
| 520 | LY_ERR lyd_path_list_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, int is_static); |
| 521 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 522 | #endif /* LY_TREE_DATA_INTERNAL_H_ */ |