blob: 980af5ed349b5bf47df8020d973984a8ba0f6613 [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
Michal Vasko60ea6352020-06-29 13:39:39 +020018#include "lyb.h"
Radek Krejciaca74032019-06-04 08:53:06 +020019#include "plugins_types.h"
Michal Vasko60ea6352020-06-29 13:39:39 +020020#include "set.h"
21#include "tree_data.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020022
Michal Vasko52927e22020-03-16 17:26:14 +010023#include <stddef.h>
24
Michal Vasko004d3152020-06-11 19:59:22 +020025struct ly_path_predicate;
26
Radek Krejcie7b95092019-05-15 11:03:07 +020027/**
Michal Vasko60ea6352020-06-29 13:39:39 +020028 * @brief Internal data parser flags.
29 */
30#define LYD_INTOPT_RPC 0x01 /**< RPC/action invocation is being parsed */
31#define LYD_INTOPT_NOTIF 0x02 /**< notification is being parsed */
32#define LYD_INTOPT_REPLY 0x04 /**< RPC/action reply is being parsed */
33
34/**
35 * @brief Hash schema sibling to be used for LYB data.
36 *
37 * @param[in] sibling Sibling to hash.
38 * @param[in] collision_id Collision ID of the hash to generate.
39 * @return Generated hash.
40 */
41LYB_HASH lyb_hash(struct lysc_node *sibling, uint8_t collision_id);
42
43/**
44 * @brief Check whether a sibling module is in a module array.
45 *
46 * @param[in] sibling Sibling to check.
47 * @param[in] models Modules in a sized array.
48 * @return non-zero if the module was found,
49 * @return 0 if not found.
50 */
51int lyb_has_schema_model(const struct lysc_node *sibling, const struct lys_module **models);
52
53/**
Michal Vaskob1b5c262020-03-05 14:29:47 +010054 * @brief Check whether a node to be deleted is the first top-level sibling.
55 *
56 * @param[in] first First sibling.
57 * @param[in] to_del Node to be deleted.
58 */
59#define LYD_DEL_IS_ROOT(first, to_del) (((first) == (to_del)) && !(first)->parent && !(first)->prev->next)
60
61/**
Michal Vasko5bfd4be2020-06-23 13:26:19 +020062 * @brief Shorthand for getting data children without its keys.
63 *
64 * @param[in] node Node, whose children to traverse.
65 * @return Node children, skipping any keys of a list.
66 */
67#define LYD_CHILD(node) lyd_node_children(node, LYD_CHILDREN_SKIP_KEYS)
68
69/**
Radek Krejcie7b95092019-05-15 11:03:07 +020070 * @brief Get address of a node's child pointer if any.
71 *
Radek Krejcie7b95092019-05-15 11:03:07 +020072 * @param[in] node Node to check.
Michal Vasko9b368d32020-02-14 13:53:31 +010073 * @return Address of the node's child member,
74 * @return NULL if there is no child pointer.
Radek Krejcie7b95092019-05-15 11:03:07 +020075 */
76struct lyd_node **lyd_node_children_p(struct lyd_node *node);
77
78/**
Michal Vasko9b368d32020-02-14 13:53:31 +010079 * @brief Create a term (leaf/leaf-list) node from a string value.
80 *
81 * Hash is calculated and new node flag is set.
Michal Vasko90932a92020-02-12 14:33:03 +010082 *
83 * @param[in] schema Schema node of the new data node.
84 * @param[in] value String value to be parsed.
Michal Vaskof03ed032020-03-04 13:31:44 +010085 * @param[in] value_len Length of @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +010086 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
87 * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string.
88 * @param[in] prefix_data User data for @p get_prefix.
89 * @param[in] format Input format of @p value.
90 * @param[out] node Created node.
91 * @return LY_SUCCESS on success.
92 * @return LY_EINCOMPLETE in case data tree is needed to finish the validation.
93 * @return LY_ERR value if an error occurred.
94 */
95LY_ERR lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, int *dynamic,
96 ly_clb_resolve_prefix get_prefix, void *prefix_data, LYD_FORMAT format, struct lyd_node **node);
97
98/**
Michal Vasko9b368d32020-02-14 13:53:31 +010099 * @brief Create a term (leaf/leaf-list) node from a parsed value by duplicating it.
100 *
101 * Hash is calculated and new node flag is set.
102 *
103 * @param[in] schema Schema node of the new data node.
104 * @param[in] val Parsed value to use.
105 * @param[out] node Created node.
106 * @return LY_SUCCESS on success.
107 * @return LY_ERR value if an error occurred.
108 */
109LY_ERR lyd_create_term2(const struct lysc_node *schema, const struct lyd_value *val, struct lyd_node **node);
110
111/**
112 * @brief Create an inner (container/list/RPC/action/notification) node.
113 *
114 * Hash is calculated and new node flag is set except
115 * for list with keys, when the hash is not calculated!
116 * Also, non-presence container has its default flag set.
Michal Vasko90932a92020-02-12 14:33:03 +0100117 *
118 * @param[in] schema Schema node of the new data node.
119 * @param[out] node Created node.
120 * @return LY_SUCCESS on success.
121 * @return LY_ERR value if an error occurred.
122 */
123LY_ERR lyd_create_inner(const struct lysc_node *schema, struct lyd_node **node);
124
125/**
Michal Vasko9b368d32020-02-14 13:53:31 +0100126 * @brief Create a list with all its keys (cannot be used for key-less list).
127 *
128 * Hash is calculated and new node flag is set.
Michal Vasko90932a92020-02-12 14:33:03 +0100129 *
130 * @param[in] schema Schema node of the new data node.
Michal Vasko004d3152020-06-11 19:59:22 +0200131 * @param[in] predicates Compiled key list predicates.
Michal Vasko90932a92020-02-12 14:33:03 +0100132 * @param[out] node Created node.
133 * @return LY_SUCCESS on success.
134 * @return LY_ERR value if an error occurred.
135 */
Michal Vasko004d3152020-06-11 19:59:22 +0200136LY_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 +0100137
138/**
Michal Vasko9b368d32020-02-14 13:53:31 +0100139 * @brief Create an anyxml/anydata node.
140 *
141 * Hash is calculated and flags are properly set based on @p is_valid.
Michal Vasko90932a92020-02-12 14:33:03 +0100142 *
143 * @param[in] schema Schema node of the new data node.
144 * @param[in] value Value of the any node, is directly assigned into the data node.
145 * @param[in] value_type Value type of the value.
146 * @param[out] node Created node.
147 * @return LY_SUCCESS on success.
148 * @return LY_ERR value if an error occurred.
149 */
Michal Vasko9b368d32020-02-14 13:53:31 +0100150LY_ERR lyd_create_any(const struct lysc_node *schema, const void *value, LYD_ANYDATA_VALUETYPE value_type,
151 struct lyd_node **node);
Michal Vasko90932a92020-02-12 14:33:03 +0100152
153/**
Michal Vasko52927e22020-03-16 17:26:14 +0100154 * @brief Create an opaque node.
155 *
156 * @param[in] ctx libyang context.
157 * @param[in] name Element name.
158 * @param[in] name_len Length of @p name, must be set correctly.
159 * @param[in] value String value to be parsed.
160 * @param[in] value_len Length of @p value, must be set correctly.
161 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
162 * @param[in] format Input format of @p value and @p ns.
163 * @param[in] val_prefs Possible value prefixes, array is spent.
164 * @param[in] prefix Element prefix.
165 * @param[in] pref_len Length of @p prefix, must be set correctly.
166 * @param[in] ns Node namespace, meaning depends on @p format.
167 * @param[out] node Created node.
168 * @return LY_SUCCESS on success.
169 * @return LY_ERR value if an error occurred.
170 */
171LY_ERR lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_len, const char *value, size_t value_len,
172 int *dynamic, LYD_FORMAT format, struct ly_prefix *val_prefs, const char *prefix, size_t pref_len,
173 const char *ns, struct lyd_node **node);
174
175/**
Michal Vaskob104f112020-07-17 09:54:54 +0200176 * @brief Find the next node, before which to insert the new node.
Michal Vasko90932a92020-02-12 14:33:03 +0100177 *
Michal Vaskob104f112020-07-17 09:54:54 +0200178 * @param[in] first_sibling First sibling of the nodes to consider.
179 * @param[in] new_node Node that will be inserted.
180 * @return Node to insert after.
181 * @return NULL if the new node should be first.
Michal Vasko90932a92020-02-12 14:33:03 +0100182 */
Michal Vaskob104f112020-07-17 09:54:54 +0200183struct 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 +0100184
185/**
Michal Vaskob104f112020-07-17 09:54:54 +0200186 * @brief Insert a node into parent/siblings. Order and hashes are fully handled.
Michal Vasko90932a92020-02-12 14:33:03 +0100187 *
Michal Vasko9b368d32020-02-14 13:53:31 +0100188 * @param[in] parent Parent to insert into, NULL for top-level sibling.
189 * @param[in,out] first_sibling First sibling, NULL if no top-level sibling exist yet. Can be also NULL if @p parent is set.
Michal Vasko90932a92020-02-12 14:33:03 +0100190 * @param[in] node Individual node (without siblings) to insert.
191 */
Michal Vasko9b368d32020-02-14 13:53:31 +0100192void lyd_insert_node(struct lyd_node *parent, struct lyd_node **first_sibling, struct lyd_node *node);
Michal Vasko90932a92020-02-12 14:33:03 +0100193
194/**
Michal Vasko52927e22020-03-16 17:26:14 +0100195 * @brief Create and insert a metadata (last) into a parent.
Michal Vasko90932a92020-02-12 14:33:03 +0100196 *
Michal Vasko52927e22020-03-16 17:26:14 +0100197 * @param[in] parent Parent of the metadata, can be NULL.
Michal Vasko9f96a052020-03-10 09:41:45 +0100198 * @param[in,out] meta Metadata list to add at its end if @p parent is NULL, returned created attribute.
199 * @param[in] mod Metadata module (with the annotation definition).
Michal Vasko90932a92020-02-12 14:33:03 +0100200 * @param[in] name Attribute name.
Michal Vaskof03ed032020-03-04 13:31:44 +0100201 * @param[in] name_len Length of @p name, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100202 * @param[in] value String value to be parsed.
Michal Vaskof03ed032020-03-04 13:31:44 +0100203 * @param[in] value_len Length of @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100204 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
Michal Vasko52927e22020-03-16 17:26:14 +0100205 * @param[in] resolve_prefix Parser-specific getter to resolve prefixes used in the @p value string.
Michal Vasko90932a92020-02-12 14:33:03 +0100206 * @param[in] prefix_data User data for @p get_prefix.
207 * @param[in] format Input format of @p value.
Michal Vasko8d544252020-03-02 10:19:52 +0100208 * @param[in] ctx_snode Context node for value resolution in schema.
Michal Vasko90932a92020-02-12 14:33:03 +0100209 * @return LY_SUCCESS on success.
210 * @return LY_EINCOMPLETE in case data tree is needed to finish the validation.
211 * @return LY_ERR value if an error occurred.
212 */
Michal Vasko9f96a052020-03-10 09:41:45 +0100213LY_ERR lyd_create_meta(struct lyd_node *parent, struct lyd_meta **meta, const struct lys_module *mod, const char *name,
Michal Vasko52927e22020-03-16 17:26:14 +0100214 size_t name_len, const char *value, size_t value_len, int *dynamic, ly_clb_resolve_prefix resolve_prefix,
Michal Vasko8d544252020-03-02 10:19:52 +0100215 void *prefix_data, LYD_FORMAT format, const struct lysc_node *ctx_snode);
Michal Vasko90932a92020-02-12 14:33:03 +0100216
217/**
Michal Vasko52927e22020-03-16 17:26:14 +0100218 * @brief Create and insert a generic attribute (last) into a parent.
219 *
220 * @param[in] parent Parent of the attribute, can be NULL.
221 * @param[in,out] attr Attribute list to add at its end if @p parent is NULL, returned created attribute.
222 * @param[in] ctx libyang context.
223 * @param[in] name Attribute name.
224 * @param[in] name_len Length of @p name, must be set correctly.
225 * @param[in] value String value to be parsed.
226 * @param[in] value_len Length of @p value, must be set correctly.
227 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
228 * @param[in] format Input format of @p value and @p ns.
229 * @param[in] val_prefs Possible value prefixes, array is spent.
230 * @param[in] prefix Attribute prefix.
231 * @param[in] prefix_len Attribute prefix length.
232 * @param[in] ns Attribute namespace, meaning depends on @p format.
233 * @return LY_SUCCESS on success.
234 * @return LY_ERR value if an error occurred.
235 */
236LY_ERR ly_create_attr(struct lyd_node *parent, struct ly_attr **attr, const struct ly_ctx *ctx, const char *name,
237 size_t name_len, const char *value, size_t value_len, int *dynamic, LYD_FORMAT format,
238 struct ly_prefix *val_prefs, const char *prefix, size_t prefix_len, const char *ns);
239
240/**
Radek Krejci5819f7c2019-05-31 14:53:29 +0200241 * @brief Validate, canonize and store the given @p value into the node according to the node's type's rules.
Radek Krejcie7b95092019-05-15 11:03:07 +0200242 *
Radek Krejci38d85362019-09-05 16:26:38 +0200243 * @param[in] node Data node for the @p value.
Radek Krejci084289f2019-07-09 17:35:30 +0200244 * @param[in] value String value to be parsed, must not be NULL.
Michal Vaskof03ed032020-03-04 13:31:44 +0100245 * @param[in] value_len Length of the give @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100246 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
Radek Krejci3c9758d2019-07-11 16:49:10 +0200247 * @param[in] second Flag for the second call after returning LY_EINCOMPLETE
Radek Krejci084289f2019-07-09 17:35:30 +0200248 * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string.
Radek Krejciaca74032019-06-04 08:53:06 +0200249 * @param[in] parser Parser's data for @p get_prefix
Michal Vasko90932a92020-02-12 14:33:03 +0100250 * @param[in] format Input format of @p value.
Michal Vaskof03ed032020-03-04 13:31:44 +0100251 * @param[in] tree Data tree (e.g. when validating RPC/Notification) where the required
Radek Krejcie553e6d2019-06-07 15:33:18 +0200252 * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete,
253 * then LY_EINCOMPLETE can be returned.
254 * @return LY_SUCCESS on success
255 * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation.
256 * @return LY_ERR value if an error occurred.
Radek Krejcie7b95092019-05-15 11:03:07 +0200257 */
Michal Vasko90932a92020-02-12 14:33:03 +0100258LY_ERR lyd_value_parse(struct lyd_node_term *node, const char *value, size_t value_len, int *dynamic, int second,
Michal Vaskof03ed032020-03-04 13:31:44 +0100259 ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format, const struct lyd_node *tree);
Radek Krejcie7b95092019-05-15 11:03:07 +0200260
Michal Vasko004d3152020-06-11 19:59:22 +0200261/* similar to lyd_value_parse except can be used just to store the value, hence does also not support a second call */
262LY_ERR lyd_value_store(struct lyd_value *val, const struct lysc_node *schema, const char *value, size_t value_len,
263 int *dynamic, ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format);
264
Radek Krejcie7b95092019-05-15 11:03:07 +0200265/**
Michal Vasko9f96a052020-03-10 09:41:45 +0100266 * @brief Validate, canonize and store the given @p value into the metadata according to the annotation type's rules.
Radek Krejci38d85362019-09-05 16:26:38 +0200267 *
Michal Vasko8d544252020-03-02 10:19:52 +0100268 * @param[in] ctx libyang context.
Michal Vasko9f96a052020-03-10 09:41:45 +0100269 * @param[in] meta Metadata for the @p value.
Radek Krejci38d85362019-09-05 16:26:38 +0200270 * @param[in] value String value to be parsed, must not be NULL.
Michal Vaskof03ed032020-03-04 13:31:44 +0100271 * @param[in] value_len Length of the give @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100272 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
Radek Krejci38d85362019-09-05 16:26:38 +0200273 * @param[in] second Flag for the second call after returning LY_EINCOMPLETE
274 * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string.
275 * @param[in] parser Parser's data for @p get_prefix
276 * @param[in] format Input format of the data.
Michal Vasko8d544252020-03-02 10:19:52 +0100277 * @param[in] ctx_snode Context node for value resolution in schema.
Michal Vaskof03ed032020-03-04 13:31:44 +0100278 * @param[in] tree Data tree (e.g. when validating RPC/Notification) where the required
Radek Krejci38d85362019-09-05 16:26:38 +0200279 * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete,
280 * then LY_EINCOMPLETE can be returned.
281 * @return LY_SUCCESS on success
282 * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation.
283 * @return LY_ERR value if an error occurred.
284 */
Michal Vasko41586352020-07-13 13:54:25 +0200285LY_ERR lyd_value_parse_meta(const struct ly_ctx *ctx, struct lyd_meta *meta, const char *value, size_t value_len,
286 int *dynamic, int second, ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format,
Michal Vaskof03ed032020-03-04 13:31:44 +0100287 const struct lysc_node *ctx_snode, const struct lyd_node *tree);
Radek Krejci38d85362019-09-05 16:26:38 +0200288
289/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200290 * @brief Parse XML string as YANG data tree.
291 *
292 * @param[in] ctx libyang context
Michal Vasko63f3d842020-07-08 10:10:14 +0200293 * @param[in] in Input structure.
Radek Krejci7931b192020-06-25 17:05:03 +0200294 * @param[in] parse_options Options for parser, see @ref dataparseroptions.
295 * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions.
Michal Vaskob1b5c262020-03-05 14:29:47 +0100296 * @param[out] tree Parsed data tree. Note that NULL can be a valid result.
Michal Vasko9f96a052020-03-10 09:41:45 +0100297 * @return LY_ERR value.
Radek Krejcie7b95092019-05-15 11:03:07 +0200298 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200299LY_ERR lyd_parse_xml_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options,
300 struct lyd_node **tree);
Michal Vasko9f96a052020-03-10 09:41:45 +0100301
302/**
303 * @brief Parse XML string as YANG RPC/action invocation.
304 *
Radek Krejci7931b192020-06-25 17:05:03 +0200305 * Optional \<rpc\> envelope element is accepted if present. It is [checked](https://tools.ietf.org/html/rfc6241#section-4.1) and all
306 * its XML attributes are parsed. As a content of the enveloper, an RPC data or \<action\> envelope element is expected. The \<action\> envelope element is
307 * also [checked](https://tools.ietf.org/html/rfc7950#section-7.15.2) and then an action data is expected as a content of this envelope.
Michal Vasko9f96a052020-03-10 09:41:45 +0100308 *
309 * @param[in] ctx libyang context.
Michal Vasko63f3d842020-07-08 10:10:14 +0200310 * @param[in] in Input structure.
Michal Vaskob36053d2020-03-26 15:49:30 +0100311 * @param[out] tree Parsed full RPC/action tree.
Michal Vaskocc048b22020-03-27 15:52:38 +0100312 * @param[out] op Optional pointer to the actual operation. Useful mainly for action.
Michal Vasko9f96a052020-03-10 09:41:45 +0100313 * @return LY_ERR value.
314 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200315LY_ERR lyd_parse_xml_rpc(const struct ly_ctx *ctx, struct ly_in *in, struct lyd_node **tree, struct lyd_node **op);
Radek Krejcie7b95092019-05-15 11:03:07 +0200316
317/**
Michal Vaskoa8edff02020-03-27 14:47:01 +0100318 * @brief Parse XML string as YANG notification.
319 *
320 * Optional \<notification\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc5277#page-25)
321 * and parsed. Specifically, its namespace and the child \<eventTime\> element and its value.
322 *
323 * @param[in] ctx libyang context.
Michal Vasko63f3d842020-07-08 10:10:14 +0200324 * @param[in] in Input structure.
Michal Vaskoa8edff02020-03-27 14:47:01 +0100325 * @param[out] tree Parsed full notification tree.
Michal Vaskocc048b22020-03-27 15:52:38 +0100326 * @param[out] op Optional pointer to the actual notification. Useful mainly for nested notifications.
Michal Vaskoa8edff02020-03-27 14:47:01 +0100327 * @return LY_ERR value.
328 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200329LY_ERR lyd_parse_xml_notif(const struct ly_ctx *ctx, struct ly_in *in, struct lyd_node **tree, struct lyd_node **ntf);
Michal Vaskoa8edff02020-03-27 14:47:01 +0100330
331/**
Michal Vasko1ce933a2020-03-30 12:38:22 +0200332 * @brief Parse XML string as YANG RPC/action reply.
333 *
334 * Optional \<rpc-reply\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc6241#section-4.2)
335 * and all its XML attributes parsed.
336 *
337 * @param[in] request Data tree of the RPC/action request.
Michal Vasko63f3d842020-07-08 10:10:14 +0200338 * @param[in] in Input structure.
Michal Vasko1ce933a2020-03-30 12:38:22 +0200339 * @param[out] tree Parsed full reply tree. It always includes duplicated operation and parents of the @p request.
340 * @param[out] op Optional pointer to the reply operation. Useful mainly for action.
341 * @return LY_ERR value.
342 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200343LY_ERR lyd_parse_xml_reply(const struct lyd_node *request, struct ly_in *in, struct lyd_node **tree, struct lyd_node **op);
Michal Vasko1ce933a2020-03-30 12:38:22 +0200344
345/**
Michal Vasko60ea6352020-06-29 13:39:39 +0200346 * @brief Parse binary data as YANG data tree.
347 *
348 * @param[in] ctx libyang context
Michal Vasko63f3d842020-07-08 10:10:14 +0200349 * @param[in] in Input structure.
Radek Krejci7931b192020-06-25 17:05:03 +0200350 * @param[in] parse_options Options for parser, see @ref dataparseroptions.
351 * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions.
Michal Vasko60ea6352020-06-29 13:39:39 +0200352 * @param[out] tree Parsed data tree. Note that NULL can be a valid result.
Michal Vasko60ea6352020-06-29 13:39:39 +0200353 * @return LY_ERR value.
354 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200355LY_ERR lyd_parse_lyb_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options,
356 struct lyd_node **tree);
Michal Vasko60ea6352020-06-29 13:39:39 +0200357
358/**
359 * @brief Parse binary data as YANG RPC/action invocation.
360 *
361 * @param[in] ctx libyang context.
Michal Vasko63f3d842020-07-08 10:10:14 +0200362 * @param[in] in Input structure.
Michal Vasko60ea6352020-06-29 13:39:39 +0200363 * @param[out] tree Parsed full RPC/action tree.
364 * @param[out] op Optional pointer to the actual operation. Useful mainly for action.
Michal Vasko60ea6352020-06-29 13:39:39 +0200365 * @return LY_ERR value.
366 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200367LY_ERR lyd_parse_lyb_rpc(const struct ly_ctx *ctx, struct ly_in *in, struct lyd_node **tree, struct lyd_node **op);
Michal Vasko60ea6352020-06-29 13:39:39 +0200368
369/**
370 * @brief Parse binary data as YANG notification.
371 *
372 * @param[in] ctx libyang context.
Michal Vasko63f3d842020-07-08 10:10:14 +0200373 * @param[in] in Input structure.
Michal Vasko60ea6352020-06-29 13:39:39 +0200374 * @param[out] tree Parsed full notification tree.
375 * @param[out] op Optional pointer to the actual notification. Useful mainly for nested notifications.
Michal Vasko60ea6352020-06-29 13:39:39 +0200376 * @return LY_ERR value.
377 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200378LY_ERR lyd_parse_lyb_notif(const struct ly_ctx *ctx, struct ly_in *in, struct lyd_node **tree, struct lyd_node **ntf);
Michal Vasko60ea6352020-06-29 13:39:39 +0200379
380/**
381 * @brief Parse binary data as YANG RPC/action reply.
382 *
383 * @param[in] request Data tree of the RPC/action request.
Michal Vasko63f3d842020-07-08 10:10:14 +0200384 * @param[in] in Input structure.
Michal Vasko60ea6352020-06-29 13:39:39 +0200385 * @param[out] tree Parsed full reply tree. It always includes duplicated operation and parents of the @p request.
386 * @param[out] op Optional pointer to the reply operation. Useful mainly for action.
Michal Vasko60ea6352020-06-29 13:39:39 +0200387 * @return LY_ERR value.
388 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200389LY_ERR lyd_parse_lyb_reply(const struct lyd_node *request, struct ly_in *in, struct lyd_node **tree, struct lyd_node **op);
Michal Vasko60ea6352020-06-29 13:39:39 +0200390
391/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200392 * @defgroup datahash Data nodes hash manipulation
393 * @ingroup datatree
394 */
395
396/**
Radek Krejci1f05b6a2019-07-18 16:15:06 +0200397 * @brief Generate hash for the node.
398 *
399 * @param[in] node Data node to (re)generate hash value.
400 * @return LY_ERR value.
401 */
402LY_ERR lyd_hash(struct lyd_node *node);
403
404/**
405 * @brief Insert hash of the node into the hash table of its parent.
406 *
407 * @param[in] node Data node which hash will be inserted into the lyd_node_inner::children_hash hash table of its parent.
408 * @return LY_ERR value.
409 */
410LY_ERR lyd_insert_hash(struct lyd_node *node);
411
412/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200413 * @brief Maintain node's parent's children hash table when unlinking the node.
414 *
415 * When completely freeing data tree, it is expected to free the parent's children hash table first, at once.
416 *
417 * @param[in] node The data node being unlinked from its parent.
418 */
419void lyd_unlink_hash(struct lyd_node *node);
420
421/** @} datahash */
422
Radek Krejci084289f2019-07-09 17:35:30 +0200423/**
Michal Vaskob1b5c262020-03-05 14:29:47 +0100424 * @brief Iterate over implemented modules for functions that accept specific modules or the whole context.
425 *
426 * @param[in] tree Data tree.
Michal Vasko26e80012020-07-08 10:55:46 +0200427 * @param[in] module Selected module, NULL for all.
Michal Vaskob1b5c262020-03-05 14:29:47 +0100428 * @param[in] ctx Context, NULL for selected modules.
429 * @param[in,out] i Iterator, set to 0 on first call.
430 * @param[out] first First sibling of the returned module.
431 * @return Next module.
432 * @return NULL if all modules were traversed.
433 */
Michal Vasko26e80012020-07-08 10:55:46 +0200434const struct lys_module *lyd_mod_next_module(struct lyd_node *tree, const struct lys_module *module,
Michal Vaskob1b5c262020-03-05 14:29:47 +0100435 const struct ly_ctx *ctx, uint32_t *i, struct lyd_node **first);
436
437/**
438 * @brief Iterate over modules for functions that want to traverse all the top-level data.
439 *
440 * @param[in,out] next Pointer to the next module data, set to first top-level sibling on first call.
441 * @param[out] first First sibling of the returned module.
442 * @return Next module.
443 * @return NULL if all modules were traversed.
444 */
445const struct lys_module *lyd_data_next_module(struct lyd_node **next, struct lyd_node **first);
446
Michal Vasko9f96a052020-03-10 09:41:45 +0100447/**
448 * @brief Check that a list has all its keys.
449 *
450 * @param[in] node List to check.
Michal Vasko44685da2020-03-17 15:38:06 +0100451 * @return LY_SUCCESS on success.
452 * @return LY_ENOT on a missing key.
Michal Vasko9f96a052020-03-10 09:41:45 +0100453 */
454LY_ERR lyd_parse_check_keys(struct lyd_node *node);
455
Michal Vasko60ea6352020-06-29 13:39:39 +0200456/**
457 * @brief Set data flags for a newly parsed node.
458 *
459 * @param[in] node Node to use.
460 * @param[in] when_check Set of nodes with unresolved when.
461 * @param[in,out] meta Node metadata, may be removed from.
462 * @param[in] options Parse options.
463 */
464void lyd_parse_set_data_flags(struct lyd_node *node, struct ly_set *when_check, struct lyd_meta **meta, int options);
465
466/**
Michal Vasko61551fa2020-07-09 15:45:45 +0200467 * @brief Copy anydata value from one node to another. Target value is freed first.
468 *
469 * @param[in,out] trg Target node.
470 * @param[in] value Source value, may be NULL when the target value is only freed.
471 * @param[in] value_type Source value type.
472 * @return LY_ERR value.
473 */
474LY_ERR lyd_any_copy_value(struct lyd_node *trg, const union lyd_any_value *value, LYD_ANYDATA_VALUETYPE value_type);
475
476/**
Michal Vasko60ea6352020-06-29 13:39:39 +0200477 * @brief Free value prefixes.
478 *
479 * @param[in] ctx libyang context.
480 * @param[in] val_prefis Value prefixes to free, sized array (@ref sizedarrays).
481 */
482void ly_free_val_prefs(const struct ly_ctx *ctx, struct ly_prefix *val_prefs);
483
Michal Vaskod59035b2020-07-08 12:00:06 +0200484/**
485 * @brief Append all list key predicates to path.
486 *
487 * @param[in] node Node with keys to print.
488 * @param[in,out] buffer Buffer to print to.
489 * @param[in,out] buflen Current buffer length.
490 * @param[in,out] bufused Current number of characters used in @p buffer.
491 * @param[in] is_static Whether buffer is static or can be reallocated.
492 * @return LY_ERR
493 */
494LY_ERR lyd_path_list_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, int is_static);
495
Radek Krejcie7b95092019-05-15 11:03:07 +0200496#endif /* LY_TREE_DATA_INTERNAL_H_ */