blob: 00b843b9a2acdd2c2f9ca66b6ba2fe2ac8673cf4 [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 Vasko90932a92020-02-12 14:33:03 +0100176 * @brief Find the key after which to insert the new key.
177 *
178 * @param[in] first_sibling List first sibling.
179 * @param[in] new_key Key that will be inserted.
180 * @return Key to insert after.
181 * @return NULL if the new key should be first.
182 */
183struct lyd_node *lyd_get_prev_key_anchor(const struct lyd_node *first_sibling, const struct lysc_node *new_key);
184
185/**
186 * @brief Insert a node into parent/siblings. In case a key is being inserted into a list, the correct position
Michal Vasko9f96a052020-03-10 09:41:45 +0100187 * is found, inserted into, and if it is the last key, parent list hash is calculated. Also, in case we are inserting
188 * into top-level siblings, insert it as the last sibling of all the module data siblings. Otherwise it is inserted at
189 * the very last place.
Michal Vasko90932a92020-02-12 14:33:03 +0100190 *
Michal Vasko9b368d32020-02-14 13:53:31 +0100191 * @param[in] parent Parent to insert into, NULL for top-level sibling.
192 * @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 +0100193 * @param[in] node Individual node (without siblings) to insert.
194 */
Michal Vasko9b368d32020-02-14 13:53:31 +0100195void lyd_insert_node(struct lyd_node *parent, struct lyd_node **first_sibling, struct lyd_node *node);
Michal Vasko90932a92020-02-12 14:33:03 +0100196
197/**
Michal Vasko52927e22020-03-16 17:26:14 +0100198 * @brief Create and insert a metadata (last) into a parent.
Michal Vasko90932a92020-02-12 14:33:03 +0100199 *
Michal Vasko52927e22020-03-16 17:26:14 +0100200 * @param[in] parent Parent of the metadata, can be NULL.
Michal Vasko9f96a052020-03-10 09:41:45 +0100201 * @param[in,out] meta Metadata list to add at its end if @p parent is NULL, returned created attribute.
202 * @param[in] mod Metadata module (with the annotation definition).
Michal Vasko90932a92020-02-12 14:33:03 +0100203 * @param[in] name Attribute name.
Michal Vaskof03ed032020-03-04 13:31:44 +0100204 * @param[in] name_len Length of @p name, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100205 * @param[in] value String value to be parsed.
Michal Vaskof03ed032020-03-04 13:31:44 +0100206 * @param[in] value_len Length of @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100207 * @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 +0100208 * @param[in] resolve_prefix Parser-specific getter to resolve prefixes used in the @p value string.
Michal Vasko90932a92020-02-12 14:33:03 +0100209 * @param[in] prefix_data User data for @p get_prefix.
210 * @param[in] format Input format of @p value.
Michal Vasko8d544252020-03-02 10:19:52 +0100211 * @param[in] ctx_snode Context node for value resolution in schema.
Michal Vasko90932a92020-02-12 14:33:03 +0100212 * @return LY_SUCCESS on success.
213 * @return LY_EINCOMPLETE in case data tree is needed to finish the validation.
214 * @return LY_ERR value if an error occurred.
215 */
Michal Vasko9f96a052020-03-10 09:41:45 +0100216LY_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 +0100217 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 +0100218 void *prefix_data, LYD_FORMAT format, const struct lysc_node *ctx_snode);
Michal Vasko90932a92020-02-12 14:33:03 +0100219
220/**
Michal Vasko52927e22020-03-16 17:26:14 +0100221 * @brief Create and insert a generic attribute (last) into a parent.
222 *
223 * @param[in] parent Parent of the attribute, can be NULL.
224 * @param[in,out] attr Attribute list to add at its end if @p parent is NULL, returned created attribute.
225 * @param[in] ctx libyang context.
226 * @param[in] name Attribute name.
227 * @param[in] name_len Length of @p name, must be set correctly.
228 * @param[in] value String value to be parsed.
229 * @param[in] value_len Length of @p value, must be set correctly.
230 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
231 * @param[in] format Input format of @p value and @p ns.
232 * @param[in] val_prefs Possible value prefixes, array is spent.
233 * @param[in] prefix Attribute prefix.
234 * @param[in] prefix_len Attribute prefix length.
235 * @param[in] ns Attribute namespace, meaning depends on @p format.
236 * @return LY_SUCCESS on success.
237 * @return LY_ERR value if an error occurred.
238 */
239LY_ERR ly_create_attr(struct lyd_node *parent, struct ly_attr **attr, const struct ly_ctx *ctx, const char *name,
240 size_t name_len, const char *value, size_t value_len, int *dynamic, LYD_FORMAT format,
241 struct ly_prefix *val_prefs, const char *prefix, size_t prefix_len, const char *ns);
242
243/**
Radek Krejci5819f7c2019-05-31 14:53:29 +0200244 * @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 +0200245 *
Radek Krejci38d85362019-09-05 16:26:38 +0200246 * @param[in] node Data node for the @p value.
Radek Krejci084289f2019-07-09 17:35:30 +0200247 * @param[in] value String value to be parsed, must not be NULL.
Michal Vaskof03ed032020-03-04 13:31:44 +0100248 * @param[in] value_len Length of the give @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100249 * @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 +0200250 * @param[in] second Flag for the second call after returning LY_EINCOMPLETE
Radek Krejci084289f2019-07-09 17:35:30 +0200251 * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string.
Radek Krejciaca74032019-06-04 08:53:06 +0200252 * @param[in] parser Parser's data for @p get_prefix
Michal Vasko90932a92020-02-12 14:33:03 +0100253 * @param[in] format Input format of @p value.
Michal Vaskof03ed032020-03-04 13:31:44 +0100254 * @param[in] tree Data tree (e.g. when validating RPC/Notification) where the required
Radek Krejcie553e6d2019-06-07 15:33:18 +0200255 * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete,
256 * then LY_EINCOMPLETE can be returned.
257 * @return LY_SUCCESS on success
258 * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation.
259 * @return LY_ERR value if an error occurred.
Radek Krejcie7b95092019-05-15 11:03:07 +0200260 */
Michal Vasko90932a92020-02-12 14:33:03 +0100261LY_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 +0100262 ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format, const struct lyd_node *tree);
Radek Krejcie7b95092019-05-15 11:03:07 +0200263
Michal Vasko004d3152020-06-11 19:59:22 +0200264/* similar to lyd_value_parse except can be used just to store the value, hence does also not support a second call */
265LY_ERR lyd_value_store(struct lyd_value *val, const struct lysc_node *schema, const char *value, size_t value_len,
266 int *dynamic, ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format);
267
Radek Krejcie7b95092019-05-15 11:03:07 +0200268/**
Michal Vasko9f96a052020-03-10 09:41:45 +0100269 * @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 +0200270 *
Michal Vasko8d544252020-03-02 10:19:52 +0100271 * @param[in] ctx libyang context.
Michal Vasko9f96a052020-03-10 09:41:45 +0100272 * @param[in] meta Metadata for the @p value.
Radek Krejci38d85362019-09-05 16:26:38 +0200273 * @param[in] value String value to be parsed, must not be NULL.
Michal Vaskof03ed032020-03-04 13:31:44 +0100274 * @param[in] value_len Length of the give @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100275 * @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 +0200276 * @param[in] second Flag for the second call after returning LY_EINCOMPLETE
277 * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string.
278 * @param[in] parser Parser's data for @p get_prefix
279 * @param[in] format Input format of the data.
Michal Vasko8d544252020-03-02 10:19:52 +0100280 * @param[in] ctx_snode Context node for value resolution in schema.
Michal Vaskof03ed032020-03-04 13:31:44 +0100281 * @param[in] tree Data tree (e.g. when validating RPC/Notification) where the required
Radek Krejci38d85362019-09-05 16:26:38 +0200282 * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete,
283 * then LY_EINCOMPLETE can be returned.
284 * @return LY_SUCCESS on success
285 * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation.
286 * @return LY_ERR value if an error occurred.
287 */
Michal Vasko9f96a052020-03-10 09:41:45 +0100288LY_ERR lyd_value_parse_meta(struct ly_ctx *ctx, struct lyd_meta *meta, const char *value, size_t value_len, int *dynamic,
Michal Vasko8d544252020-03-02 10:19:52 +0100289 int second, ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format,
Michal Vaskof03ed032020-03-04 13:31:44 +0100290 const struct lysc_node *ctx_snode, const struct lyd_node *tree);
Radek Krejci38d85362019-09-05 16:26:38 +0200291
292/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200293 * @brief Parse XML string as YANG data tree.
294 *
295 * @param[in] ctx libyang context
Michal Vasko63f3d842020-07-08 10:10:14 +0200296 * @param[in] in Input structure.
Radek Krejci7931b192020-06-25 17:05:03 +0200297 * @param[in] parse_options Options for parser, see @ref dataparseroptions.
298 * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions.
Michal Vaskob1b5c262020-03-05 14:29:47 +0100299 * @param[out] tree Parsed data tree. Note that NULL can be a valid result.
Michal Vasko9f96a052020-03-10 09:41:45 +0100300 * @return LY_ERR value.
Radek Krejcie7b95092019-05-15 11:03:07 +0200301 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200302LY_ERR lyd_parse_xml_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options,
303 struct lyd_node **tree);
Michal Vasko9f96a052020-03-10 09:41:45 +0100304
305/**
306 * @brief Parse XML string as YANG RPC/action invocation.
307 *
Radek Krejci7931b192020-06-25 17:05:03 +0200308 * Optional \<rpc\> envelope element is accepted if present. It is [checked](https://tools.ietf.org/html/rfc6241#section-4.1) and all
309 * 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
310 * 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 +0100311 *
312 * @param[in] ctx libyang context.
Michal Vasko63f3d842020-07-08 10:10:14 +0200313 * @param[in] in Input structure.
Michal Vaskob36053d2020-03-26 15:49:30 +0100314 * @param[out] tree Parsed full RPC/action tree.
Michal Vaskocc048b22020-03-27 15:52:38 +0100315 * @param[out] op Optional pointer to the actual operation. Useful mainly for action.
Michal Vasko9f96a052020-03-10 09:41:45 +0100316 * @return LY_ERR value.
317 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200318LY_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 +0200319
320/**
Michal Vaskoa8edff02020-03-27 14:47:01 +0100321 * @brief Parse XML string as YANG notification.
322 *
323 * Optional \<notification\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc5277#page-25)
324 * and parsed. Specifically, its namespace and the child \<eventTime\> element and its value.
325 *
326 * @param[in] ctx libyang context.
Michal Vasko63f3d842020-07-08 10:10:14 +0200327 * @param[in] in Input structure.
Michal Vaskoa8edff02020-03-27 14:47:01 +0100328 * @param[out] tree Parsed full notification tree.
Michal Vaskocc048b22020-03-27 15:52:38 +0100329 * @param[out] op Optional pointer to the actual notification. Useful mainly for nested notifications.
Michal Vaskoa8edff02020-03-27 14:47:01 +0100330 * @return LY_ERR value.
331 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200332LY_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 +0100333
334/**
Michal Vasko1ce933a2020-03-30 12:38:22 +0200335 * @brief Parse XML string as YANG RPC/action reply.
336 *
337 * Optional \<rpc-reply\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc6241#section-4.2)
338 * and all its XML attributes parsed.
339 *
340 * @param[in] request Data tree of the RPC/action request.
Michal Vasko63f3d842020-07-08 10:10:14 +0200341 * @param[in] in Input structure.
Michal Vasko1ce933a2020-03-30 12:38:22 +0200342 * @param[out] tree Parsed full reply tree. It always includes duplicated operation and parents of the @p request.
343 * @param[out] op Optional pointer to the reply operation. Useful mainly for action.
344 * @return LY_ERR value.
345 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200346LY_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 +0200347
348/**
Michal Vasko60ea6352020-06-29 13:39:39 +0200349 * @brief Parse binary data as YANG data tree.
350 *
351 * @param[in] ctx libyang context
Michal Vasko63f3d842020-07-08 10:10:14 +0200352 * @param[in] in Input structure.
Radek Krejci7931b192020-06-25 17:05:03 +0200353 * @param[in] parse_options Options for parser, see @ref dataparseroptions.
354 * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions.
Michal Vasko60ea6352020-06-29 13:39:39 +0200355 * @param[out] tree Parsed data tree. Note that NULL can be a valid result.
Michal Vasko60ea6352020-06-29 13:39:39 +0200356 * @return LY_ERR value.
357 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200358LY_ERR lyd_parse_lyb_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options,
359 struct lyd_node **tree);
Michal Vasko60ea6352020-06-29 13:39:39 +0200360
361/**
362 * @brief Parse binary data as YANG RPC/action invocation.
363 *
364 * @param[in] ctx libyang context.
Michal Vasko63f3d842020-07-08 10:10:14 +0200365 * @param[in] in Input structure.
Michal Vasko60ea6352020-06-29 13:39:39 +0200366 * @param[out] tree Parsed full RPC/action tree.
367 * @param[out] op Optional pointer to the actual operation. Useful mainly for action.
Michal Vasko60ea6352020-06-29 13:39:39 +0200368 * @return LY_ERR value.
369 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200370LY_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 +0200371
372/**
373 * @brief Parse binary data as YANG notification.
374 *
375 * @param[in] ctx libyang context.
Michal Vasko63f3d842020-07-08 10:10:14 +0200376 * @param[in] in Input structure.
Michal Vasko60ea6352020-06-29 13:39:39 +0200377 * @param[out] tree Parsed full notification tree.
378 * @param[out] op Optional pointer to the actual notification. Useful mainly for nested notifications.
Michal Vasko60ea6352020-06-29 13:39:39 +0200379 * @return LY_ERR value.
380 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200381LY_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 +0200382
383/**
384 * @brief Parse binary data as YANG RPC/action reply.
385 *
386 * @param[in] request Data tree of the RPC/action request.
Michal Vasko63f3d842020-07-08 10:10:14 +0200387 * @param[in] in Input structure.
Michal Vasko60ea6352020-06-29 13:39:39 +0200388 * @param[out] tree Parsed full reply tree. It always includes duplicated operation and parents of the @p request.
389 * @param[out] op Optional pointer to the reply operation. Useful mainly for action.
Michal Vasko60ea6352020-06-29 13:39:39 +0200390 * @return LY_ERR value.
391 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200392LY_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 +0200393
394/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200395 * @defgroup datahash Data nodes hash manipulation
396 * @ingroup datatree
397 */
398
399/**
Radek Krejci1f05b6a2019-07-18 16:15:06 +0200400 * @brief Generate hash for the node.
401 *
402 * @param[in] node Data node to (re)generate hash value.
403 * @return LY_ERR value.
404 */
405LY_ERR lyd_hash(struct lyd_node *node);
406
407/**
408 * @brief Insert hash of the node into the hash table of its parent.
409 *
410 * @param[in] node Data node which hash will be inserted into the lyd_node_inner::children_hash hash table of its parent.
411 * @return LY_ERR value.
412 */
413LY_ERR lyd_insert_hash(struct lyd_node *node);
414
415/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200416 * @brief Maintain node's parent's children hash table when unlinking the node.
417 *
418 * When completely freeing data tree, it is expected to free the parent's children hash table first, at once.
419 *
420 * @param[in] node The data node being unlinked from its parent.
421 */
422void lyd_unlink_hash(struct lyd_node *node);
423
424/** @} datahash */
425
Radek Krejci084289f2019-07-09 17:35:30 +0200426/**
Michal Vasko9b368d32020-02-14 13:53:31 +0100427 * @brief Find the node, in the list, satisfying the given restrictions.
428 * Does **not** use hashes - should not be used unless necessary for best performance.
429 *
430 * @param[in] first Starting sibling node for search, only succeeding ones are searched.
431 * @param[in] schema Schema node of the data node to find.
432 * @param[in] key_or_value Expected value depends on the type of @p schema:
433 * LYS_CONTAINER:
434 * LYS_ANYXML:
435 * LYS_ANYDATA:
436 * LYS_NOTIF:
437 * LYS_RPC:
438 * LYS_ACTION:
439 * NULL should be always set, will be ignored.
440 * LYS_LEAF:
441 * LYS_LEAFLIST:
442 * Optional restriction on the specific leaf(-list) value.
443 * LYS_LIST:
444 * Optional keys values of the matching list instances in the form of "[key1='val1'][key2='val2']...".
445 * The keys do not have to be ordered and not all keys need to be specified.
446 *
447 * Note that any explicit values (leaf, leaf-list or list key values) will be canonized first
448 * before comparison. But values that do not have a canonical value are expected to be in the
449 * JSON format!
450 * @param[in] val_len Optional length of the @p key_or_value argument in case it is not NULL-terminated string.
451 * @param[out] match Can be NULL, otherwise the found data node.
452 * @return LY_SUCCESS on success, @p match set.
453 * @return LY_ENOTFOUND if not found, @p match set to NULL.
454 * @return LY_ERR value if another error occurred.
455 */
456LY_ERR lyd_find_sibling_next2(const struct lyd_node *first, const struct lysc_node *schema, const char *key_or_value,
457 size_t val_len, struct lyd_node **match);
458
459/**
Michal Vaskob1b5c262020-03-05 14:29:47 +0100460 * @brief Iterate over implemented modules for functions that accept specific modules or the whole context.
461 *
462 * @param[in] tree Data tree.
Michal Vasko26e80012020-07-08 10:55:46 +0200463 * @param[in] module Selected module, NULL for all.
Michal Vaskob1b5c262020-03-05 14:29:47 +0100464 * @param[in] ctx Context, NULL for selected modules.
465 * @param[in,out] i Iterator, set to 0 on first call.
466 * @param[out] first First sibling of the returned module.
467 * @return Next module.
468 * @return NULL if all modules were traversed.
469 */
Michal Vasko26e80012020-07-08 10:55:46 +0200470const struct lys_module *lyd_mod_next_module(struct lyd_node *tree, const struct lys_module *module,
Michal Vaskob1b5c262020-03-05 14:29:47 +0100471 const struct ly_ctx *ctx, uint32_t *i, struct lyd_node **first);
472
473/**
474 * @brief Iterate over modules for functions that want to traverse all the top-level data.
475 *
476 * @param[in,out] next Pointer to the next module data, set to first top-level sibling on first call.
477 * @param[out] first First sibling of the returned module.
478 * @return Next module.
479 * @return NULL if all modules were traversed.
480 */
481const struct lys_module *lyd_data_next_module(struct lyd_node **next, struct lyd_node **first);
482
Michal Vasko9f96a052020-03-10 09:41:45 +0100483/**
484 * @brief Check that a list has all its keys.
485 *
486 * @param[in] node List to check.
Michal Vasko44685da2020-03-17 15:38:06 +0100487 * @return LY_SUCCESS on success.
488 * @return LY_ENOT on a missing key.
Michal Vasko9f96a052020-03-10 09:41:45 +0100489 */
490LY_ERR lyd_parse_check_keys(struct lyd_node *node);
491
Michal Vasko60ea6352020-06-29 13:39:39 +0200492/**
493 * @brief Set data flags for a newly parsed node.
494 *
495 * @param[in] node Node to use.
496 * @param[in] when_check Set of nodes with unresolved when.
497 * @param[in,out] meta Node metadata, may be removed from.
498 * @param[in] options Parse options.
499 */
500void lyd_parse_set_data_flags(struct lyd_node *node, struct ly_set *when_check, struct lyd_meta **meta, int options);
501
502/**
503 * @brief Free value prefixes.
504 *
505 * @param[in] ctx libyang context.
506 * @param[in] val_prefis Value prefixes to free, sized array (@ref sizedarrays).
507 */
508void ly_free_val_prefs(const struct ly_ctx *ctx, struct ly_prefix *val_prefs);
509
Michal Vaskod59035b2020-07-08 12:00:06 +0200510/**
511 * @brief Append all list key predicates to path.
512 *
513 * @param[in] node Node with keys to print.
514 * @param[in,out] buffer Buffer to print to.
515 * @param[in,out] buflen Current buffer length.
516 * @param[in,out] bufused Current number of characters used in @p buffer.
517 * @param[in] is_static Whether buffer is static or can be reallocated.
518 * @return LY_ERR
519 */
520LY_ERR lyd_path_list_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, int is_static);
521
Radek Krejcie7b95092019-05-15 11:03:07 +0200522#endif /* LY_TREE_DATA_INTERNAL_H_ */