blob: 439ad6cbf094c4f3ab2c3ee2974c1a785aa2ca52 [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 *
6 * Copyright (c) 2015 - 2019 CESNET, z.s.p.o.
7 *
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
18#include "tree_data.h"
Radek Krejciaca74032019-06-04 08:53:06 +020019#include "plugins_types.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020020
Michal Vasko52927e22020-03-16 17:26:14 +010021#include <stddef.h>
22
Michal Vasko004d3152020-06-11 19:59:22 +020023struct ly_path_predicate;
24
Radek Krejcie7b95092019-05-15 11:03:07 +020025/**
Michal Vaskob1b5c262020-03-05 14:29:47 +010026 * @brief Check whether a node to be deleted is the first top-level sibling.
27 *
28 * @param[in] first First sibling.
29 * @param[in] to_del Node to be deleted.
30 */
31#define LYD_DEL_IS_ROOT(first, to_del) (((first) == (to_del)) && !(first)->parent && !(first)->prev->next)
32
33/**
Michal Vasko5bfd4be2020-06-23 13:26:19 +020034 * @brief Shorthand for getting data children without its keys.
35 *
36 * @param[in] node Node, whose children to traverse.
37 * @return Node children, skipping any keys of a list.
38 */
39#define LYD_CHILD(node) lyd_node_children(node, LYD_CHILDREN_SKIP_KEYS)
40
41/**
Radek Krejcie7b95092019-05-15 11:03:07 +020042 * @brief Get address of a node's child pointer if any.
43 *
Radek Krejcie7b95092019-05-15 11:03:07 +020044 * @param[in] node Node to check.
Michal Vasko9b368d32020-02-14 13:53:31 +010045 * @return Address of the node's child member,
46 * @return NULL if there is no child pointer.
Radek Krejcie7b95092019-05-15 11:03:07 +020047 */
48struct lyd_node **lyd_node_children_p(struct lyd_node *node);
49
50/**
Michal Vasko9b368d32020-02-14 13:53:31 +010051 * @brief Create a term (leaf/leaf-list) node from a string value.
52 *
53 * Hash is calculated and new node flag is set.
Michal Vasko90932a92020-02-12 14:33:03 +010054 *
55 * @param[in] schema Schema node of the new data node.
56 * @param[in] value String value to be parsed.
Michal Vaskof03ed032020-03-04 13:31:44 +010057 * @param[in] value_len Length of @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +010058 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
59 * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string.
60 * @param[in] prefix_data User data for @p get_prefix.
61 * @param[in] format Input format of @p value.
62 * @param[out] node Created node.
63 * @return LY_SUCCESS on success.
64 * @return LY_EINCOMPLETE in case data tree is needed to finish the validation.
65 * @return LY_ERR value if an error occurred.
66 */
67LY_ERR lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, int *dynamic,
68 ly_clb_resolve_prefix get_prefix, void *prefix_data, LYD_FORMAT format, struct lyd_node **node);
69
70/**
Michal Vasko9b368d32020-02-14 13:53:31 +010071 * @brief Create a term (leaf/leaf-list) node from a parsed value by duplicating it.
72 *
73 * Hash is calculated and new node flag is set.
74 *
75 * @param[in] schema Schema node of the new data node.
76 * @param[in] val Parsed value to use.
77 * @param[out] node Created node.
78 * @return LY_SUCCESS on success.
79 * @return LY_ERR value if an error occurred.
80 */
81LY_ERR lyd_create_term2(const struct lysc_node *schema, const struct lyd_value *val, struct lyd_node **node);
82
83/**
84 * @brief Create an inner (container/list/RPC/action/notification) node.
85 *
86 * Hash is calculated and new node flag is set except
87 * for list with keys, when the hash is not calculated!
88 * Also, non-presence container has its default flag set.
Michal Vasko90932a92020-02-12 14:33:03 +010089 *
90 * @param[in] schema Schema node of the new data node.
91 * @param[out] node Created node.
92 * @return LY_SUCCESS on success.
93 * @return LY_ERR value if an error occurred.
94 */
95LY_ERR lyd_create_inner(const struct lysc_node *schema, struct lyd_node **node);
96
97/**
Michal Vasko9b368d32020-02-14 13:53:31 +010098 * @brief Create a list with all its keys (cannot be used for key-less list).
99 *
100 * Hash is calculated and new node flag is set.
Michal Vasko90932a92020-02-12 14:33:03 +0100101 *
102 * @param[in] schema Schema node of the new data node.
Michal Vasko004d3152020-06-11 19:59:22 +0200103 * @param[in] predicates Compiled key list predicates.
Michal Vasko90932a92020-02-12 14:33:03 +0100104 * @param[out] node Created node.
105 * @return LY_SUCCESS on success.
106 * @return LY_ERR value if an error occurred.
107 */
Michal Vasko004d3152020-06-11 19:59:22 +0200108LY_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 +0100109
110/**
Michal Vasko9b368d32020-02-14 13:53:31 +0100111 * @brief Create an anyxml/anydata node.
112 *
113 * Hash is calculated and flags are properly set based on @p is_valid.
Michal Vasko90932a92020-02-12 14:33:03 +0100114 *
115 * @param[in] schema Schema node of the new data node.
116 * @param[in] value Value of the any node, is directly assigned into the data node.
117 * @param[in] value_type Value type of the value.
118 * @param[out] node Created node.
119 * @return LY_SUCCESS on success.
120 * @return LY_ERR value if an error occurred.
121 */
Michal Vasko9b368d32020-02-14 13:53:31 +0100122LY_ERR lyd_create_any(const struct lysc_node *schema, const void *value, LYD_ANYDATA_VALUETYPE value_type,
123 struct lyd_node **node);
Michal Vasko90932a92020-02-12 14:33:03 +0100124
125/**
Michal Vasko52927e22020-03-16 17:26:14 +0100126 * @brief Create an opaque node.
127 *
128 * @param[in] ctx libyang context.
129 * @param[in] name Element name.
130 * @param[in] name_len Length of @p name, must be set correctly.
131 * @param[in] value String value to be parsed.
132 * @param[in] value_len Length of @p value, must be set correctly.
133 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
134 * @param[in] format Input format of @p value and @p ns.
135 * @param[in] val_prefs Possible value prefixes, array is spent.
136 * @param[in] prefix Element prefix.
137 * @param[in] pref_len Length of @p prefix, must be set correctly.
138 * @param[in] ns Node namespace, meaning depends on @p format.
139 * @param[out] node Created node.
140 * @return LY_SUCCESS on success.
141 * @return LY_ERR value if an error occurred.
142 */
143LY_ERR lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_len, const char *value, size_t value_len,
144 int *dynamic, LYD_FORMAT format, struct ly_prefix *val_prefs, const char *prefix, size_t pref_len,
145 const char *ns, struct lyd_node **node);
146
147/**
Michal Vasko90932a92020-02-12 14:33:03 +0100148 * @brief Find the key after which to insert the new key.
149 *
150 * @param[in] first_sibling List first sibling.
151 * @param[in] new_key Key that will be inserted.
152 * @return Key to insert after.
153 * @return NULL if the new key should be first.
154 */
155struct lyd_node *lyd_get_prev_key_anchor(const struct lyd_node *first_sibling, const struct lysc_node *new_key);
156
157/**
158 * @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 +0100159 * is found, inserted into, and if it is the last key, parent list hash is calculated. Also, in case we are inserting
160 * into top-level siblings, insert it as the last sibling of all the module data siblings. Otherwise it is inserted at
161 * the very last place.
Michal Vasko90932a92020-02-12 14:33:03 +0100162 *
Michal Vasko9b368d32020-02-14 13:53:31 +0100163 * @param[in] parent Parent to insert into, NULL for top-level sibling.
164 * @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 +0100165 * @param[in] node Individual node (without siblings) to insert.
166 */
Michal Vasko9b368d32020-02-14 13:53:31 +0100167void lyd_insert_node(struct lyd_node *parent, struct lyd_node **first_sibling, struct lyd_node *node);
Michal Vasko90932a92020-02-12 14:33:03 +0100168
169/**
Michal Vasko52927e22020-03-16 17:26:14 +0100170 * @brief Create and insert a metadata (last) into a parent.
Michal Vasko90932a92020-02-12 14:33:03 +0100171 *
Michal Vasko52927e22020-03-16 17:26:14 +0100172 * @param[in] parent Parent of the metadata, can be NULL.
Michal Vasko9f96a052020-03-10 09:41:45 +0100173 * @param[in,out] meta Metadata list to add at its end if @p parent is NULL, returned created attribute.
174 * @param[in] mod Metadata module (with the annotation definition).
Michal Vasko90932a92020-02-12 14:33:03 +0100175 * @param[in] name Attribute name.
Michal Vaskof03ed032020-03-04 13:31:44 +0100176 * @param[in] name_len Length of @p name, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100177 * @param[in] value String value to be parsed.
Michal Vaskof03ed032020-03-04 13:31:44 +0100178 * @param[in] value_len Length of @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100179 * @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 +0100180 * @param[in] resolve_prefix Parser-specific getter to resolve prefixes used in the @p value string.
Michal Vasko90932a92020-02-12 14:33:03 +0100181 * @param[in] prefix_data User data for @p get_prefix.
182 * @param[in] format Input format of @p value.
Michal Vasko8d544252020-03-02 10:19:52 +0100183 * @param[in] ctx_snode Context node for value resolution in schema.
Michal Vasko90932a92020-02-12 14:33:03 +0100184 * @return LY_SUCCESS on success.
185 * @return LY_EINCOMPLETE in case data tree is needed to finish the validation.
186 * @return LY_ERR value if an error occurred.
187 */
Michal Vasko9f96a052020-03-10 09:41:45 +0100188LY_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 +0100189 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 +0100190 void *prefix_data, LYD_FORMAT format, const struct lysc_node *ctx_snode);
Michal Vasko90932a92020-02-12 14:33:03 +0100191
192/**
Michal Vasko52927e22020-03-16 17:26:14 +0100193 * @brief Create and insert a generic attribute (last) into a parent.
194 *
195 * @param[in] parent Parent of the attribute, can be NULL.
196 * @param[in,out] attr Attribute list to add at its end if @p parent is NULL, returned created attribute.
197 * @param[in] ctx libyang context.
198 * @param[in] name Attribute name.
199 * @param[in] name_len Length of @p name, must be set correctly.
200 * @param[in] value String value to be parsed.
201 * @param[in] value_len Length of @p value, must be set correctly.
202 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
203 * @param[in] format Input format of @p value and @p ns.
204 * @param[in] val_prefs Possible value prefixes, array is spent.
205 * @param[in] prefix Attribute prefix.
206 * @param[in] prefix_len Attribute prefix length.
207 * @param[in] ns Attribute namespace, meaning depends on @p format.
208 * @return LY_SUCCESS on success.
209 * @return LY_ERR value if an error occurred.
210 */
211LY_ERR ly_create_attr(struct lyd_node *parent, struct ly_attr **attr, const struct ly_ctx *ctx, const char *name,
212 size_t name_len, const char *value, size_t value_len, int *dynamic, LYD_FORMAT format,
213 struct ly_prefix *val_prefs, const char *prefix, size_t prefix_len, const char *ns);
214
215/**
Radek Krejci5819f7c2019-05-31 14:53:29 +0200216 * @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 +0200217 *
Radek Krejci38d85362019-09-05 16:26:38 +0200218 * @param[in] node Data node for the @p value.
Radek Krejci084289f2019-07-09 17:35:30 +0200219 * @param[in] value String value to be parsed, must not be NULL.
Michal Vaskof03ed032020-03-04 13:31:44 +0100220 * @param[in] value_len Length of the give @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100221 * @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 +0200222 * @param[in] second Flag for the second call after returning LY_EINCOMPLETE
Radek Krejci084289f2019-07-09 17:35:30 +0200223 * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string.
Radek Krejciaca74032019-06-04 08:53:06 +0200224 * @param[in] parser Parser's data for @p get_prefix
Michal Vasko90932a92020-02-12 14:33:03 +0100225 * @param[in] format Input format of @p value.
Michal Vaskof03ed032020-03-04 13:31:44 +0100226 * @param[in] tree Data tree (e.g. when validating RPC/Notification) where the required
Radek Krejcie553e6d2019-06-07 15:33:18 +0200227 * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete,
228 * then LY_EINCOMPLETE can be returned.
229 * @return LY_SUCCESS on success
230 * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation.
231 * @return LY_ERR value if an error occurred.
Radek Krejcie7b95092019-05-15 11:03:07 +0200232 */
Michal Vasko90932a92020-02-12 14:33:03 +0100233LY_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 +0100234 ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format, const struct lyd_node *tree);
Radek Krejcie7b95092019-05-15 11:03:07 +0200235
Michal Vasko004d3152020-06-11 19:59:22 +0200236/* similar to lyd_value_parse except can be used just to store the value, hence does also not support a second call */
237LY_ERR lyd_value_store(struct lyd_value *val, const struct lysc_node *schema, const char *value, size_t value_len,
238 int *dynamic, ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format);
239
Radek Krejcie7b95092019-05-15 11:03:07 +0200240/**
Michal Vasko9f96a052020-03-10 09:41:45 +0100241 * @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 +0200242 *
Michal Vasko8d544252020-03-02 10:19:52 +0100243 * @param[in] ctx libyang context.
Michal Vasko9f96a052020-03-10 09:41:45 +0100244 * @param[in] meta Metadata for the @p value.
Radek Krejci38d85362019-09-05 16:26:38 +0200245 * @param[in] value String value to be parsed, must not be NULL.
Michal Vaskof03ed032020-03-04 13:31:44 +0100246 * @param[in] value_len Length of the give @p value, must be set correctly.
Michal Vasko90932a92020-02-12 14:33:03 +0100247 * @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 +0200248 * @param[in] second Flag for the second call after returning LY_EINCOMPLETE
249 * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string.
250 * @param[in] parser Parser's data for @p get_prefix
251 * @param[in] format Input format of the data.
Michal Vasko8d544252020-03-02 10:19:52 +0100252 * @param[in] ctx_snode Context node for value resolution in schema.
Michal Vaskof03ed032020-03-04 13:31:44 +0100253 * @param[in] tree Data tree (e.g. when validating RPC/Notification) where the required
Radek Krejci38d85362019-09-05 16:26:38 +0200254 * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete,
255 * then LY_EINCOMPLETE can be returned.
256 * @return LY_SUCCESS on success
257 * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation.
258 * @return LY_ERR value if an error occurred.
259 */
Michal Vasko9f96a052020-03-10 09:41:45 +0100260LY_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 +0100261 int second, ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format,
Michal Vaskof03ed032020-03-04 13:31:44 +0100262 const struct lysc_node *ctx_snode, const struct lyd_node *tree);
Radek Krejci38d85362019-09-05 16:26:38 +0200263
264/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200265 * @brief Parse XML string as YANG data tree.
266 *
267 * @param[in] ctx libyang context
Michal Vasko9f96a052020-03-10 09:41:45 +0100268 * @param[in] data Pointer to the XML data to parse.
Radek Krejcie7b95092019-05-15 11:03:07 +0200269 * @param[in] options @ref dataparseroptions
Michal Vaskob1b5c262020-03-05 14:29:47 +0100270 * @param[out] tree Parsed data tree. Note that NULL can be a valid result.
Michal Vasko9f96a052020-03-10 09:41:45 +0100271 * @return LY_ERR value.
Radek Krejcie7b95092019-05-15 11:03:07 +0200272 */
Michal Vasko1bf09392020-03-27 12:38:10 +0100273LY_ERR lyd_parse_xml_data(const struct ly_ctx *ctx, const char *data, int options, struct lyd_node **tree);
Michal Vasko9f96a052020-03-10 09:41:45 +0100274
275/**
276 * @brief Parse XML string as YANG RPC/action invocation.
277 *
278 * Optional \<rpc\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc6241#section-4.1) and all
Michal Vaskoa8edff02020-03-27 14:47:01 +0100279 * its XML attributes parsed. In that case an RPC is expected to be parsed.
Michal Vasko9f96a052020-03-10 09:41:45 +0100280 *
281 * Can be followed by optional \<action\> envelope element, which is also
282 * [checked](https://tools.ietf.org/html/rfc7950#section-7.15.2) and then an action is expected to be parsed.
283 *
284 * @param[in] ctx libyang context.
285 * @param[in] data Pointer to the XML data to parse.
Michal Vaskob36053d2020-03-26 15:49:30 +0100286 * @param[out] tree Parsed full RPC/action tree.
Michal Vaskocc048b22020-03-27 15:52:38 +0100287 * @param[out] op Optional pointer to the actual operation. Useful mainly for action.
Michal Vasko9f96a052020-03-10 09:41:45 +0100288 * @return LY_ERR value.
289 */
Michal Vasko1bf09392020-03-27 12:38:10 +0100290LY_ERR lyd_parse_xml_rpc(const struct ly_ctx *ctx, const char *data, struct lyd_node **tree, struct lyd_node **op);
Radek Krejcie7b95092019-05-15 11:03:07 +0200291
292/**
Michal Vaskoa8edff02020-03-27 14:47:01 +0100293 * @brief Parse XML string as YANG notification.
294 *
295 * Optional \<notification\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc5277#page-25)
296 * and parsed. Specifically, its namespace and the child \<eventTime\> element and its value.
297 *
298 * @param[in] ctx libyang context.
299 * @param[in] data Pointer to the XML data to parse.
300 * @param[out] tree Parsed full notification tree.
Michal Vaskocc048b22020-03-27 15:52:38 +0100301 * @param[out] op Optional pointer to the actual notification. Useful mainly for nested notifications.
Michal Vaskoa8edff02020-03-27 14:47:01 +0100302 * @return LY_ERR value.
303 */
304LY_ERR lyd_parse_xml_notif(const struct ly_ctx *ctx, const char *data, struct lyd_node **tree, struct lyd_node **ntf);
305
306/**
Michal Vasko1ce933a2020-03-30 12:38:22 +0200307 * @brief Parse XML string as YANG RPC/action reply.
308 *
309 * Optional \<rpc-reply\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc6241#section-4.2)
310 * and all its XML attributes parsed.
311 *
312 * @param[in] request Data tree of the RPC/action request.
313 * @param[in] data Pointer to the XML data to parse.
314 * @param[out] tree Parsed full reply tree. It always includes duplicated operation and parents of the @p request.
315 * @param[out] op Optional pointer to the reply operation. Useful mainly for action.
316 * @return LY_ERR value.
317 */
318LY_ERR lyd_parse_xml_reply(const struct lyd_node *request, const char *data, struct lyd_node **tree, struct lyd_node **op);
319
320/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200321 * @defgroup datahash Data nodes hash manipulation
322 * @ingroup datatree
323 */
324
325/**
Radek Krejci1f05b6a2019-07-18 16:15:06 +0200326 * @brief Generate hash for the node.
327 *
328 * @param[in] node Data node to (re)generate hash value.
329 * @return LY_ERR value.
330 */
331LY_ERR lyd_hash(struct lyd_node *node);
332
333/**
334 * @brief Insert hash of the node into the hash table of its parent.
335 *
336 * @param[in] node Data node which hash will be inserted into the lyd_node_inner::children_hash hash table of its parent.
337 * @return LY_ERR value.
338 */
339LY_ERR lyd_insert_hash(struct lyd_node *node);
340
341/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200342 * @brief Maintain node's parent's children hash table when unlinking the node.
343 *
344 * When completely freeing data tree, it is expected to free the parent's children hash table first, at once.
345 *
346 * @param[in] node The data node being unlinked from its parent.
347 */
348void lyd_unlink_hash(struct lyd_node *node);
349
350/** @} datahash */
351
Radek Krejci084289f2019-07-09 17:35:30 +0200352/**
Michal Vasko9b368d32020-02-14 13:53:31 +0100353 * @brief Find the node, in the list, satisfying the given restrictions.
354 * Does **not** use hashes - should not be used unless necessary for best performance.
355 *
356 * @param[in] first Starting sibling node for search, only succeeding ones are searched.
357 * @param[in] schema Schema node of the data node to find.
358 * @param[in] key_or_value Expected value depends on the type of @p schema:
359 * LYS_CONTAINER:
360 * LYS_ANYXML:
361 * LYS_ANYDATA:
362 * LYS_NOTIF:
363 * LYS_RPC:
364 * LYS_ACTION:
365 * NULL should be always set, will be ignored.
366 * LYS_LEAF:
367 * LYS_LEAFLIST:
368 * Optional restriction on the specific leaf(-list) value.
369 * LYS_LIST:
370 * Optional keys values of the matching list instances in the form of "[key1='val1'][key2='val2']...".
371 * The keys do not have to be ordered and not all keys need to be specified.
372 *
373 * Note that any explicit values (leaf, leaf-list or list key values) will be canonized first
374 * before comparison. But values that do not have a canonical value are expected to be in the
375 * JSON format!
376 * @param[in] val_len Optional length of the @p key_or_value argument in case it is not NULL-terminated string.
377 * @param[out] match Can be NULL, otherwise the found data node.
378 * @return LY_SUCCESS on success, @p match set.
379 * @return LY_ENOTFOUND if not found, @p match set to NULL.
380 * @return LY_ERR value if another error occurred.
381 */
382LY_ERR lyd_find_sibling_next2(const struct lyd_node *first, const struct lysc_node *schema, const char *key_or_value,
383 size_t val_len, struct lyd_node **match);
384
385/**
Michal Vaskob1b5c262020-03-05 14:29:47 +0100386 * @brief Iterate over implemented modules for functions that accept specific modules or the whole context.
387 *
388 * @param[in] tree Data tree.
389 * @param[in] modules Selected modules, NULL for all.
390 * @param[in] mod_count Count of @p modules.
391 * @param[in] ctx Context, NULL for selected modules.
392 * @param[in,out] i Iterator, set to 0 on first call.
393 * @param[out] first First sibling of the returned module.
394 * @return Next module.
395 * @return NULL if all modules were traversed.
396 */
397const struct lys_module *lyd_mod_next_module(struct lyd_node *tree, const struct lys_module **modules, int mod_count,
398 const struct ly_ctx *ctx, uint32_t *i, struct lyd_node **first);
399
400/**
401 * @brief Iterate over modules for functions that want to traverse all the top-level data.
402 *
403 * @param[in,out] next Pointer to the next module data, set to first top-level sibling on first call.
404 * @param[out] first First sibling of the returned module.
405 * @return Next module.
406 * @return NULL if all modules were traversed.
407 */
408const struct lys_module *lyd_data_next_module(struct lyd_node **next, struct lyd_node **first);
409
Michal Vasko9f96a052020-03-10 09:41:45 +0100410/**
411 * @brief Check that a list has all its keys.
412 *
413 * @param[in] node List to check.
Michal Vasko44685da2020-03-17 15:38:06 +0100414 * @return LY_SUCCESS on success.
415 * @return LY_ENOT on a missing key.
Michal Vasko9f96a052020-03-10 09:41:45 +0100416 */
417LY_ERR lyd_parse_check_keys(struct lyd_node *node);
418
Radek Krejcie7b95092019-05-15 11:03:07 +0200419#endif /* LY_TREE_DATA_INTERNAL_H_ */