1 /**
2  * @file validation.h
3  * @author Radek Krejci <rkrejci@cesnet.cz>
4  * @brief Data tree validation for libyang
5  *
6  * Copyright (c) 2015 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_VALIDATION_H_
16 #define LY_VALIDATION_H_
17 
18 #include "libyang.h"
19 #include "resolve.h"
20 #include "tree_data.h"
21 
22 /**
23  * @brief Check, that the data node of the given schema node can even appear in a data tree.
24  *
25  * Checks included:
26  * - data node is not disabled via if-features
27  * - data node's when-stmt condition - if false, 1 is returned and ly_vecode is set to LYE_NOCOND,
28  * - data node is not status in case of edit-config content (options includes LYD_OPT_EDIT)
29  * - data node is in correct place (options includes LYD_OPT_RPC or LYD_OPT_RPCREPLY), since elements order matters
30  *   in RPCs and RPC replies.
31  *
32  * @param[in] node Data tree node to be checked.
33  * @param[in] options Parser options, see @ref parseroptions.
34  * @param[in] check_node_order Whether to check node order in operations if the format supports it.
35  * @param[out] unres Structure to store unresolved items into. Cannot be NULL.
36  * @return 0 on success, non-zero on error.
37  */
38 int lyv_data_context(struct lyd_node *node, int options, int check_node_order, struct unres_data *unres);
39 
40 /**
41  * @brief Validate if the node's content is valid in the context it is placed.
42  *
43  * Expects that the node is already interconnected to the target tree and all its children
44  * are already resolved. All currently connected siblings are included to the tests.
45  *
46  * @param[in] node Data tree node to be checked.
47  * @param[in] options Parser options, see @ref parseroptions.
48  * @param[out] unres Structure to store unresolved items into. Cannot be NULL.
49  * @return 0 on success, non-zero on error.
50  */
51 int lyv_data_content(struct lyd_node *node, int options, struct unres_data *unres);
52 
53 /**
54  * @brief Check list unique leaves.
55  *
56  * @param[in] list List node to be checked.
57  * @return 0 on success, non-zero on error.
58  */
59 int lyv_data_unique(struct lyd_node *list);
60 
61 /**
62  * @brief Check for list/leaflist instance duplications.
63  *
64  * Function is used by lyv_data_context for inner lists/leaflists. Due to optimization, the function
65  * is used separatedly for the top-level lists/leaflists.
66  *
67  * @param[in] node List/leaflist node to be checked.
68  * @param[in] start First sibling of the \p node for searching for other instances of the same list/leaflist.
69  *                  Used for optimization, but can be NULL and the first sibling will be found.
70  * @return 0 on success, non-zero on error.
71  */
72 int lyv_data_dup(struct lyd_node *node, struct lyd_node *start);
73 
74 /**
75  * @brief Validate if the \p node has a sibling from another choice's case. It can report an error or automatically
76  * remove the nodes from other case than \p node.
77  *
78  * @param[in] node Data tree node to be checked.
79  * @param[in] schemanode Alternative to \p node (node is preferred), schema of the (potential) node
80  * @param[in,out] first_sibling The first sibling of the node where the searching will always start. It is updated
81  * when the first_sibling is (even repeatedly) autodeleted.
82  * @param[in] autodelete Flag to select if the conflicting nodes are supposed to be removed silently or reported.
83  * @param[in] nodel Exception for autodelete, if the \p nodel node would be removed, report an error.
84  * @return 0 on success (possible implicit autodelete), 1 on reported autodelete.
85  */
86 int lyv_multicases(struct lyd_node *node, struct lys_node *schemanode, struct lyd_node **first_sibling, int autodelete,
87                    struct lyd_node *nodel);
88 
89 #endif /* LY_VALIDATION_H_ */
90