blob: dfa72e96930d4e85c1fe5d5cf1843c23410ea857 [file] [log] [blame]
Radek Krejcib1c12512015-08-11 11:22:04 +02001/**
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 *
Radek Krejci54f6fb32016-02-24 12:56:39 +01008 * 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
Michal Vasko8de098c2016-02-26 10:00:25 +010011 *
Radek Krejci54f6fb32016-02-24 12:56:39 +010012 * https://opensource.org/licenses/BSD-3-Clause
Radek Krejcib1c12512015-08-11 11:22:04 +020013 */
14
15#ifndef LY_VALIDATION_H_
16#define LY_VALIDATION_H_
17
18#include "libyang.h"
Michal Vaskocf024702015-10-08 15:01:42 +020019#include "resolve.h"
Michal Vasko2d162e12015-09-24 14:33:29 +020020#include "tree_data.h"
Radek Krejcib1c12512015-08-11 11:22:04 +020021
22/**
Radek Krejcieab784a2015-08-27 09:56:53 +020023 * @brief Check, that the data node of the given schema node can even appear in a data tree.
Radek Krejcib1c12512015-08-11 11:22:04 +020024 *
Radek Krejcieab784a2015-08-27 09:56:53 +020025 * Checks included:
26 * - data node is not disabled via if-features
Radek Krejci03b71f72016-03-16 11:10:09 +010027 * - data node's when-stmt condition - if false, EXIT_FAILURE is returned and ly_vecode is set to LYE_NOCOND,
Radek Krejcieab784a2015-08-27 09:56:53 +020028 * - data node is not status in case of edit-config content (options includes LYD_OPT_EDIT)
Radek Krejci4a49bdf2016-01-12 17:17:01 +010029 * - 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.
Radek Krejcib1c12512015-08-11 11:22:04 +020031 *
Michal Vaskocf024702015-10-08 15:01:42 +020032 * @param[in] node Data tree node to be checked.
Radek Krejcieab784a2015-08-27 09:56:53 +020033 * @param[in] options Parser options, see @ref parseroptions.
Radek Krejci03b71f72016-03-16 11:10:09 +010034 * @param[out] unres Structure to store unresolved items into. Can not be NULL.
Radek Krejcieab784a2015-08-27 09:56:53 +020035 * @return EXIT_SUCCESS or EXIT_FAILURE with ly_errno set.
Radek Krejcib1c12512015-08-11 11:22:04 +020036 */
Radek Krejci48464ed2016-03-17 15:44:09 +010037int lyv_data_context(const struct lyd_node *node, int options, struct unres_data *unres);
Radek Krejcieab784a2015-08-27 09:56:53 +020038
39/**
40 * @brief Validate if the node's content is valid in the context it is placed.
41 *
42 * Expects that the node is already interconnected to the target tree and all its children
43 * are already resolved. All currently connected siblings are included to the tests.
44 *
45 * @param[in] node Data tree node to be checked.
Radek Krejcieab784a2015-08-27 09:56:53 +020046 * @param[in] options Parser options, see @ref parseroptions.
Radek Krejci0b7704f2016-03-18 12:16:14 +010047 * @param[out] unres Structure to store unresolved items into. Cannot be NULL.
Radek Krejcieab784a2015-08-27 09:56:53 +020048 * @return EXIT_SUCCESS or EXIT_FAILURE with set ly_errno. If EXIT_FAILURE is returned
49 * but ly_errno is not set, the issue was internally resolved and caller is supposed to
50 * unlink and free the node and continue;
51 */
Radek Krejci48464ed2016-03-17 15:44:09 +010052int lyv_data_content(struct lyd_node *node, int options, struct unres_data *unres);
Radek Krejcib1c12512015-08-11 11:22:04 +020053
Radek Krejci46c4cd72016-01-21 15:13:52 +010054/**
Radek Krejci63b79c82016-08-10 10:09:33 +020055 * @brief check for list/leaflist uniqueness.
56 *
57 * Function is used by lyv_data_context for inner lists/leaflists. Due to optimization, the function
58 * is used separatedly for the top-level lists/leaflists.
59 *
60 * @param[in] node List/leaflist node to be checked.
61 * @param[in] start First sibling of the \p node for searching for other instances of the same list/leaflist.
62 * Used for optimization, but can be NULL and the first sibling will be found.
63 */
64int lyv_data_unique(struct lyd_node *node, struct lyd_node *start);
65
66/**
Radek Krejci2d5525d2016-04-04 15:43:30 +020067 * @brief Validate if the \p node has a sibling from another choice's case. It can report an error or automatically
68 * remove the nodes from other case than \p node.
69 *
70 * @param[in] node Data tree node to be checked.
Radek Krejci76fed2b2016-04-11 14:55:23 +020071 * @param[in] schemanode Alternative to \p node (node is preferred), schema of the (potential) node
Radek Krejcia1c33bf2016-09-07 12:38:49 +020072 * @param[in,out] first_sibling The first sibling of the node where the searching will always start. It is updated
73 * when the first_sibling is (even repeatedly) autodeleted
Radek Krejci2d5525d2016-04-04 15:43:30 +020074 * @param[in] autodelete Flag to select if the conflicting nodes are supposed to be removed or reported
75 * @param[in] nodel Exception for autodelete, if the \p nodel node would be removed, error is reported instead.
76 * @return EXIT_SUCCESS or EXIT_FAILURE with set ly_errno.
77 */
Radek Krejcia1c33bf2016-09-07 12:38:49 +020078int lyv_multicases(struct lyd_node *node, struct lys_node *schemanode, struct lyd_node **first_sibling, int autodelete,
Radek Krejci76fed2b2016-04-11 14:55:23 +020079 struct lyd_node *nodel);
Radek Krejci2d5525d2016-04-04 15:43:30 +020080
Radek Krejcib1c12512015-08-11 11:22:04 +020081#endif /* LY_VALIDATION_H_ */