blob: 15fc4ad33470487f86294a362efeafc9088b0956 [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
11 *
12 * 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
Michal Vaskocf024702015-10-08 15:01:42 +020027 * - data node is not disabled via an unsatisfied when condition
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.
Michal Vaskocf024702015-10-08 15:01:42 +020034 * @param[in] line Optional line of the input to be printed in case of an error.
35 * @param[out] unres Structure to store unresolved items into. Can be NULL.
Radek Krejcieab784a2015-08-27 09:56:53 +020036 * @return EXIT_SUCCESS or EXIT_FAILURE with ly_errno set.
Radek Krejcib1c12512015-08-11 11:22:04 +020037 */
Michal Vasko1e62a092015-12-01 12:27:20 +010038int lyv_data_context(const struct lyd_node *node, int options, unsigned int line, struct unres_data *unres);
Radek Krejcieab784a2015-08-27 09:56:53 +020039
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.
Radek Krejcieab784a2015-08-27 09:56:53 +020047 * @param[in] options Parser options, see @ref parseroptions.
Michal Vaskocf024702015-10-08 15:01:42 +020048 * @param[in] line Optional line of the input to be printed in case of an error.
49 * @param[out] unres Structure to store unresolved items into. Can be NULL.
Radek Krejcieab784a2015-08-27 09:56:53 +020050 * @return EXIT_SUCCESS or EXIT_FAILURE with set ly_errno. If EXIT_FAILURE is returned
51 * but ly_errno is not set, the issue was internally resolved and caller is supposed to
52 * unlink and free the node and continue;
53 */
Michal Vaskocf024702015-10-08 15:01:42 +020054int lyv_data_content(struct lyd_node *node, int options, unsigned int line, struct unres_data *unres);
Radek Krejcib1c12512015-08-11 11:22:04 +020055
Radek Krejci46c4cd72016-01-21 15:13:52 +010056/**
57 * @brief Validate the node's value. Applies only to referrence values where the validity can change by
58 * modifying a value/tree outside the node itself (leafrefs).
59 *
60 * @param[in] node Data tree node to be checked.
61 * @param[in] options Parser options, see @ref parseroptions.
62 * @return EXIT_SUCCESS or EXIT_FAILURE with ly_errno set.
63 */
64int lyv_data_value(struct lyd_node *node, int options);
65
Radek Krejcib1c12512015-08-11 11:22:04 +020066#endif /* LY_VALIDATION_H_ */