Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 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 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame^] | 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 |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef LY_VALIDATION_H_ |
| 16 | #define LY_VALIDATION_H_ |
| 17 | |
| 18 | #include "libyang.h" |
Michal Vasko | cf02470 | 2015-10-08 15:01:42 +0200 | [diff] [blame] | 19 | #include "resolve.h" |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 20 | #include "tree_data.h" |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 21 | |
| 22 | /** |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 23 | * @brief Check, that the data node of the given schema node can even appear in a data tree. |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 24 | * |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 25 | * Checks included: |
| 26 | * - data node is not disabled via if-features |
Michal Vasko | cf02470 | 2015-10-08 15:01:42 +0200 | [diff] [blame] | 27 | * - data node is not disabled via an unsatisfied when condition |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 28 | * - data node is not status in case of edit-config content (options includes LYD_OPT_EDIT) |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 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. |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 31 | * |
Michal Vasko | cf02470 | 2015-10-08 15:01:42 +0200 | [diff] [blame] | 32 | * @param[in] node Data tree node to be checked. |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 33 | * @param[in] options Parser options, see @ref parseroptions. |
Michal Vasko | cf02470 | 2015-10-08 15:01:42 +0200 | [diff] [blame] | 34 | * @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 Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 36 | * @return EXIT_SUCCESS or EXIT_FAILURE with ly_errno set. |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 37 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 38 | int lyv_data_context(const struct lyd_node *node, int options, unsigned int line, struct unres_data *unres); |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 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. |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 47 | * @param[in] options Parser options, see @ref parseroptions. |
Michal Vasko | cf02470 | 2015-10-08 15:01:42 +0200 | [diff] [blame] | 48 | * @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 Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 50 | * @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 Vasko | cf02470 | 2015-10-08 15:01:42 +0200 | [diff] [blame] | 54 | int lyv_data_content(struct lyd_node *node, int options, unsigned int line, struct unres_data *unres); |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 55 | |
Radek Krejci | 46c4cd7 | 2016-01-21 15:13:52 +0100 | [diff] [blame] | 56 | /** |
| 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 | */ |
| 64 | int lyv_data_value(struct lyd_node *node, int options); |
| 65 | |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 66 | #endif /* LY_VALIDATION_H_ */ |