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