blob: 402f732b8194b76c170cc1d9aaf733073ceaf7a4 [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 Hash schema sibling to be used for LYB data.
38 *
39 * @param[in] sibling Sibling to hash.
40 * @param[in] collision_id Collision ID of the hash to generate.
41 * @return Generated hash.
42 */
43LYB_HASH lyb_hash(struct lysc_node *sibling, uint8_t collision_id);
44
45/**
Radek Krejci857189e2020-09-01 13:26:36 +020046 * @brief Check whether a sibling's module is in a module array.
Michal Vasko60ea6352020-06-29 13:39:39 +020047 *
48 * @param[in] sibling Sibling to check.
49 * @param[in] models Modules in a sized array.
50 * @return non-zero if the module was found,
Radek Krejci857189e2020-09-01 13:26:36 +020051 * @return Boolean value whether @p sibling's module found in the given @p models array.
Michal Vasko60ea6352020-06-29 13:39:39 +020052 */
Radek Krejci857189e2020-09-01 13:26:36 +020053ly_bool lyb_has_schema_model(const struct lysc_node *sibling, const struct lys_module **models);
Michal Vasko60ea6352020-06-29 13:39:39 +020054
55/**
Michal Vaskod3bb12f2020-12-04 14:33:09 +010056 * @brief Check whether a node to be deleted is the root node, move it if it is.
Michal Vaskob1b5c262020-03-05 14:29:47 +010057 *
Michal Vaskod3bb12f2020-12-04 14:33:09 +010058 * @param[in] root Root sibling.
Michal Vaskob1b5c262020-03-05 14:29:47 +010059 * @param[in] to_del Node to be deleted.
Michal Vaskod3bb12f2020-12-04 14:33:09 +010060 * @param[in] mod If set, it is expected @p tree should point to the first node of @p mod. Otherwise it will simply be
61 * the first top-level sibling.
Michal Vaskob1b5c262020-03-05 14:29:47 +010062 */
Michal Vaskod3bb12f2020-12-04 14:33:09 +010063void 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 +010064
65/**
Radek Krejcie7b95092019-05-15 11:03:07 +020066 * @brief Get address of a node's child pointer if any.
67 *
Radek Krejcie7b95092019-05-15 11:03:07 +020068 * @param[in] node Node to check.
Michal Vasko9b368d32020-02-14 13:53:31 +010069 * @return Address of the node's child member,
70 * @return NULL if there is no child pointer.
Radek Krejcie7b95092019-05-15 11:03:07 +020071 */
Michal Vaskoe0665742021-02-11 11:08:44 +010072struct lyd_node **lyd_node_child_p(struct lyd_node *node);
Radek Krejcie7b95092019-05-15 11:03:07 +020073
74/**
Radek Krejci8678fa42020-08-18 16:07:28 +020075 * @brief Just like ::lys_getnext() but iterates over all data instances of the schema nodes.
Michal Vaskoa6669ba2020-08-06 16:14:26 +020076 *
77 * @param[in] last Last returned data node.
78 * @param[in] sibling Data node sibling to search in.
79 * @param[in,out] slast Schema last node, set to NULL for first call and do not change afterwards.
80 * May not be set if the function is used only for any suitable node existence check (such as the existence
81 * of any choice case data).
82 * @param[in] parent Schema parent of the iterated children nodes.
83 * @param[in] module Schema module of the iterated top-level nodes.
84 * @return Next matching data node,
85 * @return NULL if last data node was already returned.
86 */
87struct lyd_node *lys_getnext_data(const struct lyd_node *last, const struct lyd_node *sibling,
Radek Krejci0f969882020-08-21 16:56:47 +020088 const struct lysc_node **slast, const struct lysc_node *parent,
89 const struct lysc_module *module);
Michal Vaskoa6669ba2020-08-06 16:14:26 +020090
91/**
Michal Vasko9b368d32020-02-14 13:53:31 +010092 * @brief Create a term (leaf/leaf-list) node from a string value.
93 *
94 * Hash is calculated and new node flag is set.
Michal Vasko90932a92020-02-12 14:33:03 +010095 *
96 * @param[in] schema Schema node of the new data node.
97 * @param[in] value String value to be parsed.
Michal Vaskof03ed032020-03-04 13:31:44 +010098 * @param[in] value_len Length of @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +010099 * @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 +0100100 * @param[in] format Input format of @p value.
Michal Vaskoc8a230d2020-08-14 12:17:10 +0200101 * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix).
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200102 * @param[in] hints [Value hints](@ref lydvalhints) from the parser regarding the value type.
103 * @param[out] incomplete Whether the value needs to be resolved.
Michal Vasko90932a92020-02-12 14:33:03 +0100104 * @param[out] node Created node.
105 * @return LY_SUCCESS on success.
106 * @return LY_EINCOMPLETE in case data tree is needed to finish the validation.
107 * @return LY_ERR value if an error occurred.
108 */
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200109LY_ERR lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, ly_bool *dynamic,
110 LY_PREFIX_FORMAT format, void *prefix_data, uint32_t hints, ly_bool *incomplete, struct lyd_node **node);
Michal Vasko90932a92020-02-12 14:33:03 +0100111
112/**
Michal Vasko9b368d32020-02-14 13:53:31 +0100113 * @brief Create a term (leaf/leaf-list) node from a parsed value by duplicating it.
114 *
115 * Hash is calculated and new node flag is set.
116 *
117 * @param[in] schema Schema node of the new data node.
118 * @param[in] val Parsed value to use.
119 * @param[out] node Created node.
120 * @return LY_SUCCESS on success.
121 * @return LY_ERR value if an error occurred.
122 */
123LY_ERR lyd_create_term2(const struct lysc_node *schema, const struct lyd_value *val, struct lyd_node **node);
124
125/**
126 * @brief Create an inner (container/list/RPC/action/notification) node.
127 *
128 * Hash is calculated and new node flag is set except
129 * for list with keys, when the hash is not calculated!
130 * Also, non-presence container has its default flag set.
Michal Vasko90932a92020-02-12 14:33:03 +0100131 *
132 * @param[in] schema Schema node of the new data node.
133 * @param[out] node Created node.
134 * @return LY_SUCCESS on success.
135 * @return LY_ERR value if an error occurred.
136 */
137LY_ERR lyd_create_inner(const struct lysc_node *schema, struct lyd_node **node);
138
139/**
Michal Vasko9b368d32020-02-14 13:53:31 +0100140 * @brief Create a list with all its keys (cannot be used for key-less list).
141 *
142 * Hash is calculated and new node flag is set.
Michal Vasko90932a92020-02-12 14:33:03 +0100143 *
144 * @param[in] schema Schema node of the new data node.
Michal Vasko004d3152020-06-11 19:59:22 +0200145 * @param[in] predicates Compiled key list predicates.
Michal Vasko90932a92020-02-12 14:33:03 +0100146 * @param[out] node Created node.
147 * @return LY_SUCCESS on success.
148 * @return LY_ERR value if an error occurred.
149 */
Michal Vasko004d3152020-06-11 19:59:22 +0200150LY_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 +0100151
152/**
Michal Vasko9b368d32020-02-14 13:53:31 +0100153 * @brief Create an anyxml/anydata node.
154 *
155 * Hash is calculated and flags are properly set based on @p is_valid.
Michal Vasko90932a92020-02-12 14:33:03 +0100156 *
157 * @param[in] schema Schema node of the new data node.
Michal Vasko366a4a12020-12-04 16:23:57 +0100158 * @param[in] value Value of the any node.
Michal Vasko90932a92020-02-12 14:33:03 +0100159 * @param[in] value_type Value type of the value.
Michal Vasko366a4a12020-12-04 16:23:57 +0100160 * @param[in] use_value Whether to directly assign (eat) the value or duplicate it.
Michal Vasko90932a92020-02-12 14:33:03 +0100161 * @param[out] node Created node.
162 * @return LY_SUCCESS on success.
163 * @return LY_ERR value if an error occurred.
164 */
Michal Vasko9b368d32020-02-14 13:53:31 +0100165LY_ERR lyd_create_any(const struct lysc_node *schema, const void *value, LYD_ANYDATA_VALUETYPE value_type,
Michal Vasko366a4a12020-12-04 16:23:57 +0100166 ly_bool use_value, struct lyd_node **node);
Michal Vasko90932a92020-02-12 14:33:03 +0100167
168/**
Michal Vasko52927e22020-03-16 17:26:14 +0100169 * @brief Create an opaque node.
170 *
171 * @param[in] ctx libyang context.
172 * @param[in] name Element name.
173 * @param[in] name_len Length of @p name, must be set correctly.
Michal Vasko52927e22020-03-16 17:26:14 +0100174 * @param[in] prefix Element prefix.
175 * @param[in] pref_len Length of @p prefix, must be set correctly.
Radek Krejci1798aae2020-07-14 13:26:06 +0200176 * @param[in] module_key Mandatory key to reference module, can be namespace or name.
177 * @param[in] module_key_len Length of @p module_key, must be set correctly.
Michal Vasko501af032020-11-11 20:27:44 +0100178 * @param[in] value String value to be parsed.
179 * @param[in] value_len Length of @p value, must be set correctly.
180 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
181 * @param[in] format Input format of @p value and @p ns.
Radek Krejciec9ad602021-01-04 10:46:30 +0100182 * @param[in] val_prefix_data Format-specific prefix data, param is spent (even in case the function fails):
183 * LY_PREF_SCHEMA - const struct lysp_module * (module used for resolving prefixes from imports)
184 * LY_PREF_SCHEMA_RESOLVED - struct lyd_value_prefix * (sized array of pairs: prefix - module)
185 * LY_PREF_XML - const struct ly_set * (set with defined namespaces stored as ::lyxml_ns)
186 * LY_PREF_JSON - NULL
Michal Vasko501af032020-11-11 20:27:44 +0100187 * @param[in] hints [Hints](@ref lydhints) from the parser regarding the node/value type.
Michal Vasko52927e22020-03-16 17:26:14 +0100188 * @param[out] node Created node.
189 * @return LY_SUCCESS on success.
190 * @return LY_ERR value if an error occurred.
191 */
Michal Vasko501af032020-11-11 20:27:44 +0100192LY_ERR lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_len, const char *prefix, size_t pref_len,
193 const char *module_key, size_t module_key_len, const char *value, size_t value_len, ly_bool *dynamic,
194 LY_PREFIX_FORMAT format, void *val_prefix_data, uint32_t hints, struct lyd_node **node);
Michal Vasko52927e22020-03-16 17:26:14 +0100195
196/**
Michal Vaskoa6669ba2020-08-06 16:14:26 +0200197 * @brief Check the existence and create any non-existing implicit siblings, recursively for the created nodes.
198 *
199 * @param[in] parent Parent of the potential default values, NULL for top-level siblings.
200 * @param[in,out] first First sibling.
201 * @param[in] sparent Schema parent of the siblings, NULL if schema of @p parent can be used.
202 * @param[in] mod Module of the default values, NULL for nested siblings.
Michal Vaskoa6669ba2020-08-06 16:14:26 +0200203 * @param[in] node_when Optional set to add nodes with "when" conditions into.
Michal Vaskoc43c8ab2021-03-05 13:32:44 +0100204 * @param[in] node_types Optional set to add nodes with unresolved types into.
Michal Vaskoa6669ba2020-08-06 16:14:26 +0200205 * @param[in] impl_opts Implicit options (@ref implicitoptions).
206 * @param[in,out] diff Validation diff.
207 * @return LY_ERR value.
208 */
209LY_ERR lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struct lysc_node *sparent,
Michal Vaskoc43c8ab2021-03-05 13:32:44 +0100210 const struct lys_module *mod, struct ly_set *node_when, struct ly_set *node_types,
Radek Krejci1deb5be2020-08-26 16:43:36 +0200211 uint32_t impl_opts, struct lyd_node **diff);
Michal Vaskoa6669ba2020-08-06 16:14:26 +0200212
213/**
Michal Vaskob104f112020-07-17 09:54:54 +0200214 * @brief Find the next node, before which to insert the new node.
Michal Vasko90932a92020-02-12 14:33:03 +0100215 *
Michal Vaskob104f112020-07-17 09:54:54 +0200216 * @param[in] first_sibling First sibling of the nodes to consider.
217 * @param[in] new_node Node that will be inserted.
218 * @return Node to insert after.
219 * @return NULL if the new node should be first.
Michal Vasko90932a92020-02-12 14:33:03 +0100220 */
Michal Vaskob104f112020-07-17 09:54:54 +0200221struct 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 +0100222
223/**
Michal Vaskob104f112020-07-17 09:54:54 +0200224 * @brief Insert a node into parent/siblings. Order and hashes are fully handled.
Michal Vasko90932a92020-02-12 14:33:03 +0100225 *
Michal Vasko9b368d32020-02-14 13:53:31 +0100226 * @param[in] parent Parent to insert into, NULL for top-level sibling.
227 * @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 +0100228 * @param[in] node Individual node (without siblings) to insert.
229 */
Michal Vasko9b368d32020-02-14 13:53:31 +0100230void lyd_insert_node(struct lyd_node *parent, struct lyd_node **first_sibling, struct lyd_node *node);
Michal Vasko90932a92020-02-12 14:33:03 +0100231
232/**
Michal Vaskoa5da3292020-08-12 13:10:50 +0200233 * @brief Insert a metadata (last) into a parent
234 *
235 * @param[in] parent Parent of the metadata.
236 * @param[in] meta Metadata (list) to be added into the @p parent.
Michal Vasko871a0252020-11-11 18:35:24 +0100237 * @param[in] clear_dflt Whether to clear dflt flag starting from @p parent, recursively all NP containers.
Michal Vaskoa5da3292020-08-12 13:10:50 +0200238 */
Michal Vasko871a0252020-11-11 18:35:24 +0100239void lyd_insert_meta(struct lyd_node *parent, struct lyd_meta *meta, ly_bool clear_dflt);
Michal Vaskoa5da3292020-08-12 13:10:50 +0200240
241/**
Michal Vasko52927e22020-03-16 17:26:14 +0100242 * @brief Create and insert a metadata (last) into a parent.
Michal Vasko90932a92020-02-12 14:33:03 +0100243 *
Michal Vasko52927e22020-03-16 17:26:14 +0100244 * @param[in] parent Parent of the metadata, can be NULL.
Michal Vasko9f96a052020-03-10 09:41:45 +0100245 * @param[in,out] meta Metadata list to add at its end if @p parent is NULL, returned created attribute.
246 * @param[in] mod Metadata module (with the annotation definition).
Michal Vasko90932a92020-02-12 14:33:03 +0100247 * @param[in] name Attribute name.
Michal Vaskof03ed032020-03-04 13:31:44 +0100248 * @param[in] name_len Length of @p name, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100249 * @param[in] value String value to be parsed.
Michal Vaskof03ed032020-03-04 13:31:44 +0100250 * @param[in] value_len Length of @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100251 * @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 +0100252 * @param[in] format Input format of @p value.
Michal Vaskoc8a230d2020-08-14 12:17:10 +0200253 * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix).
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200254 * @param[in] hints [Value hints](@ref lydvalhints) from the parser regarding the value type.
Michal Vasko871a0252020-11-11 18:35:24 +0100255 * @param[in] clear_dflt Whether to clear dflt flag starting from @p parent, recursively all NP containers.
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200256 * @param[out] incomplete Whether the value needs to be resolved.
Michal Vasko90932a92020-02-12 14:33:03 +0100257 * @return LY_SUCCESS on success.
258 * @return LY_EINCOMPLETE in case data tree is needed to finish the validation.
259 * @return LY_ERR value if an error occurred.
260 */
Michal Vasko9f96a052020-03-10 09:41:45 +0100261LY_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 +0200262 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 +0100263 void *prefix_data, uint32_t hints, ly_bool clear_dlft, ly_bool *incomplete);
Radek Krejci1798aae2020-07-14 13:26:06 +0200264
265/**
Michal Vaskoa5da3292020-08-12 13:10:50 +0200266 * @brief Insert an attribute (last) into a parent
Radek Krejci1798aae2020-07-14 13:26:06 +0200267 *
Michal Vaskoa5da3292020-08-12 13:10:50 +0200268 * @param[in] parent Parent of the attributes.
269 * @param[in] attr Attribute (list) to be added into the @p parent.
Radek Krejci1798aae2020-07-14 13:26:06 +0200270 */
Michal Vaskoa5da3292020-08-12 13:10:50 +0200271void lyd_insert_attr(struct lyd_node *parent, struct lyd_attr *attr);
Michal Vasko90932a92020-02-12 14:33:03 +0100272
273/**
Michal Vasko52927e22020-03-16 17:26:14 +0100274 * @brief Create and insert a generic attribute (last) into a parent.
275 *
276 * @param[in] parent Parent of the attribute, can be NULL.
277 * @param[in,out] attr Attribute list to add at its end if @p parent is NULL, returned created attribute.
278 * @param[in] ctx libyang context.
279 * @param[in] name Attribute name.
280 * @param[in] name_len Length of @p name, must be set correctly.
Michal Vasko52927e22020-03-16 17:26:14 +0100281 * @param[in] prefix Attribute prefix.
282 * @param[in] prefix_len Attribute prefix length.
Radek Krejci1798aae2020-07-14 13:26:06 +0200283 * @param[in] module_key Mandatory key to reference module, can be namespace or name.
284 * @param[in] module_key_len Length of @p module_key, must be set correctly.
Michal Vasko501af032020-11-11 20:27:44 +0100285 * @param[in] value String value to be parsed.
286 * @param[in] value_len Length of @p value, must be set correctly.
287 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
288 * @param[in] format Input format of @p value and @p ns.
289 * @param[in] val_prefix_data Format-specific prefix data, param is spent (even in case the function fails).
290 * @param[in] hints [Hints](@ref lydhints) from the parser regarding the node/value type.
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200291 * @return LY_SUCCESS on success,
292 * @return LY_ERR value on error.
Michal Vasko52927e22020-03-16 17:26:14 +0100293 */
Radek Krejci1798aae2020-07-14 13:26:06 +0200294LY_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 +0100295 size_t name_len, const char *prefix, size_t prefix_len, const char *module_key, size_t module_key_len,
296 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 +0200297
298/**
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200299 * @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 +0200300 *
Michal Vasko8d544252020-03-02 10:19:52 +0100301 * @param[in] ctx libyang context.
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200302 * @param[in,out] val Storage for the value.
303 * @param[in] type Type of the value.
Radek Krejci38d85362019-09-05 16:26:38 +0200304 * @param[in] value String value to be parsed, must not be NULL.
Michal Vaskof03ed032020-03-04 13:31:44 +0100305 * @param[in] value_len Length of the give @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100306 * @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 +0200307 * @param[in] format Input format of @p value.
Michal Vaskoc8a230d2020-08-14 12:17:10 +0200308 * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix).
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200309 * @param[in] hints [Value hints](@ref lydvalhints) from the parser.
310 * @param[in] ctx_node Context schema node.
311 * @param[out] incomplete Optional, set if the value also needs to be resolved.
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200312 * @return LY_SUCCESS on success,
313 * @return LY_ERR value on error.
Radek Krejci38d85362019-09-05 16:26:38 +0200314 */
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200315LY_ERR lyd_value_store(const struct ly_ctx *ctx, struct lyd_value *val, const struct lysc_type *type, const char *value,
316 size_t value_len, ly_bool *dynamic, LY_PREFIX_FORMAT format, void *prefix_data, uint32_t hints,
Radek Krejci2efc45b2020-12-22 16:25:44 +0100317 const struct lysc_node *ctx_node, ly_bool *incomplete);
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200318
319/**
320 * @brief Validate previously incompletely stored value.
321 *
322 * @param[in] ctx libyang context.
323 * @param[in] type Schema type of the value (not the stored one, but the original one).
324 * @param[in,out] val Stored value to resolve.
325 * @param[in] ctx_node Context node for the resolution.
326 * @param[in] tree Data tree for the resolution.
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200327 * @return LY_SUCCESS on success,
328 * @return LY_ERR value on error.
329 */
330LY_ERR lyd_value_validate_incomplete(const struct ly_ctx *ctx, const struct lysc_type *type, struct lyd_value *val,
Radek Krejci2efc45b2020-12-22 16:25:44 +0100331 const struct lyd_node *ctx_node, const struct lyd_node *tree);
Radek Krejci38d85362019-09-05 16:26:38 +0200332
Michal Vaskof937cfe2020-08-03 16:07:12 +0200333/* generic function lys_value_validate */
334LY_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 +0200335 LY_PREFIX_FORMAT format, void *prefix_data);
Michal Vaskof937cfe2020-08-03 16:07:12 +0200336
Radek Krejci38d85362019-09-05 16:26:38 +0200337/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200338 * @defgroup datahash Data nodes hash manipulation
339 * @ingroup datatree
340 */
341
342/**
Radek Krejci1f05b6a2019-07-18 16:15:06 +0200343 * @brief Generate hash for the node.
344 *
345 * @param[in] node Data node to (re)generate hash value.
346 * @return LY_ERR value.
347 */
348LY_ERR lyd_hash(struct lyd_node *node);
349
350/**
351 * @brief Insert hash of the node into the hash table of its parent.
352 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200353 * @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 +0200354 * @return LY_ERR value.
355 */
356LY_ERR lyd_insert_hash(struct lyd_node *node);
357
358/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200359 * @brief Maintain node's parent's children hash table when unlinking the node.
360 *
361 * When completely freeing data tree, it is expected to free the parent's children hash table first, at once.
362 *
363 * @param[in] node The data node being unlinked from its parent.
364 */
365void lyd_unlink_hash(struct lyd_node *node);
366
367/** @} datahash */
368
Radek Krejci084289f2019-07-09 17:35:30 +0200369/**
Michal Vaskob1b5c262020-03-05 14:29:47 +0100370 * @brief Iterate over implemented modules for functions that accept specific modules or the whole context.
371 *
372 * @param[in] tree Data tree.
Michal Vasko26e80012020-07-08 10:55:46 +0200373 * @param[in] module Selected module, NULL for all.
Michal Vaskob1b5c262020-03-05 14:29:47 +0100374 * @param[in] ctx Context, NULL for selected modules.
375 * @param[in,out] i Iterator, set to 0 on first call.
376 * @param[out] first First sibling of the returned module.
377 * @return Next module.
378 * @return NULL if all modules were traversed.
379 */
Michal Vasko26e80012020-07-08 10:55:46 +0200380const struct lys_module *lyd_mod_next_module(struct lyd_node *tree, const struct lys_module *module,
Radek Krejci0f969882020-08-21 16:56:47 +0200381 const struct ly_ctx *ctx, uint32_t *i, struct lyd_node **first);
Michal Vaskob1b5c262020-03-05 14:29:47 +0100382
383/**
384 * @brief Iterate over modules for functions that want to traverse all the top-level data.
385 *
386 * @param[in,out] next Pointer to the next module data, set to first top-level sibling on first call.
387 * @param[out] first First sibling of the returned module.
388 * @return Next module.
389 * @return NULL if all modules were traversed.
390 */
391const struct lys_module *lyd_data_next_module(struct lyd_node **next, struct lyd_node **first);
392
Michal Vasko9f96a052020-03-10 09:41:45 +0100393/**
394 * @brief Check that a list has all its keys.
395 *
396 * @param[in] node List to check.
Michal Vasko44685da2020-03-17 15:38:06 +0100397 * @return LY_SUCCESS on success.
398 * @return LY_ENOT on a missing key.
Michal Vasko9f96a052020-03-10 09:41:45 +0100399 */
400LY_ERR lyd_parse_check_keys(struct lyd_node *node);
401
Michal Vasko60ea6352020-06-29 13:39:39 +0200402/**
403 * @brief Set data flags for a newly parsed node.
404 *
405 * @param[in] node Node to use.
406 * @param[in] when_check Set of nodes with unresolved when.
407 * @param[in,out] meta Node metadata, may be removed from.
408 * @param[in] options Parse options.
409 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200410void 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 +0200411
412/**
Michal Vaskod59035b2020-07-08 12:00:06 +0200413 * @brief Append all list key predicates to path.
414 *
415 * @param[in] node Node with keys to print.
416 * @param[in,out] buffer Buffer to print to.
417 * @param[in,out] buflen Current buffer length.
418 * @param[in,out] bufused Current number of characters used in @p buffer.
419 * @param[in] is_static Whether buffer is static or can be reallocated.
420 * @return LY_ERR
421 */
Radek Krejci857189e2020-09-01 13:26:36 +0200422LY_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 +0200423
Michal Vasko6b5cb2a2020-11-11 19:11:21 +0100424/**
425 * @brief Free stored prefix data.
426 *
427 * @param[in] format Format of the prefixes.
Radek Krejciec9ad602021-01-04 10:46:30 +0100428 * @param[in] prefix_data Format-specific data to free:
429 * LY_PREF_SCHEMA - const struct lysp_module * (module used for resolving prefixes from imports)
430 * LY_PREF_SCHEMA_RESOLVED - struct lyd_value_prefix * (sized array of pairs: prefix - module)
431 * LY_PREF_XML - const struct ly_set * (set with defined namespaces stored as ::lyxml_ns)
432 * LY_PREF_JSON - NULL
Michal Vasko6b5cb2a2020-11-11 19:11:21 +0100433 */
434void ly_free_prefix_data(LY_PREFIX_FORMAT format, void *prefix_data);
435
436/**
437 * @brief Duplicate prefix data.
438 *
439 * @param[in] ctx libyang context.
440 * @param[in] format Format of the prefixes in the value.
441 * @param[in] prefix_data Prefix data to duplicate.
442 * @param[out] prefix_data_p Duplicated prefix data.
443 * @return LY_ERR value.
444 */
445LY_ERR ly_dup_prefix_data(const struct ly_ctx *ctx, LY_PREFIX_FORMAT format, const void *prefix_data, void **prefix_data_p);
446
447/**
Michal Vaskofc2cd072021-02-24 13:17:17 +0100448 * @brief Store used prefixes in a string.
449 *
450 * If @p prefix_data_p are non-NULL, they are treated as valid according to the @p format_p and new possible
451 * prefixes are simply added. This way it is possible to store prefix data for several strings together.
Michal Vasko6b5cb2a2020-11-11 19:11:21 +0100452 *
453 * @param[in] ctx libyang context.
454 * @param[in] value Value string to be parsed.
455 * @param[in] value_len Length of the @p value string.
456 * @param[in] format Format of the prefixes in the value.
457 * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix).
Michal Vaskofc2cd072021-02-24 13:17:17 +0100458 * @param[in,out] format_p Resulting format of the prefixes.
459 * @param[in,out] prefix_data_p Resulting prefix data for the value in format @p format_p.
Michal Vasko6b5cb2a2020-11-11 19:11:21 +0100460 * @return LY_ERR value.
461 */
462LY_ERR ly_store_prefix_data(const struct ly_ctx *ctx, const char *value, size_t value_len, LY_PREFIX_FORMAT format,
Radek Krejcid64d6462021-03-16 15:58:00 +0100463 const void *prefix_data, LY_PREFIX_FORMAT *format_p, void **prefix_data_p);
Michal Vasko6b5cb2a2020-11-11 19:11:21 +0100464
Michal Vasko7ed1fcb2020-12-03 14:15:22 +0100465/**
466 * @brief Get string name of the format.
467 *
468 * @param[in] format Format whose name to get.
469 * @return Format string name.
470 */
471const char *ly_format2str(LY_PREFIX_FORMAT format);
472
Radek Krejcie7b95092019-05-15 11:03:07 +0200473#endif /* LY_TREE_DATA_INTERNAL_H_ */