blob: be5ceca6e250f499c327c00e06ba7dff697173a1 [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;
Michal Vaskoa6669ba2020-08-06 16:14:26 +020026struct lysc_module;
Michal Vasko004d3152020-06-11 19:59:22 +020027
Radek Krejcie7b95092019-05-15 11:03:07 +020028/**
Michal Vasko60ea6352020-06-29 13:39:39 +020029 * @brief Internal data parser flags.
30 */
31#define LYD_INTOPT_RPC 0x01 /**< RPC/action invocation is being parsed */
32#define LYD_INTOPT_NOTIF 0x02 /**< notification is being parsed */
33#define LYD_INTOPT_REPLY 0x04 /**< RPC/action reply is being parsed */
34
35/**
36 * @brief Hash schema sibling to be used for LYB data.
37 *
38 * @param[in] sibling Sibling to hash.
39 * @param[in] collision_id Collision ID of the hash to generate.
40 * @return Generated hash.
41 */
42LYB_HASH lyb_hash(struct lysc_node *sibling, uint8_t collision_id);
43
44/**
45 * @brief Check whether a sibling module is in a module array.
46 *
47 * @param[in] sibling Sibling to check.
48 * @param[in] models Modules in a sized array.
49 * @return non-zero if the module was found,
50 * @return 0 if not found.
51 */
52int lyb_has_schema_model(const struct lysc_node *sibling, const struct lys_module **models);
53
54/**
Michal Vaskob1b5c262020-03-05 14:29:47 +010055 * @brief Check whether a node to be deleted is the first top-level sibling.
56 *
57 * @param[in] first First sibling.
58 * @param[in] to_del Node to be deleted.
59 */
60#define LYD_DEL_IS_ROOT(first, to_del) (((first) == (to_del)) && !(first)->parent && !(first)->prev->next)
61
62/**
Michal Vasko5bfd4be2020-06-23 13:26:19 +020063 * @brief Shorthand for getting data children without its keys.
64 *
65 * @param[in] node Node, whose children to traverse.
66 * @return Node children, skipping any keys of a list.
67 */
68#define LYD_CHILD(node) lyd_node_children(node, LYD_CHILDREN_SKIP_KEYS)
69
70/**
Radek Krejcie7b95092019-05-15 11:03:07 +020071 * @brief Get address of a node's child pointer if any.
72 *
Radek Krejcie7b95092019-05-15 11:03:07 +020073 * @param[in] node Node to check.
Michal Vasko9b368d32020-02-14 13:53:31 +010074 * @return Address of the node's child member,
75 * @return NULL if there is no child pointer.
Radek Krejcie7b95092019-05-15 11:03:07 +020076 */
77struct lyd_node **lyd_node_children_p(struct lyd_node *node);
78
79/**
Michal Vaskoa6669ba2020-08-06 16:14:26 +020080 * @brief Just like lys_getnext() but iterates over all data instances of the schema nodes.
81 *
82 * @param[in] last Last returned data node.
83 * @param[in] sibling Data node sibling to search in.
84 * @param[in,out] slast Schema last node, set to NULL for first call and do not change afterwards.
85 * May not be set if the function is used only for any suitable node existence check (such as the existence
86 * of any choice case data).
87 * @param[in] parent Schema parent of the iterated children nodes.
88 * @param[in] module Schema module of the iterated top-level nodes.
89 * @return Next matching data node,
90 * @return NULL if last data node was already returned.
91 */
92struct lyd_node *lys_getnext_data(const struct lyd_node *last, const struct lyd_node *sibling,
93 const struct lysc_node **slast, const struct lysc_node *parent,
94 const struct lysc_module *module);
95
96/**
Michal Vasko9b368d32020-02-14 13:53:31 +010097 * @brief Create a term (leaf/leaf-list) node from a string value.
98 *
99 * Hash is calculated and new node flag is set.
Michal Vasko90932a92020-02-12 14:33:03 +0100100 *
101 * @param[in] schema Schema node of the new data node.
102 * @param[in] value String value to be parsed.
Michal Vaskof03ed032020-03-04 13:31:44 +0100103 * @param[in] value_len Length of @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100104 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
105 * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string.
106 * @param[in] prefix_data User data for @p get_prefix.
107 * @param[in] format Input format of @p value.
108 * @param[out] node Created node.
109 * @return LY_SUCCESS on success.
110 * @return LY_EINCOMPLETE in case data tree is needed to finish the validation.
111 * @return LY_ERR value if an error occurred.
112 */
113LY_ERR lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, int *dynamic,
114 ly_clb_resolve_prefix get_prefix, void *prefix_data, LYD_FORMAT format, struct lyd_node **node);
115
116/**
Michal Vasko9b368d32020-02-14 13:53:31 +0100117 * @brief Create a term (leaf/leaf-list) node from a parsed value by duplicating it.
118 *
119 * Hash is calculated and new node flag is set.
120 *
121 * @param[in] schema Schema node of the new data node.
122 * @param[in] val Parsed value to use.
123 * @param[out] node Created node.
124 * @return LY_SUCCESS on success.
125 * @return LY_ERR value if an error occurred.
126 */
127LY_ERR lyd_create_term2(const struct lysc_node *schema, const struct lyd_value *val, struct lyd_node **node);
128
129/**
130 * @brief Create an inner (container/list/RPC/action/notification) node.
131 *
132 * Hash is calculated and new node flag is set except
133 * for list with keys, when the hash is not calculated!
134 * Also, non-presence container has its default flag set.
Michal Vasko90932a92020-02-12 14:33:03 +0100135 *
136 * @param[in] schema Schema node of the new data node.
137 * @param[out] node Created node.
138 * @return LY_SUCCESS on success.
139 * @return LY_ERR value if an error occurred.
140 */
141LY_ERR lyd_create_inner(const struct lysc_node *schema, struct lyd_node **node);
142
143/**
Michal Vasko9b368d32020-02-14 13:53:31 +0100144 * @brief Create a list with all its keys (cannot be used for key-less list).
145 *
146 * Hash is calculated and new node flag is set.
Michal Vasko90932a92020-02-12 14:33:03 +0100147 *
148 * @param[in] schema Schema node of the new data node.
Michal Vasko004d3152020-06-11 19:59:22 +0200149 * @param[in] predicates Compiled key list predicates.
Michal Vasko90932a92020-02-12 14:33:03 +0100150 * @param[out] node Created node.
151 * @return LY_SUCCESS on success.
152 * @return LY_ERR value if an error occurred.
153 */
Michal Vasko004d3152020-06-11 19:59:22 +0200154LY_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 +0100155
156/**
Michal Vasko9b368d32020-02-14 13:53:31 +0100157 * @brief Create an anyxml/anydata node.
158 *
159 * Hash is calculated and flags are properly set based on @p is_valid.
Michal Vasko90932a92020-02-12 14:33:03 +0100160 *
161 * @param[in] schema Schema node of the new data node.
162 * @param[in] value Value of the any node, is directly assigned into the data node.
163 * @param[in] value_type Value type of the value.
164 * @param[out] node Created node.
165 * @return LY_SUCCESS on success.
166 * @return LY_ERR value if an error occurred.
167 */
Michal Vasko9b368d32020-02-14 13:53:31 +0100168LY_ERR lyd_create_any(const struct lysc_node *schema, const void *value, LYD_ANYDATA_VALUETYPE value_type,
169 struct lyd_node **node);
Michal Vasko90932a92020-02-12 14:33:03 +0100170
171/**
Michal Vasko52927e22020-03-16 17:26:14 +0100172 * @brief Create an opaque node.
173 *
174 * @param[in] ctx libyang context.
175 * @param[in] name Element name.
176 * @param[in] name_len Length of @p name, must be set correctly.
177 * @param[in] value String value to be parsed.
178 * @param[in] value_len Length of @p value, must be set correctly.
179 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
180 * @param[in] format Input format of @p value and @p ns.
181 * @param[in] val_prefs Possible value prefixes, array is spent.
182 * @param[in] prefix Element prefix.
183 * @param[in] pref_len Length of @p prefix, must be set correctly.
184 * @param[in] ns Node namespace, meaning depends on @p format.
185 * @param[out] node Created node.
186 * @return LY_SUCCESS on success.
187 * @return LY_ERR value if an error occurred.
188 */
189LY_ERR lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_len, const char *value, size_t value_len,
190 int *dynamic, LYD_FORMAT format, struct ly_prefix *val_prefs, const char *prefix, size_t pref_len,
191 const char *ns, struct lyd_node **node);
192
193/**
Michal Vaskoa6669ba2020-08-06 16:14:26 +0200194 * @brief Check the existence and create any non-existing implicit siblings, recursively for the created nodes.
195 *
196 * @param[in] parent Parent of the potential default values, NULL for top-level siblings.
197 * @param[in,out] first First sibling.
198 * @param[in] sparent Schema parent of the siblings, NULL if schema of @p parent can be used.
199 * @param[in] mod Module of the default values, NULL for nested siblings.
200 * @param[in] node_types Optional set to add nodes with unresolved types into.
201 * @param[in] node_when Optional set to add nodes with "when" conditions into.
202 * @param[in] impl_opts Implicit options (@ref implicitoptions).
203 * @param[in,out] diff Validation diff.
204 * @return LY_ERR value.
205 */
206LY_ERR lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struct lysc_node *sparent,
207 const struct lys_module *mod, struct ly_set *node_types, struct ly_set *node_when,
208 int impl_opts, struct lyd_node **diff);
209
210/**
Michal Vaskob104f112020-07-17 09:54:54 +0200211 * @brief Find the next node, before which to insert the new node.
Michal Vasko90932a92020-02-12 14:33:03 +0100212 *
Michal Vaskob104f112020-07-17 09:54:54 +0200213 * @param[in] first_sibling First sibling of the nodes to consider.
214 * @param[in] new_node Node that will be inserted.
215 * @return Node to insert after.
216 * @return NULL if the new node should be first.
Michal Vasko90932a92020-02-12 14:33:03 +0100217 */
Michal Vaskob104f112020-07-17 09:54:54 +0200218struct 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 +0100219
220/**
Michal Vaskob104f112020-07-17 09:54:54 +0200221 * @brief Insert a node into parent/siblings. Order and hashes are fully handled.
Michal Vasko90932a92020-02-12 14:33:03 +0100222 *
Michal Vasko9b368d32020-02-14 13:53:31 +0100223 * @param[in] parent Parent to insert into, NULL for top-level sibling.
224 * @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 +0100225 * @param[in] node Individual node (without siblings) to insert.
226 */
Michal Vasko9b368d32020-02-14 13:53:31 +0100227void lyd_insert_node(struct lyd_node *parent, struct lyd_node **first_sibling, struct lyd_node *node);
Michal Vasko90932a92020-02-12 14:33:03 +0100228
229/**
Michal Vasko52927e22020-03-16 17:26:14 +0100230 * @brief Create and insert a metadata (last) into a parent.
Michal Vasko90932a92020-02-12 14:33:03 +0100231 *
Michal Vasko52927e22020-03-16 17:26:14 +0100232 * @param[in] parent Parent of the metadata, can be NULL.
Michal Vasko9f96a052020-03-10 09:41:45 +0100233 * @param[in,out] meta Metadata list to add at its end if @p parent is NULL, returned created attribute.
234 * @param[in] mod Metadata module (with the annotation definition).
Michal Vasko90932a92020-02-12 14:33:03 +0100235 * @param[in] name Attribute name.
Michal Vaskof03ed032020-03-04 13:31:44 +0100236 * @param[in] name_len Length of @p name, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100237 * @param[in] value String value to be parsed.
Michal Vaskof03ed032020-03-04 13:31:44 +0100238 * @param[in] value_len Length of @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100239 * @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 +0100240 * @param[in] resolve_prefix Parser-specific getter to resolve prefixes used in the @p value string.
Michal Vasko90932a92020-02-12 14:33:03 +0100241 * @param[in] prefix_data User data for @p get_prefix.
242 * @param[in] format Input format of @p value.
Michal Vasko8d544252020-03-02 10:19:52 +0100243 * @param[in] ctx_snode Context node for value resolution in schema.
Michal Vasko90932a92020-02-12 14:33:03 +0100244 * @return LY_SUCCESS on success.
245 * @return LY_EINCOMPLETE in case data tree is needed to finish the validation.
246 * @return LY_ERR value if an error occurred.
247 */
Michal Vasko9f96a052020-03-10 09:41:45 +0100248LY_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 +0100249 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 +0100250 void *prefix_data, LYD_FORMAT format, const struct lysc_node *ctx_snode);
Michal Vasko90932a92020-02-12 14:33:03 +0100251
252/**
Michal Vasko52927e22020-03-16 17:26:14 +0100253 * @brief Create and insert a generic attribute (last) into a parent.
254 *
255 * @param[in] parent Parent of the attribute, can be NULL.
256 * @param[in,out] attr Attribute list to add at its end if @p parent is NULL, returned created attribute.
257 * @param[in] ctx libyang context.
258 * @param[in] name Attribute name.
259 * @param[in] name_len Length of @p name, must be set correctly.
260 * @param[in] value String value to be parsed.
261 * @param[in] value_len Length of @p value, must be set correctly.
262 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
263 * @param[in] format Input format of @p value and @p ns.
264 * @param[in] val_prefs Possible value prefixes, array is spent.
265 * @param[in] prefix Attribute prefix.
266 * @param[in] prefix_len Attribute prefix length.
267 * @param[in] ns Attribute namespace, meaning depends on @p format.
268 * @return LY_SUCCESS on success.
269 * @return LY_ERR value if an error occurred.
270 */
271LY_ERR ly_create_attr(struct lyd_node *parent, struct ly_attr **attr, const struct ly_ctx *ctx, const char *name,
272 size_t name_len, const char *value, size_t value_len, int *dynamic, LYD_FORMAT format,
273 struct ly_prefix *val_prefs, const char *prefix, size_t prefix_len, const char *ns);
274
275/**
Radek Krejci5819f7c2019-05-31 14:53:29 +0200276 * @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 +0200277 *
Radek Krejci38d85362019-09-05 16:26:38 +0200278 * @param[in] node Data node for the @p value.
Radek Krejci084289f2019-07-09 17:35:30 +0200279 * @param[in] value String value to be parsed, must not be NULL.
Michal Vaskof03ed032020-03-04 13:31:44 +0100280 * @param[in] value_len Length of the give @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100281 * @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 +0200282 * @param[in] second Flag for the second call after returning LY_EINCOMPLETE
Radek Krejci084289f2019-07-09 17:35:30 +0200283 * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string.
Radek Krejciaca74032019-06-04 08:53:06 +0200284 * @param[in] parser Parser's data for @p get_prefix
Michal Vasko90932a92020-02-12 14:33:03 +0100285 * @param[in] format Input format of @p value.
Michal Vaskof03ed032020-03-04 13:31:44 +0100286 * @param[in] tree Data tree (e.g. when validating RPC/Notification) where the required
Radek Krejcie553e6d2019-06-07 15:33:18 +0200287 * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete,
288 * then LY_EINCOMPLETE can be returned.
289 * @return LY_SUCCESS on success
290 * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation.
291 * @return LY_ERR value if an error occurred.
Radek Krejcie7b95092019-05-15 11:03:07 +0200292 */
Michal Vasko90932a92020-02-12 14:33:03 +0100293LY_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 +0100294 ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format, const struct lyd_node *tree);
Radek Krejcie7b95092019-05-15 11:03:07 +0200295
Michal Vasko004d3152020-06-11 19:59:22 +0200296/* similar to lyd_value_parse except can be used just to store the value, hence does also not support a second call */
297LY_ERR lyd_value_store(struct lyd_value *val, const struct lysc_node *schema, const char *value, size_t value_len,
298 int *dynamic, ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format);
299
Radek Krejcie7b95092019-05-15 11:03:07 +0200300/**
Michal Vasko9f96a052020-03-10 09:41:45 +0100301 * @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 +0200302 *
Michal Vasko8d544252020-03-02 10:19:52 +0100303 * @param[in] ctx libyang context.
Michal Vasko9f96a052020-03-10 09:41:45 +0100304 * @param[in] meta Metadata for the @p value.
Radek Krejci38d85362019-09-05 16:26:38 +0200305 * @param[in] value String value to be parsed, must not be NULL.
Michal Vaskof03ed032020-03-04 13:31:44 +0100306 * @param[in] value_len Length of the give @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100307 * @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 +0200308 * @param[in] second Flag for the second call after returning LY_EINCOMPLETE
309 * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string.
310 * @param[in] parser Parser's data for @p get_prefix
311 * @param[in] format Input format of the data.
Michal Vasko8d544252020-03-02 10:19:52 +0100312 * @param[in] ctx_snode Context node for value resolution in schema.
Michal Vaskof03ed032020-03-04 13:31:44 +0100313 * @param[in] tree Data tree (e.g. when validating RPC/Notification) where the required
Radek Krejci38d85362019-09-05 16:26:38 +0200314 * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete,
315 * then LY_EINCOMPLETE can be returned.
316 * @return LY_SUCCESS on success
317 * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation.
318 * @return LY_ERR value if an error occurred.
319 */
Michal Vasko41586352020-07-13 13:54:25 +0200320LY_ERR lyd_value_parse_meta(const struct ly_ctx *ctx, struct lyd_meta *meta, const char *value, size_t value_len,
321 int *dynamic, int second, ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format,
Michal Vaskof03ed032020-03-04 13:31:44 +0100322 const struct lysc_node *ctx_snode, const struct lyd_node *tree);
Radek Krejci38d85362019-09-05 16:26:38 +0200323
Michal Vaskof937cfe2020-08-03 16:07:12 +0200324/* generic function lys_value_validate */
325LY_ERR _lys_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len,
326 ly_clb_resolve_prefix resolve_prefix, void *prefix_data, LYD_FORMAT format);
327
Radek Krejci38d85362019-09-05 16:26:38 +0200328/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200329 * @brief Parse XML string as YANG data tree.
330 *
331 * @param[in] ctx libyang context
Michal Vasko63f3d842020-07-08 10:10:14 +0200332 * @param[in] in Input structure.
Radek Krejci7931b192020-06-25 17:05:03 +0200333 * @param[in] parse_options Options for parser, see @ref dataparseroptions.
334 * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions.
Michal Vaskob1b5c262020-03-05 14:29:47 +0100335 * @param[out] tree Parsed data tree. Note that NULL can be a valid result.
Michal Vasko9f96a052020-03-10 09:41:45 +0100336 * @return LY_ERR value.
Radek Krejcie7b95092019-05-15 11:03:07 +0200337 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200338LY_ERR lyd_parse_xml_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options,
339 struct lyd_node **tree);
Michal Vasko9f96a052020-03-10 09:41:45 +0100340
341/**
342 * @brief Parse XML string as YANG RPC/action invocation.
343 *
Radek Krejci7931b192020-06-25 17:05:03 +0200344 * Optional \<rpc\> envelope element is accepted if present. It is [checked](https://tools.ietf.org/html/rfc6241#section-4.1) and all
345 * 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
346 * 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 +0100347 *
348 * @param[in] ctx libyang context.
Michal Vasko63f3d842020-07-08 10:10:14 +0200349 * @param[in] in Input structure.
Michal Vaskob36053d2020-03-26 15:49:30 +0100350 * @param[out] tree Parsed full RPC/action tree.
Michal Vaskocc048b22020-03-27 15:52:38 +0100351 * @param[out] op Optional pointer to the actual operation. Useful mainly for action.
Michal Vasko9f96a052020-03-10 09:41:45 +0100352 * @return LY_ERR value.
353 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200354LY_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 +0200355
356/**
Michal Vaskoa8edff02020-03-27 14:47:01 +0100357 * @brief Parse XML string as YANG notification.
358 *
359 * Optional \<notification\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc5277#page-25)
360 * and parsed. Specifically, its namespace and the child \<eventTime\> element and its value.
361 *
362 * @param[in] ctx libyang context.
Michal Vasko63f3d842020-07-08 10:10:14 +0200363 * @param[in] in Input structure.
Michal Vaskoa8edff02020-03-27 14:47:01 +0100364 * @param[out] tree Parsed full notification tree.
Michal Vaskocc048b22020-03-27 15:52:38 +0100365 * @param[out] op Optional pointer to the actual notification. Useful mainly for nested notifications.
Michal Vaskoa8edff02020-03-27 14:47:01 +0100366 * @return LY_ERR value.
367 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200368LY_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 +0100369
370/**
Michal Vasko1ce933a2020-03-30 12:38:22 +0200371 * @brief Parse XML string as YANG RPC/action reply.
372 *
373 * Optional \<rpc-reply\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc6241#section-4.2)
374 * and all its XML attributes parsed.
375 *
376 * @param[in] request Data tree of the RPC/action request.
Michal Vasko63f3d842020-07-08 10:10:14 +0200377 * @param[in] in Input structure.
Michal Vasko1ce933a2020-03-30 12:38:22 +0200378 * @param[out] tree Parsed full reply tree. It always includes duplicated operation and parents of the @p request.
379 * @param[out] op Optional pointer to the reply operation. Useful mainly for action.
380 * @return LY_ERR value.
381 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200382LY_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 +0200383
384/**
Michal Vasko60ea6352020-06-29 13:39:39 +0200385 * @brief Parse binary data as YANG data tree.
386 *
387 * @param[in] ctx libyang context
Michal Vasko63f3d842020-07-08 10:10:14 +0200388 * @param[in] in Input structure.
Radek Krejci7931b192020-06-25 17:05:03 +0200389 * @param[in] parse_options Options for parser, see @ref dataparseroptions.
390 * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions.
Michal Vasko60ea6352020-06-29 13:39:39 +0200391 * @param[out] tree Parsed data tree. Note that NULL can be a valid result.
Michal Vasko60ea6352020-06-29 13:39:39 +0200392 * @return LY_ERR value.
393 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200394LY_ERR lyd_parse_lyb_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options,
395 struct lyd_node **tree);
Michal Vasko60ea6352020-06-29 13:39:39 +0200396
397/**
398 * @brief Parse binary data as YANG RPC/action invocation.
399 *
400 * @param[in] ctx libyang context.
Michal Vasko63f3d842020-07-08 10:10:14 +0200401 * @param[in] in Input structure.
Michal Vasko60ea6352020-06-29 13:39:39 +0200402 * @param[out] tree Parsed full RPC/action tree.
403 * @param[out] op Optional pointer to the actual operation. Useful mainly for action.
Michal Vasko60ea6352020-06-29 13:39:39 +0200404 * @return LY_ERR value.
405 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200406LY_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 +0200407
408/**
409 * @brief Parse binary data as YANG notification.
410 *
411 * @param[in] ctx libyang context.
Michal Vasko63f3d842020-07-08 10:10:14 +0200412 * @param[in] in Input structure.
Michal Vasko60ea6352020-06-29 13:39:39 +0200413 * @param[out] tree Parsed full notification tree.
414 * @param[out] op Optional pointer to the actual notification. Useful mainly for nested notifications.
Michal Vasko60ea6352020-06-29 13:39:39 +0200415 * @return LY_ERR value.
416 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200417LY_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 +0200418
419/**
420 * @brief Parse binary data as YANG RPC/action reply.
421 *
422 * @param[in] request Data tree of the RPC/action request.
Michal Vasko63f3d842020-07-08 10:10:14 +0200423 * @param[in] in Input structure.
Michal Vasko60ea6352020-06-29 13:39:39 +0200424 * @param[out] tree Parsed full reply tree. It always includes duplicated operation and parents of the @p request.
425 * @param[out] op Optional pointer to the reply operation. Useful mainly for action.
Michal Vasko60ea6352020-06-29 13:39:39 +0200426 * @return LY_ERR value.
427 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200428LY_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 +0200429
430/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200431 * @defgroup datahash Data nodes hash manipulation
432 * @ingroup datatree
433 */
434
435/**
Radek Krejci1f05b6a2019-07-18 16:15:06 +0200436 * @brief Generate hash for the node.
437 *
438 * @param[in] node Data node to (re)generate hash value.
439 * @return LY_ERR value.
440 */
441LY_ERR lyd_hash(struct lyd_node *node);
442
443/**
444 * @brief Insert hash of the node into the hash table of its parent.
445 *
446 * @param[in] node Data node which hash will be inserted into the lyd_node_inner::children_hash hash table of its parent.
447 * @return LY_ERR value.
448 */
449LY_ERR lyd_insert_hash(struct lyd_node *node);
450
451/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200452 * @brief Maintain node's parent's children hash table when unlinking the node.
453 *
454 * When completely freeing data tree, it is expected to free the parent's children hash table first, at once.
455 *
456 * @param[in] node The data node being unlinked from its parent.
457 */
458void lyd_unlink_hash(struct lyd_node *node);
459
460/** @} datahash */
461
Radek Krejci084289f2019-07-09 17:35:30 +0200462/**
Michal Vaskob1b5c262020-03-05 14:29:47 +0100463 * @brief Iterate over implemented modules for functions that accept specific modules or the whole context.
464 *
465 * @param[in] tree Data tree.
Michal Vasko26e80012020-07-08 10:55:46 +0200466 * @param[in] module Selected module, NULL for all.
Michal Vaskob1b5c262020-03-05 14:29:47 +0100467 * @param[in] ctx Context, NULL for selected modules.
468 * @param[in,out] i Iterator, set to 0 on first call.
469 * @param[out] first First sibling of the returned module.
470 * @return Next module.
471 * @return NULL if all modules were traversed.
472 */
Michal Vasko26e80012020-07-08 10:55:46 +0200473const struct lys_module *lyd_mod_next_module(struct lyd_node *tree, const struct lys_module *module,
Michal Vaskob1b5c262020-03-05 14:29:47 +0100474 const struct ly_ctx *ctx, uint32_t *i, struct lyd_node **first);
475
476/**
477 * @brief Iterate over modules for functions that want to traverse all the top-level data.
478 *
479 * @param[in,out] next Pointer to the next module data, set to first top-level sibling on first call.
480 * @param[out] first First sibling of the returned module.
481 * @return Next module.
482 * @return NULL if all modules were traversed.
483 */
484const struct lys_module *lyd_data_next_module(struct lyd_node **next, struct lyd_node **first);
485
Michal Vasko9f96a052020-03-10 09:41:45 +0100486/**
487 * @brief Check that a list has all its keys.
488 *
489 * @param[in] node List to check.
Michal Vasko44685da2020-03-17 15:38:06 +0100490 * @return LY_SUCCESS on success.
491 * @return LY_ENOT on a missing key.
Michal Vasko9f96a052020-03-10 09:41:45 +0100492 */
493LY_ERR lyd_parse_check_keys(struct lyd_node *node);
494
Michal Vasko60ea6352020-06-29 13:39:39 +0200495/**
496 * @brief Set data flags for a newly parsed node.
497 *
498 * @param[in] node Node to use.
499 * @param[in] when_check Set of nodes with unresolved when.
500 * @param[in,out] meta Node metadata, may be removed from.
501 * @param[in] options Parse options.
502 */
503void lyd_parse_set_data_flags(struct lyd_node *node, struct ly_set *when_check, struct lyd_meta **meta, int options);
504
505/**
506 * @brief Free value prefixes.
507 *
508 * @param[in] ctx libyang context.
509 * @param[in] val_prefis Value prefixes to free, sized array (@ref sizedarrays).
510 */
511void ly_free_val_prefs(const struct ly_ctx *ctx, struct ly_prefix *val_prefs);
512
Michal Vaskod59035b2020-07-08 12:00:06 +0200513/**
514 * @brief Append all list key predicates to path.
515 *
516 * @param[in] node Node with keys to print.
517 * @param[in,out] buffer Buffer to print to.
518 * @param[in,out] buflen Current buffer length.
519 * @param[in,out] bufused Current number of characters used in @p buffer.
520 * @param[in] is_static Whether buffer is static or can be reallocated.
521 * @return LY_ERR
522 */
523LY_ERR lyd_path_list_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, int is_static);
524
Radek Krejcie7b95092019-05-15 11:03:07 +0200525#endif /* LY_TREE_DATA_INTERNAL_H_ */