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> |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 5 | * @brief internal functions for YANG schema trees. |
| 6 | * |
Michal Vasko | 271d2e3 | 2023-01-31 15:43:19 +0100 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2023 CESNET, z.s.p.o. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 8 | * |
| 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * https://opensource.org/licenses/BSD-3-Clause |
| 14 | */ |
| 15 | |
| 16 | #ifndef LY_TREE_DATA_INTERNAL_H_ |
| 17 | #define LY_TREE_DATA_INTERNAL_H_ |
| 18 | |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 19 | #include "log.h" |
Radek Krejci | aca7403 | 2019-06-04 08:53:06 +0200 | [diff] [blame] | 20 | #include "plugins_types.h" |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 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; |
Michal Vasko | 8cc3f66 | 2022-03-29 11:25:51 +0200 | [diff] [blame] | 26 | struct lyd_ctx; |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 27 | struct lysc_module; |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 28 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 29 | #define LY_XML_SUFFIX ".xml" |
| 30 | #define LY_XML_SUFFIX_LEN 4 |
| 31 | #define LY_JSON_SUFFIX ".json" |
| 32 | #define LY_JSON_SUFFIX_LEN 5 |
| 33 | #define LY_LYB_SUFFIX ".lyb" |
| 34 | #define LY_LYB_SUFFIX_LEN 4 |
| 35 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 36 | /** |
Michal Vasko | 271d2e3 | 2023-01-31 15:43:19 +0100 | [diff] [blame] | 37 | * @brief Internal item structure for remembering "used" instances of duplicate node instances. |
Michal Vasko | d7c048c | 2021-05-18 16:12:55 +0200 | [diff] [blame] | 38 | */ |
| 39 | struct lyd_dup_inst { |
Michal Vasko | 271d2e3 | 2023-01-31 15:43:19 +0100 | [diff] [blame] | 40 | struct ly_set *set; |
Michal Vasko | d7c048c | 2021-05-18 16:12:55 +0200 | [diff] [blame] | 41 | uint32_t used; |
| 42 | }; |
| 43 | |
| 44 | /** |
Michal Vasko | 271d2e3 | 2023-01-31 15:43:19 +0100 | [diff] [blame] | 45 | * @brief Update a found inst using a duplicate instance cache hash table. Needs to be called for every "used" |
Michal Vasko | d7c048c | 2021-05-18 16:12:55 +0200 | [diff] [blame] | 46 | * (that should not be considered next time) instance. |
| 47 | * |
| 48 | * @param[in,out] inst Found instance, is updated so that the same instance is not returned twice. |
| 49 | * @param[in] siblings Siblings where @p inst was found. |
Michal Vasko | 271d2e3 | 2023-01-31 15:43:19 +0100 | [diff] [blame] | 50 | * @param[in] dup_inst_ht Duplicate instance cache hash table. |
Michal Vasko | d7c048c | 2021-05-18 16:12:55 +0200 | [diff] [blame] | 51 | * @return LY_ERR value. |
| 52 | */ |
Michal Vasko | 8efac24 | 2023-03-30 08:24:56 +0200 | [diff] [blame] | 53 | LY_ERR lyd_dup_inst_next(struct lyd_node **inst, const struct lyd_node *siblings, struct ly_ht **dup_inst_ht); |
Michal Vasko | d7c048c | 2021-05-18 16:12:55 +0200 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * @brief Free duplicate instance cache. |
| 57 | * |
Michal Vasko | 271d2e3 | 2023-01-31 15:43:19 +0100 | [diff] [blame] | 58 | * @param[in] dup_inst Duplicate instance cache hash table to free. |
Michal Vasko | d7c048c | 2021-05-18 16:12:55 +0200 | [diff] [blame] | 59 | */ |
Michal Vasko | 8efac24 | 2023-03-30 08:24:56 +0200 | [diff] [blame] | 60 | void lyd_dup_inst_free(struct ly_ht *dup_inst_ht); |
Michal Vasko | d7c048c | 2021-05-18 16:12:55 +0200 | [diff] [blame] | 61 | |
| 62 | /** |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 63 | * @brief Just like ::lys_getnext() but iterates over all data instances of the schema nodes. |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 64 | * |
| 65 | * @param[in] last Last returned data node. |
| 66 | * @param[in] sibling Data node sibling to search in. |
| 67 | * @param[in,out] slast Schema last node, set to NULL for first call and do not change afterwards. |
| 68 | * May not be set if the function is used only for any suitable node existence check (such as the existence |
| 69 | * of any choice case data). |
| 70 | * @param[in] parent Schema parent of the iterated children nodes. |
| 71 | * @param[in] module Schema module of the iterated top-level nodes. |
| 72 | * @return Next matching data node, |
| 73 | * @return NULL if last data node was already returned. |
| 74 | */ |
| 75 | struct lyd_node *lys_getnext_data(const struct lyd_node *last, const struct lyd_node *sibling, |
Michal Vasko | 106f086 | 2021-11-02 11:49:27 +0100 | [diff] [blame] | 76 | const struct lysc_node **slast, const struct lysc_node *parent, const struct lysc_module *module); |
| 77 | |
| 78 | /** |
| 79 | * @brief Get address of a node's child pointer if any. |
| 80 | * |
| 81 | * @param[in] node Node to check. |
| 82 | * @return Address of the node's child member, |
| 83 | * @return NULL if there is no child pointer. |
| 84 | */ |
| 85 | struct lyd_node **lyd_node_child_p(struct lyd_node *node); |
| 86 | |
| 87 | /** |
| 88 | * @brief Update node pointer to point to the first data node of a module, leave unchanged if there is none. |
| 89 | * |
| 90 | * @param[in,out] node Node pointer, may be updated. |
| 91 | * @param[in] mod Module whose data to search for. |
| 92 | */ |
| 93 | void lyd_first_module_sibling(struct lyd_node **node, const struct lys_module *mod); |
| 94 | |
| 95 | /** |
| 96 | * @brief Iterate over implemented modules for functions that accept specific modules or the whole context. |
| 97 | * |
| 98 | * @param[in] tree Data tree. |
| 99 | * @param[in] module Selected module, NULL for all. |
| 100 | * @param[in] ctx Context, NULL for selected modules. |
| 101 | * @param[in,out] i Iterator, set to 0 on first call. |
| 102 | * @param[out] first First sibling of the returned module. |
| 103 | * @return Next module. |
| 104 | * @return NULL if all modules were traversed. |
| 105 | */ |
| 106 | const struct lys_module *lyd_mod_next_module(struct lyd_node *tree, const struct lys_module *module, |
| 107 | const struct ly_ctx *ctx, uint32_t *i, struct lyd_node **first); |
| 108 | |
| 109 | /** |
| 110 | * @brief Iterate over modules for functions that want to traverse all the top-level data. |
| 111 | * |
| 112 | * @param[in,out] next Pointer to the next module data, set to first top-level sibling on first call. |
| 113 | * @param[out] first First sibling of the returned module. |
| 114 | * @return Next module. |
| 115 | * @return NULL if all modules were traversed. |
| 116 | */ |
| 117 | const struct lys_module *lyd_data_next_module(struct lyd_node **next, struct lyd_node **first); |
| 118 | |
| 119 | /** |
Michal Vasko | 4754d4a | 2022-12-01 10:11:21 +0100 | [diff] [blame] | 120 | * @brief Set dflt flag for a NP container if applicable, recursively for parents. |
| 121 | * |
| 122 | * @param[in] node Node whose criteria for the dflt flag has changed. |
| 123 | */ |
| 124 | void lyd_cont_set_dflt(struct lyd_node *node); |
| 125 | |
| 126 | /** |
Michal Vasko | 59892dd | 2022-05-13 11:02:30 +0200 | [diff] [blame] | 127 | * @brief Search in the given siblings (NOT recursively) for the first schema node data instance. |
| 128 | * Uses hashes - should be used whenever possible for best performance. |
| 129 | * |
| 130 | * @param[in] siblings Siblings to search in including preceding and succeeding nodes. |
| 131 | * @param[in] schema Target data node schema to find. |
| 132 | * @param[out] match Can be NULL, otherwise the found data node. |
| 133 | * @return LY_SUCCESS on success, @p match set. |
| 134 | * @return LY_ENOTFOUND if not found, @p match set to NULL. |
| 135 | * @return LY_ERR value if another error occurred. |
| 136 | */ |
| 137 | LY_ERR lyd_find_sibling_schema(const struct lyd_node *siblings, const struct lysc_node *schema, struct lyd_node **match); |
| 138 | |
| 139 | /** |
Michal Vasko | 106f086 | 2021-11-02 11:49:27 +0100 | [diff] [blame] | 140 | * @brief Check whether a node to be deleted is the root node, move it if it is. |
| 141 | * |
| 142 | * @param[in] root Root sibling. |
| 143 | * @param[in] to_del Node to be deleted. |
| 144 | * @param[in] mod If set, it is expected @p tree should point to the first node of @p mod. Otherwise it will simply be |
| 145 | * the first top-level sibling. |
| 146 | */ |
| 147 | void lyd_del_move_root(struct lyd_node **root, const struct lyd_node *to_del, const struct lys_module *mod); |
| 148 | |
| 149 | /** |
Michal Vasko | 8cc3f66 | 2022-03-29 11:25:51 +0200 | [diff] [blame] | 150 | * @brief Try to get schema node for data with a parent based on an extension instance. |
| 151 | * |
| 152 | * @param[in] parent Parsed parent data node. Set if @p sparent is NULL. |
| 153 | * @param[in] sparent Schema parent node. Set if @p sparent is NULL. |
| 154 | * @param[in] prefix Element prefix, if any. |
| 155 | * @param[in] prefix_len Length of @p prefix. |
| 156 | * @param[in] format Format of @p prefix. |
| 157 | * @param[in] prefix_data Format-specific data. |
| 158 | * @param[in] name Element name. |
| 159 | * @param[in] name_len Length of @p name. |
| 160 | * @param[out] snode Found schema node, NULL if no suitable was found. |
Michal Vasko | 66330fc | 2022-11-21 15:52:24 +0100 | [diff] [blame] | 161 | * @param[out] ext Optional extension instance that provided @p snode. |
Michal Vasko | 8cc3f66 | 2022-03-29 11:25:51 +0200 | [diff] [blame] | 162 | * @return LY_SUCCESS on success; |
| 163 | * @return LY_ENOT if no extension instance parsed the data; |
| 164 | * @return LY_ERR on error. |
| 165 | */ |
| 166 | LY_ERR ly_nested_ext_schema(const struct lyd_node *parent, const struct lysc_node *sparent, const char *prefix, |
| 167 | size_t prefix_len, LY_VALUE_FORMAT format, void *prefix_data, const char *name, size_t name_len, |
| 168 | const struct lysc_node **snode, struct lysc_ext_instance **ext); |
| 169 | |
| 170 | /** |
Michal Vasko | 106f086 | 2021-11-02 11:49:27 +0100 | [diff] [blame] | 171 | * @brief Free stored prefix data. |
| 172 | * |
| 173 | * @param[in] format Format of the prefixes. |
| 174 | * @param[in] prefix_data Format-specific data to free: |
| 175 | * LY_PREF_SCHEMA - const struct lysp_module * (module used for resolving prefixes from imports) |
| 176 | * LY_PREF_SCHEMA_RESOLVED - struct lyd_value_prefix * (sized array of pairs: prefix - module) |
| 177 | * LY_PREF_XML - const struct ly_set * (set with defined namespaces stored as ::lyxml_ns) |
| 178 | * LY_PREF_JSON - NULL |
| 179 | */ |
| 180 | void ly_free_prefix_data(LY_VALUE_FORMAT format, void *prefix_data); |
| 181 | |
| 182 | /** |
| 183 | * @brief Duplicate prefix data. |
| 184 | * |
| 185 | * @param[in] ctx libyang context. |
| 186 | * @param[in] format Format of the prefixes in the value. |
| 187 | * @param[in] prefix_data Prefix data to duplicate. |
| 188 | * @param[out] prefix_data_p Duplicated prefix data. |
| 189 | * @return LY_ERR value. |
| 190 | */ |
| 191 | LY_ERR ly_dup_prefix_data(const struct ly_ctx *ctx, LY_VALUE_FORMAT format, const void *prefix_data, void **prefix_data_p); |
| 192 | |
| 193 | /** |
| 194 | * @brief Store used prefixes in a string. |
| 195 | * |
| 196 | * If @p prefix_data_p are non-NULL, they are treated as valid according to the @p format_p and new possible |
| 197 | * prefixes are simply added. This way it is possible to store prefix data for several strings together. |
| 198 | * |
| 199 | * @param[in] ctx libyang context. |
| 200 | * @param[in] value Value to be parsed. |
| 201 | * @param[in] value_len Length of the @p value. |
| 202 | * @param[in] format Format of the prefixes in the value. |
| 203 | * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix). |
| 204 | * @param[in,out] format_p Resulting format of the prefixes. |
| 205 | * @param[in,out] prefix_data_p Resulting prefix data for the value in format @p format_p. |
| 206 | * @return LY_ERR value. |
| 207 | */ |
| 208 | LY_ERR ly_store_prefix_data(const struct ly_ctx *ctx, const void *value, size_t value_len, LY_VALUE_FORMAT format, |
| 209 | const void *prefix_data, LY_VALUE_FORMAT *format_p, void **prefix_data_p); |
| 210 | |
| 211 | /** |
| 212 | * @brief Get string name of the format. |
| 213 | * |
| 214 | * @param[in] format Format whose name to get. |
| 215 | * @return Format string name. |
| 216 | */ |
| 217 | const char *ly_format2str(LY_VALUE_FORMAT format); |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 218 | |
| 219 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 220 | * @brief Create a term (leaf/leaf-list) node from a string value. |
| 221 | * |
| 222 | * Hash is calculated and new node flag is set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 223 | * |
| 224 | * @param[in] schema Schema node of the new data node. |
| 225 | * @param[in] value String value to be parsed. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 226 | * @param[in] value_len Length of @p value, must be set correctly. |
Michal Vasko | 989cdb4 | 2023-10-06 15:32:37 +0200 | [diff] [blame] | 227 | * @param[in] is_utf8 Whether @p value is a valid UTF-8 string, if applicable. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 228 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 229 | * @param[in] format Input format of @p value. |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 230 | * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix). |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 231 | * @param[in] hints [Value hints](@ref lydvalhints) from the parser regarding the value type. |
| 232 | * @param[out] incomplete Whether the value needs to be resolved. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 233 | * @param[out] node Created node. |
| 234 | * @return LY_SUCCESS on success. |
| 235 | * @return LY_EINCOMPLETE in case data tree is needed to finish the validation. |
| 236 | * @return LY_ERR value if an error occurred. |
| 237 | */ |
Michal Vasko | 989cdb4 | 2023-10-06 15:32:37 +0200 | [diff] [blame] | 238 | LY_ERR lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, ly_bool is_utf8, |
| 239 | ly_bool *dynamic, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, ly_bool *incomplete, |
| 240 | struct lyd_node **node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 241 | |
| 242 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 243 | * @brief Create a term (leaf/leaf-list) node from a parsed value by duplicating it. |
| 244 | * |
| 245 | * Hash is calculated and new node flag is set. |
| 246 | * |
| 247 | * @param[in] schema Schema node of the new data node. |
| 248 | * @param[in] val Parsed value to use. |
| 249 | * @param[out] node Created node. |
| 250 | * @return LY_SUCCESS on success. |
| 251 | * @return LY_ERR value if an error occurred. |
| 252 | */ |
| 253 | LY_ERR lyd_create_term2(const struct lysc_node *schema, const struct lyd_value *val, struct lyd_node **node); |
| 254 | |
| 255 | /** |
| 256 | * @brief Create an inner (container/list/RPC/action/notification) node. |
| 257 | * |
| 258 | * Hash is calculated and new node flag is set except |
| 259 | * for list with keys, when the hash is not calculated! |
| 260 | * Also, non-presence container has its default flag set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 261 | * |
| 262 | * @param[in] schema Schema node of the new data node. |
| 263 | * @param[out] node Created node. |
| 264 | * @return LY_SUCCESS on success. |
| 265 | * @return LY_ERR value if an error occurred. |
| 266 | */ |
| 267 | LY_ERR lyd_create_inner(const struct lysc_node *schema, struct lyd_node **node); |
| 268 | |
| 269 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 270 | * @brief Create a list with all its keys (cannot be used for key-less list). |
| 271 | * |
| 272 | * Hash is calculated and new node flag is set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 273 | * |
| 274 | * @param[in] schema Schema node of the new data node. |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 275 | * @param[in] predicates Compiled key list predicates. |
Michal Vasko | 9018996 | 2023-02-28 12:10:34 +0100 | [diff] [blame] | 276 | * @param[in] vars Array of defined variables to use in predicates, may be NULL. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 277 | * @param[out] node Created node. |
| 278 | * @return LY_SUCCESS on success. |
| 279 | * @return LY_ERR value if an error occurred. |
| 280 | */ |
Michal Vasko | 9018996 | 2023-02-28 12:10:34 +0100 | [diff] [blame] | 281 | LY_ERR lyd_create_list(const struct lysc_node *schema, const struct ly_path_predicate *predicates, |
| 282 | const struct lyxp_var *vars, struct lyd_node **node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 283 | |
| 284 | /** |
Michal Vasko | 59892dd | 2022-05-13 11:02:30 +0200 | [diff] [blame] | 285 | * @brief Create a list with all its keys (cannot be used for key-less list). |
| 286 | * |
| 287 | * Hash is calculated and new node flag is set. |
| 288 | * |
| 289 | * @param[in] schema Schema node of the new data node. |
| 290 | * @param[in] keys Key list predicates. |
| 291 | * @param[in] keys_len Length of @p keys. |
| 292 | * @param[out] node Created node. |
| 293 | * @return LY_SUCCESS on success. |
| 294 | * @return LY_ERR value if an error occurred. |
| 295 | */ |
| 296 | LY_ERR lyd_create_list2(const struct lysc_node *schema, const char *keys, size_t keys_len, struct lyd_node **node); |
| 297 | |
| 298 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 299 | * @brief Create an anyxml/anydata node. |
| 300 | * |
| 301 | * 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] | 302 | * |
| 303 | * @param[in] schema Schema node of the new data node. |
Michal Vasko | 366a4a1 | 2020-12-04 16:23:57 +0100 | [diff] [blame] | 304 | * @param[in] value Value of the any node. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 305 | * @param[in] value_type Value type of the value. |
Michal Vasko | 742a5b1 | 2022-02-24 16:07:27 +0100 | [diff] [blame] | 306 | * @param[in] use_value Whether to use dynamic @p value or duplicate it. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 307 | * @param[out] node Created node. |
| 308 | * @return LY_SUCCESS on success. |
| 309 | * @return LY_ERR value if an error occurred. |
| 310 | */ |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 311 | LY_ERR lyd_create_any(const struct lysc_node *schema, const void *value, LYD_ANYDATA_VALUETYPE value_type, |
Michal Vasko | 366a4a1 | 2020-12-04 16:23:57 +0100 | [diff] [blame] | 312 | ly_bool use_value, struct lyd_node **node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 313 | |
| 314 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 315 | * @brief Create an opaque node. |
| 316 | * |
| 317 | * @param[in] ctx libyang context. |
| 318 | * @param[in] name Element name. |
| 319 | * @param[in] name_len Length of @p name, must be set correctly. |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 320 | * @param[in] prefix Element prefix. |
| 321 | * @param[in] pref_len Length of @p prefix, must be set correctly. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 322 | * @param[in] module_key Mandatory key to reference module, can be namespace or name. |
| 323 | * @param[in] module_key_len Length of @p module_key, must be set correctly. |
Michal Vasko | 501af03 | 2020-11-11 20:27:44 +0100 | [diff] [blame] | 324 | * @param[in] value String value to be parsed. |
| 325 | * @param[in] value_len Length of @p value, must be set correctly. |
| 326 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
| 327 | * @param[in] format Input format of @p value and @p ns. |
Radek Krejci | ec9ad60 | 2021-01-04 10:46:30 +0100 | [diff] [blame] | 328 | * @param[in] val_prefix_data Format-specific prefix data, param is spent (even in case the function fails): |
| 329 | * LY_PREF_SCHEMA - const struct lysp_module * (module used for resolving prefixes from imports) |
| 330 | * LY_PREF_SCHEMA_RESOLVED - struct lyd_value_prefix * (sized array of pairs: prefix - module) |
| 331 | * LY_PREF_XML - const struct ly_set * (set with defined namespaces stored as ::lyxml_ns) |
| 332 | * LY_PREF_JSON - NULL |
Michal Vasko | 501af03 | 2020-11-11 20:27:44 +0100 | [diff] [blame] | 333 | * @param[in] hints [Hints](@ref lydhints) from the parser regarding the node/value type. |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 334 | * @param[out] node Created node. |
| 335 | * @return LY_SUCCESS on success. |
| 336 | * @return LY_ERR value if an error occurred. |
| 337 | */ |
Michal Vasko | 501af03 | 2020-11-11 20:27:44 +0100 | [diff] [blame] | 338 | LY_ERR lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_len, const char *prefix, size_t pref_len, |
| 339 | const char *module_key, size_t module_key_len, const char *value, size_t value_len, ly_bool *dynamic, |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 340 | LY_VALUE_FORMAT format, void *val_prefix_data, uint32_t hints, struct lyd_node **node); |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 341 | |
| 342 | /** |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 343 | * @brief Check the existence and create any non-existing implicit siblings, recursively for the created nodes. |
| 344 | * |
| 345 | * @param[in] parent Parent of the potential default values, NULL for top-level siblings. |
| 346 | * @param[in,out] first First sibling. |
| 347 | * @param[in] sparent Schema parent of the siblings, NULL if schema of @p parent can be used. |
| 348 | * @param[in] mod Module of the default values, NULL for nested siblings. |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 349 | * @param[in] node_when Optional set to add nodes with "when" conditions into. |
Michal Vasko | c43c8ab | 2021-03-05 13:32:44 +0100 | [diff] [blame] | 350 | * @param[in] node_types Optional set to add nodes with unresolved types into. |
Michal Vasko | fcbd78f | 2022-08-26 08:34:15 +0200 | [diff] [blame] | 351 | * @param[in] ext_node Optional set to add nodes with extension instance node callbacks into. |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 352 | * @param[in] impl_opts Implicit options (@ref implicitoptions). |
| 353 | * @param[in,out] diff Validation diff. |
| 354 | * @return LY_ERR value. |
| 355 | */ |
| 356 | LY_ERR lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struct lysc_node *sparent, |
Michal Vasko | fcbd78f | 2022-08-26 08:34:15 +0200 | [diff] [blame] | 357 | const struct lys_module *mod, struct ly_set *node_when, struct ly_set *node_types, struct ly_set *ext_node, |
| 358 | uint32_t impl_opts, struct lyd_node **diff); |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 359 | |
| 360 | /** |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 361 | * @brief Find the next node, before which to insert the new node. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 362 | * |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 363 | * @param[in] first_sibling First sibling of the nodes to consider. |
| 364 | * @param[in] new_node Node that will be inserted. |
| 365 | * @return Node to insert after. |
| 366 | * @return NULL if the new node should be first. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 367 | */ |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 368 | 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] | 369 | |
| 370 | /** |
Michal Vasko | c61dd06 | 2022-06-07 11:01:28 +0200 | [diff] [blame] | 371 | * @brief Insert node after a sibling. |
| 372 | * |
| 373 | * Handles inserting into NP containers and key-less lists. |
| 374 | * |
| 375 | * @param[in] sibling Sibling to insert after. |
| 376 | * @param[in] node Node to insert. |
| 377 | */ |
| 378 | void lyd_insert_after_node(struct lyd_node *sibling, struct lyd_node *node); |
| 379 | |
| 380 | /** |
| 381 | * @brief Insert node before a sibling. |
| 382 | * |
| 383 | * Handles inserting into NP containers and key-less lists. |
| 384 | * |
| 385 | * @param[in] sibling Sibling to insert before. |
| 386 | * @param[in] node Node to insert. |
| 387 | */ |
| 388 | void lyd_insert_before_node(struct lyd_node *sibling, struct lyd_node *node); |
| 389 | |
| 390 | /** |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 391 | * @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] | 392 | * |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 393 | * @param[in] parent Parent to insert into, NULL for top-level sibling. |
| 394 | * @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] | 395 | * @param[in] node Individual node (without siblings) to insert. |
Michal Vasko | 6ee6f43 | 2021-07-16 09:49:14 +0200 | [diff] [blame] | 396 | * @param[in] last If set, do not search for the correct anchor but always insert at the end. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 397 | */ |
Michal Vasko | 6ee6f43 | 2021-07-16 09:49:14 +0200 | [diff] [blame] | 398 | void lyd_insert_node(struct lyd_node *parent, struct lyd_node **first_sibling, struct lyd_node *node, ly_bool last); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 399 | |
| 400 | /** |
Michal Vasko | 2e784f8 | 2024-01-11 09:51:22 +0100 | [diff] [blame] | 401 | * @brief Unlink the specified data subtree. |
| 402 | * |
| 403 | * @param[in] node Data tree node to be unlinked (together with all the children). |
| 404 | */ |
| 405 | void lyd_unlink(struct lyd_node *node); |
| 406 | |
| 407 | /** |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 408 | * @brief Insert a metadata (last) into a parent |
| 409 | * |
| 410 | * @param[in] parent Parent of the metadata. |
| 411 | * @param[in] meta Metadata (list) to be added into the @p parent. |
Michal Vasko | 871a025 | 2020-11-11 18:35:24 +0100 | [diff] [blame] | 412 | * @param[in] clear_dflt Whether to clear dflt flag starting from @p parent, recursively all NP containers. |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 413 | */ |
Michal Vasko | 871a025 | 2020-11-11 18:35:24 +0100 | [diff] [blame] | 414 | void lyd_insert_meta(struct lyd_node *parent, struct lyd_meta *meta, ly_bool clear_dflt); |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 415 | |
| 416 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 417 | * @brief Create and insert a metadata (last) into a parent. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 418 | * |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 419 | * @param[in] parent Parent of the metadata, can be NULL. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 420 | * @param[in,out] meta Metadata list to add at its end if @p parent is NULL, returned created attribute. |
| 421 | * @param[in] mod Metadata module (with the annotation definition). |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 422 | * @param[in] name Attribute name. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 423 | * @param[in] name_len Length of @p name, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 424 | * @param[in] value String value to be parsed. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 425 | * @param[in] value_len Length of @p value, must be set correctly. |
Michal Vasko | 989cdb4 | 2023-10-06 15:32:37 +0200 | [diff] [blame] | 426 | * @param[in] is_utf8 Whether @p value is a valid UTF-8 string, if applicable. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 427 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 428 | * @param[in] format Input format of @p value. |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 429 | * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix). |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 430 | * @param[in] hints [Value hints](@ref lydvalhints) from the parser regarding the value type. |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 431 | * @param[in] ctx_node Value context node, may be NULL for metadata. |
Michal Vasko | 871a025 | 2020-11-11 18:35:24 +0100 | [diff] [blame] | 432 | * @param[in] clear_dflt Whether to clear dflt flag starting from @p parent, recursively all NP containers. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 433 | * @param[out] incomplete Whether the value needs to be resolved. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 434 | * @return LY_SUCCESS on success. |
| 435 | * @return LY_EINCOMPLETE in case data tree is needed to finish the validation. |
| 436 | * @return LY_ERR value if an error occurred. |
| 437 | */ |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 438 | LY_ERR lyd_create_meta(struct lyd_node *parent, struct lyd_meta **meta, const struct lys_module *mod, const char *name, |
Michal Vasko | 989cdb4 | 2023-10-06 15:32:37 +0200 | [diff] [blame] | 439 | size_t name_len, const char *value, size_t value_len, ly_bool is_utf8, ly_bool *dynamic, LY_VALUE_FORMAT format, |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 440 | void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node, ly_bool clear_dflt, ly_bool *incomplete); |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 441 | |
| 442 | /** |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 443 | * @brief Insert an attribute (last) into a parent |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 444 | * |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 445 | * @param[in] parent Parent of the attributes. |
| 446 | * @param[in] attr Attribute (list) to be added into the @p parent. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 447 | */ |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 448 | void lyd_insert_attr(struct lyd_node *parent, struct lyd_attr *attr); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 449 | |
| 450 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 451 | * @brief Create and insert a generic attribute (last) into a parent. |
| 452 | * |
| 453 | * @param[in] parent Parent of the attribute, can be NULL. |
| 454 | * @param[in,out] attr Attribute list to add at its end if @p parent is NULL, returned created attribute. |
| 455 | * @param[in] ctx libyang context. |
| 456 | * @param[in] name Attribute name. |
| 457 | * @param[in] name_len Length of @p name, must be set correctly. |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 458 | * @param[in] prefix Attribute prefix. |
| 459 | * @param[in] prefix_len Attribute prefix length. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 460 | * @param[in] module_key Mandatory key to reference module, can be namespace or name. |
| 461 | * @param[in] module_key_len Length of @p module_key, must be set correctly. |
Michal Vasko | 501af03 | 2020-11-11 20:27:44 +0100 | [diff] [blame] | 462 | * @param[in] value String value to be parsed. |
| 463 | * @param[in] value_len Length of @p value, must be set correctly. |
| 464 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
| 465 | * @param[in] format Input format of @p value and @p ns. |
| 466 | * @param[in] val_prefix_data Format-specific prefix data, param is spent (even in case the function fails). |
| 467 | * @param[in] hints [Hints](@ref lydhints) from the parser regarding the node/value type. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 468 | * @return LY_SUCCESS on success, |
| 469 | * @return LY_ERR value on error. |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 470 | */ |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 471 | LY_ERR lyd_create_attr(struct lyd_node *parent, struct lyd_attr **attr, const struct ly_ctx *ctx, const char *name, |
Michal Vasko | 501af03 | 2020-11-11 20:27:44 +0100 | [diff] [blame] | 472 | size_t name_len, const char *prefix, size_t prefix_len, const char *module_key, size_t module_key_len, |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 473 | const char *value, size_t value_len, ly_bool *dynamic, LY_VALUE_FORMAT format, void *val_prefix_data, uint32_t hints); |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 474 | |
| 475 | /** |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 476 | * @brief Store and canonize the given @p value into @p val according to the schema node type rules. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 477 | * |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 478 | * @param[in] ctx libyang context. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 479 | * @param[in,out] val Storage for the value. |
| 480 | * @param[in] type Type of the value. |
Radek Krejci | f994364 | 2021-04-26 10:18:21 +0200 | [diff] [blame] | 481 | * @param[in] value Value to be parsed, must not be NULL. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 482 | * @param[in] value_len Length of the give @p value, must be set correctly. |
Michal Vasko | 989cdb4 | 2023-10-06 15:32:37 +0200 | [diff] [blame] | 483 | * @param[in] is_utf8 Whether @p value is a valid UTF-8 string, if applicable. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 484 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 485 | * @param[in] format Input format of @p value. |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 486 | * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix). |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 487 | * @param[in] hints [Value hints](@ref lydvalhints) from the parser. |
| 488 | * @param[in] ctx_node Context schema node. |
| 489 | * @param[out] incomplete Optional, set if the value also needs to be resolved. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 490 | * @return LY_SUCCESS on success, |
| 491 | * @return LY_ERR value on error. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 492 | */ |
Radek Krejci | f994364 | 2021-04-26 10:18:21 +0200 | [diff] [blame] | 493 | LY_ERR lyd_value_store(const struct ly_ctx *ctx, struct lyd_value *val, const struct lysc_type *type, const void *value, |
Michal Vasko | 989cdb4 | 2023-10-06 15:32:37 +0200 | [diff] [blame] | 494 | size_t value_len, ly_bool is_utf8, ly_bool *dynamic, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 495 | const struct lysc_node *ctx_node, ly_bool *incomplete); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 496 | |
| 497 | /** |
| 498 | * @brief Validate previously incompletely stored value. |
| 499 | * |
| 500 | * @param[in] ctx libyang context. |
| 501 | * @param[in] type Schema type of the value (not the stored one, but the original one). |
| 502 | * @param[in,out] val Stored value to resolve. |
| 503 | * @param[in] ctx_node Context node for the resolution. |
| 504 | * @param[in] tree Data tree for the resolution. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 505 | * @return LY_SUCCESS on success, |
| 506 | * @return LY_ERR value on error. |
| 507 | */ |
| 508 | LY_ERR lyd_value_validate_incomplete(const struct ly_ctx *ctx, const struct lysc_type *type, struct lyd_value *val, |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 509 | const struct lyd_node *ctx_node, const struct lyd_node *tree); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 510 | |
Michal Vasko | aebbce0 | 2021-04-06 09:23:37 +0200 | [diff] [blame] | 511 | /** |
Michal Vasko | 583b464 | 2023-05-25 10:39:34 +0200 | [diff] [blame] | 512 | * @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value. |
Michal Vasko | aebbce0 | 2021-04-06 09:23:37 +0200 | [diff] [blame] | 513 | * |
| 514 | * This function check just the type's restriction, if you want to check also the data tree context (e.g. in case of |
| 515 | * require-instance restriction), use ::lyd_value_validate(). |
| 516 | * |
| 517 | * @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL) |
| 518 | * @param[in] node Schema node for the @p value. |
| 519 | * @param[in] value String value to be checked, expected to be in JSON format. |
| 520 | * @param[in] value_len Length of the given @p value (mandatory). |
| 521 | * @param[in] format Value prefix format. |
| 522 | * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix). |
Michal Vasko | 583b464 | 2023-05-25 10:39:34 +0200 | [diff] [blame] | 523 | * @param[in] hints Value encoding hints. |
Michal Vasko | aebbce0 | 2021-04-06 09:23:37 +0200 | [diff] [blame] | 524 | * @return LY_SUCCESS on success |
| 525 | * @return LY_ERR value if an error occurred. |
| 526 | */ |
Michal Vasko | 583b464 | 2023-05-25 10:39:34 +0200 | [diff] [blame] | 527 | LY_ERR ly_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len, |
| 528 | LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints); |
Michal Vasko | f937cfe | 2020-08-03 16:07:12 +0200 | [diff] [blame] | 529 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 530 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 531 | * @defgroup datahash Data nodes hash manipulation |
| 532 | * @ingroup datatree |
Michal Vasko | 8081a81 | 2021-07-15 09:19:43 +0200 | [diff] [blame] | 533 | * @{ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 534 | */ |
| 535 | |
| 536 | /** |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 537 | * @brief Generate hash for the node. |
| 538 | * |
| 539 | * @param[in] node Data node to (re)generate hash value. |
| 540 | * @return LY_ERR value. |
| 541 | */ |
| 542 | LY_ERR lyd_hash(struct lyd_node *node); |
| 543 | |
| 544 | /** |
| 545 | * @brief Insert hash of the node into the hash table of its parent. |
| 546 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 547 | * @param[in] node Data node which hash will be inserted into the ::lyd_node_inner.children_ht hash table of its parent. |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 548 | * @return LY_ERR value. |
| 549 | */ |
| 550 | LY_ERR lyd_insert_hash(struct lyd_node *node); |
| 551 | |
| 552 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 553 | * @brief Maintain node's parent's children hash table when unlinking the node. |
| 554 | * |
| 555 | * When completely freeing data tree, it is expected to free the parent's children hash table first, at once. |
| 556 | * |
| 557 | * @param[in] node The data node being unlinked from its parent. |
| 558 | */ |
| 559 | void lyd_unlink_hash(struct lyd_node *node); |
| 560 | |
| 561 | /** @} datahash */ |
| 562 | |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 563 | /** |
Michal Vasko | d59035b | 2020-07-08 12:00:06 +0200 | [diff] [blame] | 564 | * @brief Append all list key predicates to path. |
| 565 | * |
| 566 | * @param[in] node Node with keys to print. |
| 567 | * @param[in,out] buffer Buffer to print to. |
| 568 | * @param[in,out] buflen Current buffer length. |
| 569 | * @param[in,out] bufused Current number of characters used in @p buffer. |
| 570 | * @param[in] is_static Whether buffer is static or can be reallocated. |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 571 | * @return LY_ERR value. |
Michal Vasko | d59035b | 2020-07-08 12:00:06 +0200 | [diff] [blame] | 572 | */ |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 573 | LY_ERR lyd_path_list_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, ly_bool is_static); |
Michal Vasko | d59035b | 2020-07-08 12:00:06 +0200 | [diff] [blame] | 574 | |
Michal Vasko | 413af59 | 2021-12-13 11:50:51 +0100 | [diff] [blame] | 575 | /** |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 576 | * @brief Generate a path similar to ::lyd_path() except read the parents from a set. |
| 577 | * |
| 578 | * @param[in] dnodes Set with the data nodes, from parent to the last descendant. |
| 579 | * @param[in] pathtype Type of data path to generate. |
| 580 | * @return Generated data path. |
| 581 | */ |
| 582 | char *lyd_path_set(const struct ly_set *dnodes, LYD_PATH_TYPE pathtype); |
| 583 | |
| 584 | /** |
Michal Vasko | 413af59 | 2021-12-13 11:50:51 +0100 | [diff] [blame] | 585 | * @brief Remove an object on the specific set index keeping the order of the other objects. |
| 586 | * |
| 587 | * @param[in] set Set from which a node will be removed. |
| 588 | * @param[in] index Index of the object to remove in the \p set. |
| 589 | * @param[in] destructor Optional function to free the objects being removed. |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 590 | * @return LY_ERR value. |
Michal Vasko | 413af59 | 2021-12-13 11:50:51 +0100 | [diff] [blame] | 591 | */ |
| 592 | LY_ERR ly_set_rm_index_ordered(struct ly_set *set, uint32_t index, void (*destructor)(void *obj)); |
| 593 | |
steweg | f9041a2 | 2024-01-18 13:29:12 +0100 | [diff] [blame] | 594 | /** |
| 595 | * @brief Frees data within leafref links record |
| 596 | * |
| 597 | * @param[in] rec The leafref links record |
| 598 | */ |
| 599 | void lyd_free_leafref_links_rec(struct lyd_leafref_links_rec *rec); |
| 600 | |
| 601 | /** |
| 602 | * @brief Frees all leafref nodes and target node of given data node |
| 603 | * |
| 604 | * @param[in] node The data node, which leafref nodes and/or target node should be cleared. |
| 605 | */ |
| 606 | void lyd_free_leafref_nodes(const struct lyd_node_term *node); |
| 607 | |
| 608 | /** |
| 609 | * @brief Gets or creates the leafref links record. |
| 610 | * |
| 611 | * @param[in] node The term data node. |
| 612 | * @param[out] record The leafref links record. |
| 613 | * @param[in] create Whether to create record if not exists. |
| 614 | * @return LY_SUCCESS on success. |
| 615 | * @return LY_ERR value on error. |
| 616 | */ |
| 617 | LY_ERR lyd_get_or_create_leafref_links_record(const struct lyd_node_term *node, struct lyd_leafref_links_rec **record, ly_bool create); |
| 618 | |
| 619 | /** |
| 620 | * @brief Adds links between leafref adn data node. |
| 621 | * |
| 622 | * If the links were already added, it will not be added again. |
| 623 | * This API requires usage of LY_CTX_LEAFREF_LINKING context flag. |
| 624 | * |
| 625 | * @param[in] node Data node to which, the leafref is pointing to. |
| 626 | * @param[in] leafref_node The leafref, which points to given node. |
| 627 | * @return LY_SUCCESS on success. |
| 628 | * @return LY_ERR value on error. |
| 629 | */ |
| 630 | LY_ERR lyd_link_leafref_node(const struct lyd_node_term *node, const struct lyd_node_term *leafref_node); |
| 631 | |
| 632 | /** |
| 633 | * @brief Removes links between leafref adn data node. |
| 634 | * |
| 635 | * If the links were never added, it will be silently ignored. |
| 636 | * This API requires usage of LY_CTX_LEAFREF_LINKING context flag. |
| 637 | * |
| 638 | * @param[in] node Data node to which, the leafref is pointing to. |
| 639 | * @param[in] leafref_node The leafref, which points to given node. |
| 640 | * @return LY_SUCCESS on success. |
| 641 | * @return LY_ERR value on error. |
| 642 | */ |
| 643 | LY_ERR lyd_unlink_leafref_node(const struct lyd_node_term *node, const struct lyd_node_term *leafref_node); |
| 644 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 645 | #endif /* LY_TREE_DATA_INTERNAL_H_ */ |