blob: 71681c312f0b52f2fd42d9f1d17547c887b71978 [file] [log] [blame]
Radek Krejcie7b95092019-05-15 11:03:07 +02001/**
2 * @file tree_data_internal.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief internal functions for YANG schema trees.
5 *
Michal Vasko60ea6352020-06-29 13:39:39 +02006 * Copyright (c) 2015 - 2020 CESNET, z.s.p.o.
Radek Krejcie7b95092019-05-15 11:03:07 +02007 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_TREE_DATA_INTERNAL_H_
16#define LY_TREE_DATA_INTERNAL_H_
17
Radek Krejci857189e2020-09-01 13:26:36 +020018#include "log.h"
Michal Vasko60ea6352020-06-29 13:39:39 +020019#include "lyb.h"
Radek Krejciaca74032019-06-04 08:53:06 +020020#include "plugins_types.h"
Michal Vasko60ea6352020-06-29 13:39:39 +020021#include "set.h"
22#include "tree_data.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020023
Michal Vasko52927e22020-03-16 17:26:14 +010024#include <stddef.h>
25
Michal Vasko004d3152020-06-11 19:59:22 +020026struct ly_path_predicate;
Michal Vaskoa6669ba2020-08-06 16:14:26 +020027struct lysc_module;
Michal Vasko004d3152020-06-11 19:59:22 +020028
Radek Krejcif13b87b2020-12-01 22:02:17 +010029#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 Krejcie7b95092019-05-15 11:03:07 +020036/**
Michal Vasko60ea6352020-06-29 13:39:39 +020037 * @brief Internal data parser flags.
38 */
39#define LYD_INTOPT_RPC 0x01 /**< RPC/action invocation is being parsed */
40#define LYD_INTOPT_NOTIF 0x02 /**< notification is being parsed */
41#define LYD_INTOPT_REPLY 0x04 /**< RPC/action reply is being parsed */
42
43/**
44 * @brief Hash schema sibling to be used for LYB data.
45 *
46 * @param[in] sibling Sibling to hash.
47 * @param[in] collision_id Collision ID of the hash to generate.
48 * @return Generated hash.
49 */
50LYB_HASH lyb_hash(struct lysc_node *sibling, uint8_t collision_id);
51
52/**
Radek Krejci857189e2020-09-01 13:26:36 +020053 * @brief Check whether a sibling's module is in a module array.
Michal Vasko60ea6352020-06-29 13:39:39 +020054 *
55 * @param[in] sibling Sibling to check.
56 * @param[in] models Modules in a sized array.
57 * @return non-zero if the module was found,
Radek Krejci857189e2020-09-01 13:26:36 +020058 * @return Boolean value whether @p sibling's module found in the given @p models array.
Michal Vasko60ea6352020-06-29 13:39:39 +020059 */
Radek Krejci857189e2020-09-01 13:26:36 +020060ly_bool lyb_has_schema_model(const struct lysc_node *sibling, const struct lys_module **models);
Michal Vasko60ea6352020-06-29 13:39:39 +020061
62/**
Michal Vaskod3bb12f2020-12-04 14:33:09 +010063 * @brief Check whether a node to be deleted is the root node, move it if it is.
Michal Vaskob1b5c262020-03-05 14:29:47 +010064 *
Michal Vaskod3bb12f2020-12-04 14:33:09 +010065 * @param[in] root Root sibling.
Michal Vaskob1b5c262020-03-05 14:29:47 +010066 * @param[in] to_del Node to be deleted.
Michal Vaskod3bb12f2020-12-04 14:33:09 +010067 * @param[in] mod If set, it is expected @p tree should point to the first node of @p mod. Otherwise it will simply be
68 * the first top-level sibling.
Michal Vaskob1b5c262020-03-05 14:29:47 +010069 */
Michal Vaskod3bb12f2020-12-04 14:33:09 +010070void lyd_del_move_root(struct lyd_node **root, const struct lyd_node *to_del, const struct lys_module *mod);
Michal Vaskob1b5c262020-03-05 14:29:47 +010071
72/**
Radek Krejcie7b95092019-05-15 11:03:07 +020073 * @brief Get address of a node's child pointer if any.
74 *
Radek Krejcie7b95092019-05-15 11:03:07 +020075 * @param[in] node Node to check.
Michal Vasko9b368d32020-02-14 13:53:31 +010076 * @return Address of the node's child member,
77 * @return NULL if there is no child pointer.
Radek Krejcie7b95092019-05-15 11:03:07 +020078 */
79struct lyd_node **lyd_node_children_p(struct lyd_node *node);
80
81/**
Radek Krejci8678fa42020-08-18 16:07:28 +020082 * @brief Just like ::lys_getnext() but iterates over all data instances of the schema nodes.
Michal Vaskoa6669ba2020-08-06 16:14:26 +020083 *
84 * @param[in] last Last returned data node.
85 * @param[in] sibling Data node sibling to search in.
86 * @param[in,out] slast Schema last node, set to NULL for first call and do not change afterwards.
87 * May not be set if the function is used only for any suitable node existence check (such as the existence
88 * of any choice case data).
89 * @param[in] parent Schema parent of the iterated children nodes.
90 * @param[in] module Schema module of the iterated top-level nodes.
91 * @return Next matching data node,
92 * @return NULL if last data node was already returned.
93 */
94struct lyd_node *lys_getnext_data(const struct lyd_node *last, const struct lyd_node *sibling,
Radek Krejci0f969882020-08-21 16:56:47 +020095 const struct lysc_node **slast, const struct lysc_node *parent,
96 const struct lysc_module *module);
Michal Vaskoa6669ba2020-08-06 16:14:26 +020097
98/**
Michal Vasko9b368d32020-02-14 13:53:31 +010099 * @brief Create a term (leaf/leaf-list) node from a string value.
100 *
101 * Hash is calculated and new node flag is set.
Michal Vasko90932a92020-02-12 14:33:03 +0100102 *
103 * @param[in] schema Schema node of the new data node.
104 * @param[in] value String value to be parsed.
Michal Vaskof03ed032020-03-04 13:31:44 +0100105 * @param[in] value_len Length of @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100106 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
Michal Vasko90932a92020-02-12 14:33:03 +0100107 * @param[in] format Input format of @p value.
Michal Vaskoc8a230d2020-08-14 12:17:10 +0200108 * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix).
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200109 * @param[in] hints [Value hints](@ref lydvalhints) from the parser regarding the value type.
110 * @param[out] incomplete Whether the value needs to be resolved.
Michal Vasko90932a92020-02-12 14:33:03 +0100111 * @param[out] node Created node.
112 * @return LY_SUCCESS on success.
113 * @return LY_EINCOMPLETE in case data tree is needed to finish the validation.
114 * @return LY_ERR value if an error occurred.
115 */
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200116LY_ERR lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, ly_bool *dynamic,
117 LY_PREFIX_FORMAT format, void *prefix_data, uint32_t hints, ly_bool *incomplete, struct lyd_node **node);
Michal Vasko90932a92020-02-12 14:33:03 +0100118
119/**
Michal Vasko9b368d32020-02-14 13:53:31 +0100120 * @brief Create a term (leaf/leaf-list) node from a parsed value by duplicating it.
121 *
122 * Hash is calculated and new node flag is set.
123 *
124 * @param[in] schema Schema node of the new data node.
125 * @param[in] val Parsed value to use.
126 * @param[out] node Created node.
127 * @return LY_SUCCESS on success.
128 * @return LY_ERR value if an error occurred.
129 */
130LY_ERR lyd_create_term2(const struct lysc_node *schema, const struct lyd_value *val, struct lyd_node **node);
131
132/**
133 * @brief Create an inner (container/list/RPC/action/notification) node.
134 *
135 * Hash is calculated and new node flag is set except
136 * for list with keys, when the hash is not calculated!
137 * Also, non-presence container has its default flag set.
Michal Vasko90932a92020-02-12 14:33:03 +0100138 *
139 * @param[in] schema Schema node of the new data node.
140 * @param[out] node Created node.
141 * @return LY_SUCCESS on success.
142 * @return LY_ERR value if an error occurred.
143 */
144LY_ERR lyd_create_inner(const struct lysc_node *schema, struct lyd_node **node);
145
146/**
Michal Vasko9b368d32020-02-14 13:53:31 +0100147 * @brief Create a list with all its keys (cannot be used for key-less list).
148 *
149 * Hash is calculated and new node flag is set.
Michal Vasko90932a92020-02-12 14:33:03 +0100150 *
151 * @param[in] schema Schema node of the new data node.
Michal Vasko004d3152020-06-11 19:59:22 +0200152 * @param[in] predicates Compiled key list predicates.
Michal Vasko90932a92020-02-12 14:33:03 +0100153 * @param[out] node Created node.
154 * @return LY_SUCCESS on success.
155 * @return LY_ERR value if an error occurred.
156 */
Michal Vasko004d3152020-06-11 19:59:22 +0200157LY_ERR lyd_create_list(const struct lysc_node *schema, const struct ly_path_predicate *predicates, struct lyd_node **node);
Michal Vasko90932a92020-02-12 14:33:03 +0100158
159/**
Michal Vasko9b368d32020-02-14 13:53:31 +0100160 * @brief Create an anyxml/anydata node.
161 *
162 * Hash is calculated and flags are properly set based on @p is_valid.
Michal Vasko90932a92020-02-12 14:33:03 +0100163 *
164 * @param[in] schema Schema node of the new data node.
165 * @param[in] value Value of the any node, is directly assigned into the data node.
166 * @param[in] value_type Value type of the value.
167 * @param[out] node Created node.
168 * @return LY_SUCCESS on success.
169 * @return LY_ERR value if an error occurred.
170 */
Michal Vasko9b368d32020-02-14 13:53:31 +0100171LY_ERR lyd_create_any(const struct lysc_node *schema, const void *value, LYD_ANYDATA_VALUETYPE value_type,
Radek Krejci0f969882020-08-21 16:56:47 +0200172 struct lyd_node **node);
Michal Vasko90932a92020-02-12 14:33:03 +0100173
174/**
Michal Vasko52927e22020-03-16 17:26:14 +0100175 * @brief Create an opaque node.
176 *
177 * @param[in] ctx libyang context.
178 * @param[in] name Element name.
179 * @param[in] name_len Length of @p name, must be set correctly.
Michal Vasko52927e22020-03-16 17:26:14 +0100180 * @param[in] prefix Element prefix.
181 * @param[in] pref_len Length of @p prefix, must be set correctly.
Radek Krejci1798aae2020-07-14 13:26:06 +0200182 * @param[in] module_key Mandatory key to reference module, can be namespace or name.
183 * @param[in] module_key_len Length of @p module_key, must be set correctly.
Michal Vasko501af032020-11-11 20:27:44 +0100184 * @param[in] value String value to be parsed.
185 * @param[in] value_len Length of @p value, must be set correctly.
186 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
187 * @param[in] format Input format of @p value and @p ns.
188 * @param[in] val_prefix_data Format-specific prefix data, param is spent (even in case the function fails).
189 * @param[in] hints [Hints](@ref lydhints) from the parser regarding the node/value type.
Michal Vasko52927e22020-03-16 17:26:14 +0100190 * @param[out] node Created node.
191 * @return LY_SUCCESS on success.
192 * @return LY_ERR value if an error occurred.
193 */
Michal Vasko501af032020-11-11 20:27:44 +0100194LY_ERR lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_len, const char *prefix, size_t pref_len,
195 const char *module_key, size_t module_key_len, const char *value, size_t value_len, ly_bool *dynamic,
196 LY_PREFIX_FORMAT format, void *val_prefix_data, uint32_t hints, struct lyd_node **node);
Michal Vasko52927e22020-03-16 17:26:14 +0100197
198/**
Michal Vaskoa6669ba2020-08-06 16:14:26 +0200199 * @brief Check the existence and create any non-existing implicit siblings, recursively for the created nodes.
200 *
201 * @param[in] parent Parent of the potential default values, NULL for top-level siblings.
202 * @param[in,out] first First sibling.
203 * @param[in] sparent Schema parent of the siblings, NULL if schema of @p parent can be used.
204 * @param[in] mod Module of the default values, NULL for nested siblings.
205 * @param[in] node_types Optional set to add nodes with unresolved types into.
206 * @param[in] node_when Optional set to add nodes with "when" conditions into.
207 * @param[in] impl_opts Implicit options (@ref implicitoptions).
208 * @param[in,out] diff Validation diff.
209 * @return LY_ERR value.
210 */
211LY_ERR lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struct lysc_node *sparent,
Radek Krejci0f969882020-08-21 16:56:47 +0200212 const struct lys_module *mod, struct ly_set *node_types, struct ly_set *node_when,
Radek Krejci1deb5be2020-08-26 16:43:36 +0200213 uint32_t impl_opts, struct lyd_node **diff);
Michal Vaskoa6669ba2020-08-06 16:14:26 +0200214
215/**
Michal Vaskob104f112020-07-17 09:54:54 +0200216 * @brief Find the next node, before which to insert the new node.
Michal Vasko90932a92020-02-12 14:33:03 +0100217 *
Michal Vaskob104f112020-07-17 09:54:54 +0200218 * @param[in] first_sibling First sibling of the nodes to consider.
219 * @param[in] new_node Node that will be inserted.
220 * @return Node to insert after.
221 * @return NULL if the new node should be first.
Michal Vasko90932a92020-02-12 14:33:03 +0100222 */
Michal Vaskob104f112020-07-17 09:54:54 +0200223struct lyd_node *lyd_insert_get_next_anchor(const struct lyd_node *first_sibling, const struct lyd_node *new_node);
Michal Vasko90932a92020-02-12 14:33:03 +0100224
225/**
Michal Vaskob104f112020-07-17 09:54:54 +0200226 * @brief Insert a node into parent/siblings. Order and hashes are fully handled.
Michal Vasko90932a92020-02-12 14:33:03 +0100227 *
Michal Vasko9b368d32020-02-14 13:53:31 +0100228 * @param[in] parent Parent to insert into, NULL for top-level sibling.
229 * @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 Vasko90932a92020-02-12 14:33:03 +0100230 * @param[in] node Individual node (without siblings) to insert.
231 */
Michal Vasko9b368d32020-02-14 13:53:31 +0100232void lyd_insert_node(struct lyd_node *parent, struct lyd_node **first_sibling, struct lyd_node *node);
Michal Vasko90932a92020-02-12 14:33:03 +0100233
234/**
Michal Vaskoa5da3292020-08-12 13:10:50 +0200235 * @brief Insert a metadata (last) into a parent
236 *
237 * @param[in] parent Parent of the metadata.
238 * @param[in] meta Metadata (list) to be added into the @p parent.
Michal Vasko871a0252020-11-11 18:35:24 +0100239 * @param[in] clear_dflt Whether to clear dflt flag starting from @p parent, recursively all NP containers.
Michal Vaskoa5da3292020-08-12 13:10:50 +0200240 */
Michal Vasko871a0252020-11-11 18:35:24 +0100241void lyd_insert_meta(struct lyd_node *parent, struct lyd_meta *meta, ly_bool clear_dflt);
Michal Vaskoa5da3292020-08-12 13:10:50 +0200242
243/**
Michal Vasko52927e22020-03-16 17:26:14 +0100244 * @brief Create and insert a metadata (last) into a parent.
Michal Vasko90932a92020-02-12 14:33:03 +0100245 *
Michal Vasko52927e22020-03-16 17:26:14 +0100246 * @param[in] parent Parent of the metadata, can be NULL.
Michal Vasko9f96a052020-03-10 09:41:45 +0100247 * @param[in,out] meta Metadata list to add at its end if @p parent is NULL, returned created attribute.
248 * @param[in] mod Metadata module (with the annotation definition).
Michal Vasko90932a92020-02-12 14:33:03 +0100249 * @param[in] name Attribute name.
Michal Vaskof03ed032020-03-04 13:31:44 +0100250 * @param[in] name_len Length of @p name, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100251 * @param[in] value String value to be parsed.
Michal Vaskof03ed032020-03-04 13:31:44 +0100252 * @param[in] value_len Length of @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100253 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
Michal Vasko90932a92020-02-12 14:33:03 +0100254 * @param[in] format Input format of @p value.
Michal Vaskoc8a230d2020-08-14 12:17:10 +0200255 * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix).
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200256 * @param[in] hints [Value hints](@ref lydvalhints) from the parser regarding the value type.
Michal Vasko871a0252020-11-11 18:35:24 +0100257 * @param[in] clear_dflt Whether to clear dflt flag starting from @p parent, recursively all NP containers.
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200258 * @param[out] incomplete Whether the value needs to be resolved.
Michal Vasko90932a92020-02-12 14:33:03 +0100259 * @return LY_SUCCESS on success.
260 * @return LY_EINCOMPLETE in case data tree is needed to finish the validation.
261 * @return LY_ERR value if an error occurred.
262 */
Michal Vasko9f96a052020-03-10 09:41:45 +0100263LY_ERR lyd_create_meta(struct lyd_node *parent, struct lyd_meta **meta, const struct lys_module *mod, const char *name,
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200264 size_t name_len, const char *value, size_t value_len, ly_bool *dynamic, LY_PREFIX_FORMAT format,
Michal Vasko871a0252020-11-11 18:35:24 +0100265 void *prefix_data, uint32_t hints, ly_bool clear_dlft, ly_bool *incomplete);
Radek Krejci1798aae2020-07-14 13:26:06 +0200266
267/**
Michal Vaskoa5da3292020-08-12 13:10:50 +0200268 * @brief Insert an attribute (last) into a parent
Radek Krejci1798aae2020-07-14 13:26:06 +0200269 *
Michal Vaskoa5da3292020-08-12 13:10:50 +0200270 * @param[in] parent Parent of the attributes.
271 * @param[in] attr Attribute (list) to be added into the @p parent.
Radek Krejci1798aae2020-07-14 13:26:06 +0200272 */
Michal Vaskoa5da3292020-08-12 13:10:50 +0200273void lyd_insert_attr(struct lyd_node *parent, struct lyd_attr *attr);
Michal Vasko90932a92020-02-12 14:33:03 +0100274
275/**
Michal Vasko52927e22020-03-16 17:26:14 +0100276 * @brief Create and insert a generic attribute (last) into a parent.
277 *
278 * @param[in] parent Parent of the attribute, can be NULL.
279 * @param[in,out] attr Attribute list to add at its end if @p parent is NULL, returned created attribute.
280 * @param[in] ctx libyang context.
281 * @param[in] name Attribute name.
282 * @param[in] name_len Length of @p name, must be set correctly.
Michal Vasko52927e22020-03-16 17:26:14 +0100283 * @param[in] prefix Attribute prefix.
284 * @param[in] prefix_len Attribute prefix length.
Radek Krejci1798aae2020-07-14 13:26:06 +0200285 * @param[in] module_key Mandatory key to reference module, can be namespace or name.
286 * @param[in] module_key_len Length of @p module_key, must be set correctly.
Michal Vasko501af032020-11-11 20:27:44 +0100287 * @param[in] value String value to be parsed.
288 * @param[in] value_len Length of @p value, must be set correctly.
289 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
290 * @param[in] format Input format of @p value and @p ns.
291 * @param[in] val_prefix_data Format-specific prefix data, param is spent (even in case the function fails).
292 * @param[in] hints [Hints](@ref lydhints) from the parser regarding the node/value type.
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200293 * @return LY_SUCCESS on success,
294 * @return LY_ERR value on error.
Michal Vasko52927e22020-03-16 17:26:14 +0100295 */
Radek Krejci1798aae2020-07-14 13:26:06 +0200296LY_ERR lyd_create_attr(struct lyd_node *parent, struct lyd_attr **attr, const struct ly_ctx *ctx, const char *name,
Michal Vasko501af032020-11-11 20:27:44 +0100297 size_t name_len, const char *prefix, size_t prefix_len, const char *module_key, size_t module_key_len,
298 const char *value, size_t value_len, ly_bool *dynamic, LY_PREFIX_FORMAT format, void *val_prefix_data, uint32_t hints);
Radek Krejci1798aae2020-07-14 13:26:06 +0200299
300/**
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200301 * @brief Store and canonize the given @p value into @p val according to the schema node type rules.
Radek Krejci38d85362019-09-05 16:26:38 +0200302 *
Michal Vasko8d544252020-03-02 10:19:52 +0100303 * @param[in] ctx libyang context.
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200304 * @param[in,out] val Storage for the value.
305 * @param[in] type Type of the value.
Radek Krejci38d85362019-09-05 16:26:38 +0200306 * @param[in] value String value to be parsed, must not be NULL.
Michal Vaskof03ed032020-03-04 13:31:44 +0100307 * @param[in] value_len Length of the give @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100308 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200309 * @param[in] format Input format of @p value.
Michal Vaskoc8a230d2020-08-14 12:17:10 +0200310 * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix).
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200311 * @param[in] hints [Value hints](@ref lydvalhints) from the parser.
312 * @param[in] ctx_node Context schema node.
313 * @param[out] incomplete Optional, set if the value also needs to be resolved.
314 * @param[in] log_elem_type Elem type for logging.
315 * @param[in] log_elem Elem for logging.
316 * @return LY_SUCCESS on success,
317 * @return LY_ERR value on error.
Radek Krejci38d85362019-09-05 16:26:38 +0200318 */
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200319LY_ERR lyd_value_store(const struct ly_ctx *ctx, struct lyd_value *val, const struct lysc_type *type, const char *value,
320 size_t value_len, ly_bool *dynamic, LY_PREFIX_FORMAT format, void *prefix_data, uint32_t hints,
321 const struct lysc_node *ctx_node, ly_bool *incomplete, enum LY_VLOG_ELEM log_elem_type, const void *log_elem);
322
323/**
324 * @brief Validate previously incompletely stored value.
325 *
326 * @param[in] ctx libyang context.
327 * @param[in] type Schema type of the value (not the stored one, but the original one).
328 * @param[in,out] val Stored value to resolve.
329 * @param[in] ctx_node Context node for the resolution.
330 * @param[in] tree Data tree for the resolution.
331 * @param[in] log_elem_type Elem type for logging.
332 * @param[in] log_elem Elem for logging.
333 * @return LY_SUCCESS on success,
334 * @return LY_ERR value on error.
335 */
336LY_ERR lyd_value_validate_incomplete(const struct ly_ctx *ctx, const struct lysc_type *type, struct lyd_value *val,
337 const struct lyd_node *ctx_node, const struct lyd_node *tree, enum LY_VLOG_ELEM log_elem_type, const void *log_elem);
Radek Krejci38d85362019-09-05 16:26:38 +0200338
Michal Vaskof937cfe2020-08-03 16:07:12 +0200339/* generic function lys_value_validate */
340LY_ERR _lys_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len,
Radek Krejci0f969882020-08-21 16:56:47 +0200341 LY_PREFIX_FORMAT format, void *prefix_data);
Michal Vaskof937cfe2020-08-03 16:07:12 +0200342
Radek Krejci38d85362019-09-05 16:26:38 +0200343/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200344 * @defgroup datahash Data nodes hash manipulation
345 * @ingroup datatree
346 */
347
348/**
Radek Krejci1f05b6a2019-07-18 16:15:06 +0200349 * @brief Generate hash for the node.
350 *
351 * @param[in] node Data node to (re)generate hash value.
352 * @return LY_ERR value.
353 */
354LY_ERR lyd_hash(struct lyd_node *node);
355
356/**
357 * @brief Insert hash of the node into the hash table of its parent.
358 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200359 * @param[in] node Data node which hash will be inserted into the ::lyd_node_inner.children_ht hash table of its parent.
Radek Krejci1f05b6a2019-07-18 16:15:06 +0200360 * @return LY_ERR value.
361 */
362LY_ERR lyd_insert_hash(struct lyd_node *node);
363
364/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200365 * @brief Maintain node's parent's children hash table when unlinking the node.
366 *
367 * When completely freeing data tree, it is expected to free the parent's children hash table first, at once.
368 *
369 * @param[in] node The data node being unlinked from its parent.
370 */
371void lyd_unlink_hash(struct lyd_node *node);
372
373/** @} datahash */
374
Radek Krejci084289f2019-07-09 17:35:30 +0200375/**
Michal Vaskob1b5c262020-03-05 14:29:47 +0100376 * @brief Iterate over implemented modules for functions that accept specific modules or the whole context.
377 *
378 * @param[in] tree Data tree.
Michal Vasko26e80012020-07-08 10:55:46 +0200379 * @param[in] module Selected module, NULL for all.
Michal Vaskob1b5c262020-03-05 14:29:47 +0100380 * @param[in] ctx Context, NULL for selected modules.
381 * @param[in,out] i Iterator, set to 0 on first call.
382 * @param[out] first First sibling of the returned module.
383 * @return Next module.
384 * @return NULL if all modules were traversed.
385 */
Michal Vasko26e80012020-07-08 10:55:46 +0200386const struct lys_module *lyd_mod_next_module(struct lyd_node *tree, const struct lys_module *module,
Radek Krejci0f969882020-08-21 16:56:47 +0200387 const struct ly_ctx *ctx, uint32_t *i, struct lyd_node **first);
Michal Vaskob1b5c262020-03-05 14:29:47 +0100388
389/**
390 * @brief Iterate over modules for functions that want to traverse all the top-level data.
391 *
392 * @param[in,out] next Pointer to the next module data, set to first top-level sibling on first call.
393 * @param[out] first First sibling of the returned module.
394 * @return Next module.
395 * @return NULL if all modules were traversed.
396 */
397const struct lys_module *lyd_data_next_module(struct lyd_node **next, struct lyd_node **first);
398
Michal Vasko9f96a052020-03-10 09:41:45 +0100399/**
400 * @brief Check that a list has all its keys.
401 *
402 * @param[in] node List to check.
Michal Vasko44685da2020-03-17 15:38:06 +0100403 * @return LY_SUCCESS on success.
404 * @return LY_ENOT on a missing key.
Michal Vasko9f96a052020-03-10 09:41:45 +0100405 */
406LY_ERR lyd_parse_check_keys(struct lyd_node *node);
407
Michal Vasko60ea6352020-06-29 13:39:39 +0200408/**
409 * @brief Set data flags for a newly parsed node.
410 *
411 * @param[in] node Node to use.
412 * @param[in] when_check Set of nodes with unresolved when.
413 * @param[in,out] meta Node metadata, may be removed from.
414 * @param[in] options Parse options.
415 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200416void lyd_parse_set_data_flags(struct lyd_node *node, struct ly_set *when_check, struct lyd_meta **meta, uint32_t options);
Michal Vasko60ea6352020-06-29 13:39:39 +0200417
418/**
Michal Vaskod59035b2020-07-08 12:00:06 +0200419 * @brief Append all list key predicates to path.
420 *
421 * @param[in] node Node with keys to print.
422 * @param[in,out] buffer Buffer to print to.
423 * @param[in,out] buflen Current buffer length.
424 * @param[in,out] bufused Current number of characters used in @p buffer.
425 * @param[in] is_static Whether buffer is static or can be reallocated.
426 * @return LY_ERR
427 */
Radek Krejci857189e2020-09-01 13:26:36 +0200428LY_ERR lyd_path_list_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, ly_bool is_static);
Michal Vaskod59035b2020-07-08 12:00:06 +0200429
Michal Vasko6b5cb2a2020-11-11 19:11:21 +0100430/**
431 * @brief Free stored prefix data.
432 *
433 * @param[in] format Format of the prefixes.
434 * @param[in] prefix_data Prefix data to free.
435 */
436void ly_free_prefix_data(LY_PREFIX_FORMAT format, void *prefix_data);
437
438/**
439 * @brief Duplicate prefix data.
440 *
441 * @param[in] ctx libyang context.
442 * @param[in] format Format of the prefixes in the value.
443 * @param[in] prefix_data Prefix data to duplicate.
444 * @param[out] prefix_data_p Duplicated prefix data.
445 * @return LY_ERR value.
446 */
447LY_ERR ly_dup_prefix_data(const struct ly_ctx *ctx, LY_PREFIX_FORMAT format, const void *prefix_data, void **prefix_data_p);
448
449/**
450 * @brief Store used prefixes in a value.
451 *
452 * @param[in] ctx libyang context.
453 * @param[in] value Value string to be parsed.
454 * @param[in] value_len Length of the @p value string.
455 * @param[in] format Format of the prefixes in the value.
456 * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix).
457 * @param[out] format_p Resulting format of the prefixes.
458 * @param[out] prefix_data_p Resulting prefix data for the value in format @p format_p.
459 * @return LY_ERR value.
460 */
461LY_ERR ly_store_prefix_data(const struct ly_ctx *ctx, const char *value, size_t value_len, LY_PREFIX_FORMAT format,
462 void *prefix_data, LY_PREFIX_FORMAT *format_p, void **prefix_data_p);
463
Michal Vasko7ed1fcb2020-12-03 14:15:22 +0100464/**
465 * @brief Get string name of the format.
466 *
467 * @param[in] format Format whose name to get.
468 * @return Format string name.
469 */
470const char *ly_format2str(LY_PREFIX_FORMAT format);
471
Radek Krejcie7b95092019-05-15 11:03:07 +0200472#endif /* LY_TREE_DATA_INTERNAL_H_ */