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 | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 176 | * @brief Find the next node, before which to insert the new node. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 177 | * |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 178 | * @param[in] first_sibling First sibling of the nodes to consider. |
| 179 | * @param[in] new_node Node that will be inserted. |
| 180 | * @return Node to insert after. |
| 181 | * @return NULL if the new node should be first. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 182 | */ |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 183 | struct lyd_node *lyd_insert_get_next_anchor(const struct lyd_node *first_sibling, const struct lyd_node *new_node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 184 | |
| 185 | /** |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 186 | * @brief Insert a node into parent/siblings. Order and hashes are fully handled. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 187 | * |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 188 | * @param[in] parent Parent to insert into, NULL for top-level sibling. |
| 189 | * @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] | 190 | * @param[in] node Individual node (without siblings) to insert. |
| 191 | */ |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 192 | 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] | 193 | |
| 194 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 195 | * @brief Create and insert a metadata (last) into a parent. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 196 | * |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 197 | * @param[in] parent Parent of the metadata, can be NULL. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 198 | * @param[in,out] meta Metadata list to add at its end if @p parent is NULL, returned created attribute. |
| 199 | * @param[in] mod Metadata module (with the annotation definition). |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 200 | * @param[in] name Attribute name. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 201 | * @param[in] name_len Length of @p name, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 202 | * @param[in] value String value to be parsed. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 203 | * @param[in] value_len Length of @p value, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 204 | * @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] | 205 | * @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] | 206 | * @param[in] prefix_data User data for @p get_prefix. |
| 207 | * @param[in] format Input format of @p value. |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 208 | * @param[in] ctx_snode Context node for value resolution in schema. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 209 | * @return LY_SUCCESS on success. |
| 210 | * @return LY_EINCOMPLETE in case data tree is needed to finish the validation. |
| 211 | * @return LY_ERR value if an error occurred. |
| 212 | */ |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 213 | 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] | 214 | 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] | 215 | void *prefix_data, LYD_FORMAT format, const struct lysc_node *ctx_snode); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 216 | |
| 217 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 218 | * @brief Create and insert a generic attribute (last) into a parent. |
| 219 | * |
| 220 | * @param[in] parent Parent of the attribute, can be NULL. |
| 221 | * @param[in,out] attr Attribute list to add at its end if @p parent is NULL, returned created attribute. |
| 222 | * @param[in] ctx libyang context. |
| 223 | * @param[in] name Attribute name. |
| 224 | * @param[in] name_len Length of @p name, must be set correctly. |
| 225 | * @param[in] value String value to be parsed. |
| 226 | * @param[in] value_len Length of @p value, must be set correctly. |
| 227 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
| 228 | * @param[in] format Input format of @p value and @p ns. |
| 229 | * @param[in] val_prefs Possible value prefixes, array is spent. |
| 230 | * @param[in] prefix Attribute prefix. |
| 231 | * @param[in] prefix_len Attribute prefix length. |
| 232 | * @param[in] ns Attribute namespace, meaning depends on @p format. |
| 233 | * @return LY_SUCCESS on success. |
| 234 | * @return LY_ERR value if an error occurred. |
| 235 | */ |
| 236 | LY_ERR ly_create_attr(struct lyd_node *parent, struct ly_attr **attr, const struct ly_ctx *ctx, const char *name, |
| 237 | size_t name_len, const char *value, size_t value_len, int *dynamic, LYD_FORMAT format, |
| 238 | struct ly_prefix *val_prefs, const char *prefix, size_t prefix_len, const char *ns); |
| 239 | |
| 240 | /** |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 241 | * @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] | 242 | * |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 243 | * @param[in] node Data node for the @p value. |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 244 | * @param[in] value String value to be parsed, must not be NULL. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 245 | * @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] | 246 | * @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] | 247 | * @param[in] second Flag for the second call after returning LY_EINCOMPLETE |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 248 | * @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] | 249 | * @param[in] parser Parser's data for @p get_prefix |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 250 | * @param[in] format Input format of @p value. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 251 | * @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] | 252 | * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete, |
| 253 | * then LY_EINCOMPLETE can be returned. |
| 254 | * @return LY_SUCCESS on success |
| 255 | * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation. |
| 256 | * @return LY_ERR value if an error occurred. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 257 | */ |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 258 | 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] | 259 | 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] | 260 | |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 261 | /* similar to lyd_value_parse except can be used just to store the value, hence does also not support a second call */ |
| 262 | LY_ERR lyd_value_store(struct lyd_value *val, const struct lysc_node *schema, const char *value, size_t value_len, |
| 263 | int *dynamic, ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format); |
| 264 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 265 | /** |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 266 | * @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] | 267 | * |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 268 | * @param[in] ctx libyang context. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 269 | * @param[in] meta Metadata for the @p value. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 270 | * @param[in] value String value to be parsed, must not be NULL. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 271 | * @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] | 272 | * @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] | 273 | * @param[in] second Flag for the second call after returning LY_EINCOMPLETE |
| 274 | * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string. |
| 275 | * @param[in] parser Parser's data for @p get_prefix |
| 276 | * @param[in] format Input format of the data. |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 277 | * @param[in] ctx_snode Context node for value resolution in schema. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 278 | * @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] | 279 | * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete, |
| 280 | * then LY_EINCOMPLETE can be returned. |
| 281 | * @return LY_SUCCESS on success |
| 282 | * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation. |
| 283 | * @return LY_ERR value if an error occurred. |
| 284 | */ |
Michal Vasko | 4158635 | 2020-07-13 13:54:25 +0200 | [diff] [blame] | 285 | LY_ERR lyd_value_parse_meta(const struct ly_ctx *ctx, struct lyd_meta *meta, const char *value, size_t value_len, |
| 286 | int *dynamic, 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] | 287 | const struct lysc_node *ctx_snode, const struct lyd_node *tree); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 288 | |
| 289 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 290 | * @brief Parse XML string as YANG data tree. |
| 291 | * |
| 292 | * @param[in] ctx libyang context |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 293 | * @param[in] in Input structure. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 294 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 295 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 296 | * @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] | 297 | * @return LY_ERR value. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 298 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 299 | LY_ERR lyd_parse_xml_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options, |
| 300 | struct lyd_node **tree); |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 301 | |
| 302 | /** |
| 303 | * @brief Parse XML string as YANG RPC/action invocation. |
| 304 | * |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 305 | * Optional \<rpc\> envelope element is accepted if present. It is [checked](https://tools.ietf.org/html/rfc6241#section-4.1) and all |
| 306 | * 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 |
| 307 | * 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] | 308 | * |
| 309 | * @param[in] ctx libyang context. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 310 | * @param[in] in Input structure. |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 311 | * @param[out] tree Parsed full RPC/action tree. |
Michal Vasko | cc048b2 | 2020-03-27 15:52:38 +0100 | [diff] [blame] | 312 | * @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] | 313 | * @return LY_ERR value. |
| 314 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 315 | 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] | 316 | |
| 317 | /** |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 318 | * @brief Parse XML string as YANG notification. |
| 319 | * |
| 320 | * Optional \<notification\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc5277#page-25) |
| 321 | * and parsed. Specifically, its namespace and the child \<eventTime\> element and its value. |
| 322 | * |
| 323 | * @param[in] ctx libyang context. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 324 | * @param[in] in Input structure. |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 325 | * @param[out] tree Parsed full notification tree. |
Michal Vasko | cc048b2 | 2020-03-27 15:52:38 +0100 | [diff] [blame] | 326 | * @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] | 327 | * @return LY_ERR value. |
| 328 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 329 | 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] | 330 | |
| 331 | /** |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 332 | * @brief Parse XML string as YANG RPC/action reply. |
| 333 | * |
| 334 | * Optional \<rpc-reply\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc6241#section-4.2) |
| 335 | * and all its XML attributes parsed. |
| 336 | * |
| 337 | * @param[in] request Data tree of the RPC/action request. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 338 | * @param[in] in Input structure. |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 339 | * @param[out] tree Parsed full reply tree. It always includes duplicated operation and parents of the @p request. |
| 340 | * @param[out] op Optional pointer to the reply operation. Useful mainly for action. |
| 341 | * @return LY_ERR value. |
| 342 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 343 | 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] | 344 | |
| 345 | /** |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 346 | * @brief Parse binary data as YANG data tree. |
| 347 | * |
| 348 | * @param[in] ctx libyang context |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 349 | * @param[in] in Input structure. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 350 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 351 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 352 | * @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] | 353 | * @return LY_ERR value. |
| 354 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 355 | LY_ERR lyd_parse_lyb_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options, |
| 356 | struct lyd_node **tree); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 357 | |
| 358 | /** |
| 359 | * @brief Parse binary data as YANG RPC/action invocation. |
| 360 | * |
| 361 | * @param[in] ctx libyang context. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 362 | * @param[in] in Input structure. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 363 | * @param[out] tree Parsed full RPC/action tree. |
| 364 | * @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] | 365 | * @return LY_ERR value. |
| 366 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 367 | 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] | 368 | |
| 369 | /** |
| 370 | * @brief Parse binary data as YANG notification. |
| 371 | * |
| 372 | * @param[in] ctx libyang context. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 373 | * @param[in] in Input structure. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 374 | * @param[out] tree Parsed full notification tree. |
| 375 | * @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] | 376 | * @return LY_ERR value. |
| 377 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 378 | 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] | 379 | |
| 380 | /** |
| 381 | * @brief Parse binary data as YANG RPC/action reply. |
| 382 | * |
| 383 | * @param[in] request Data tree of the RPC/action request. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 384 | * @param[in] in Input structure. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 385 | * @param[out] tree Parsed full reply tree. It always includes duplicated operation and parents of the @p request. |
| 386 | * @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] | 387 | * @return LY_ERR value. |
| 388 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 389 | 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] | 390 | |
| 391 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 392 | * @defgroup datahash Data nodes hash manipulation |
| 393 | * @ingroup datatree |
| 394 | */ |
| 395 | |
| 396 | /** |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 397 | * @brief Generate hash for the node. |
| 398 | * |
| 399 | * @param[in] node Data node to (re)generate hash value. |
| 400 | * @return LY_ERR value. |
| 401 | */ |
| 402 | LY_ERR lyd_hash(struct lyd_node *node); |
| 403 | |
| 404 | /** |
| 405 | * @brief Insert hash of the node into the hash table of its parent. |
| 406 | * |
| 407 | * @param[in] node Data node which hash will be inserted into the lyd_node_inner::children_hash hash table of its parent. |
| 408 | * @return LY_ERR value. |
| 409 | */ |
| 410 | LY_ERR lyd_insert_hash(struct lyd_node *node); |
| 411 | |
| 412 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 413 | * @brief Maintain node's parent's children hash table when unlinking the node. |
| 414 | * |
| 415 | * When completely freeing data tree, it is expected to free the parent's children hash table first, at once. |
| 416 | * |
| 417 | * @param[in] node The data node being unlinked from its parent. |
| 418 | */ |
| 419 | void lyd_unlink_hash(struct lyd_node *node); |
| 420 | |
| 421 | /** @} datahash */ |
| 422 | |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 423 | /** |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 424 | * @brief Iterate over implemented modules for functions that accept specific modules or the whole context. |
| 425 | * |
| 426 | * @param[in] tree Data tree. |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 427 | * @param[in] module Selected module, NULL for all. |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 428 | * @param[in] ctx Context, NULL for selected modules. |
| 429 | * @param[in,out] i Iterator, set to 0 on first call. |
| 430 | * @param[out] first First sibling of the returned module. |
| 431 | * @return Next module. |
| 432 | * @return NULL if all modules were traversed. |
| 433 | */ |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 434 | 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] | 435 | const struct ly_ctx *ctx, uint32_t *i, struct lyd_node **first); |
| 436 | |
| 437 | /** |
| 438 | * @brief Iterate over modules for functions that want to traverse all the top-level data. |
| 439 | * |
| 440 | * @param[in,out] next Pointer to the next module data, set to first top-level sibling on first call. |
| 441 | * @param[out] first First sibling of the returned module. |
| 442 | * @return Next module. |
| 443 | * @return NULL if all modules were traversed. |
| 444 | */ |
| 445 | const struct lys_module *lyd_data_next_module(struct lyd_node **next, struct lyd_node **first); |
| 446 | |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 447 | /** |
| 448 | * @brief Check that a list has all its keys. |
| 449 | * |
| 450 | * @param[in] node List to check. |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 451 | * @return LY_SUCCESS on success. |
| 452 | * @return LY_ENOT on a missing key. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 453 | */ |
| 454 | LY_ERR lyd_parse_check_keys(struct lyd_node *node); |
| 455 | |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 456 | /** |
| 457 | * @brief Set data flags for a newly parsed node. |
| 458 | * |
| 459 | * @param[in] node Node to use. |
| 460 | * @param[in] when_check Set of nodes with unresolved when. |
| 461 | * @param[in,out] meta Node metadata, may be removed from. |
| 462 | * @param[in] options Parse options. |
| 463 | */ |
| 464 | void lyd_parse_set_data_flags(struct lyd_node *node, struct ly_set *when_check, struct lyd_meta **meta, int options); |
| 465 | |
| 466 | /** |
Michal Vasko | 61551fa | 2020-07-09 15:45:45 +0200 | [diff] [blame] | 467 | * @brief Copy anydata value from one node to another. Target value is freed first. |
| 468 | * |
| 469 | * @param[in,out] trg Target node. |
| 470 | * @param[in] value Source value, may be NULL when the target value is only freed. |
| 471 | * @param[in] value_type Source value type. |
| 472 | * @return LY_ERR value. |
| 473 | */ |
| 474 | LY_ERR lyd_any_copy_value(struct lyd_node *trg, const union lyd_any_value *value, LYD_ANYDATA_VALUETYPE value_type); |
| 475 | |
| 476 | /** |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 477 | * @brief Free value prefixes. |
| 478 | * |
| 479 | * @param[in] ctx libyang context. |
| 480 | * @param[in] val_prefis Value prefixes to free, sized array (@ref sizedarrays). |
| 481 | */ |
| 482 | void ly_free_val_prefs(const struct ly_ctx *ctx, struct ly_prefix *val_prefs); |
| 483 | |
Michal Vasko | d59035b | 2020-07-08 12:00:06 +0200 | [diff] [blame] | 484 | /** |
| 485 | * @brief Append all list key predicates to path. |
| 486 | * |
| 487 | * @param[in] node Node with keys to print. |
| 488 | * @param[in,out] buffer Buffer to print to. |
| 489 | * @param[in,out] buflen Current buffer length. |
| 490 | * @param[in,out] bufused Current number of characters used in @p buffer. |
| 491 | * @param[in] is_static Whether buffer is static or can be reallocated. |
| 492 | * @return LY_ERR |
| 493 | */ |
| 494 | LY_ERR lyd_path_list_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, int is_static); |
| 495 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 496 | #endif /* LY_TREE_DATA_INTERNAL_H_ */ |