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 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in |
| 15 | * the documentation and/or other materials provided with the |
| 16 | * distribution. |
| 17 | * 3. Neither the name of the Company nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this |
| 19 | * software without specific prior written permission. |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef LY_VALIDATION_H_ |
| 23 | #define LY_VALIDATION_H_ |
| 24 | |
| 25 | #include "libyang.h" |
Michal Vasko | cf02470 | 2015-10-08 15:01:42 +0200 | [diff] [blame] | 26 | #include "resolve.h" |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 27 | #include "tree_data.h" |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 28 | |
| 29 | /** |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 30 | * @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] | 31 | * |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 32 | * Checks included: |
| 33 | * - data node is not disabled via if-features |
Michal Vasko | cf02470 | 2015-10-08 15:01:42 +0200 | [diff] [blame] | 34 | * - data node is not disabled via an unsatisfied when condition |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 35 | * - 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] | 36 | * - data node is in correct place (options includes LYD_OPT_RPC or LYD_OPT_RPCREPLY), since elements order matters |
| 37 | * in RPCs and RPC replies. |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 38 | * |
Michal Vasko | cf02470 | 2015-10-08 15:01:42 +0200 | [diff] [blame] | 39 | * @param[in] node Data tree node to be checked. |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 40 | * @param[in] options Parser options, see @ref parseroptions. |
Michal Vasko | cf02470 | 2015-10-08 15:01:42 +0200 | [diff] [blame] | 41 | * @param[in] line Optional line of the input to be printed in case of an error. |
| 42 | * @param[out] unres Structure to store unresolved items into. Can be NULL. |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 43 | * @return EXIT_SUCCESS or EXIT_FAILURE with ly_errno set. |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 44 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 45 | 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] | 46 | |
| 47 | /** |
| 48 | * @brief Validate if the node's content is valid in the context it is placed. |
| 49 | * |
| 50 | * Expects that the node is already interconnected to the target tree and all its children |
| 51 | * are already resolved. All currently connected siblings are included to the tests. |
| 52 | * |
| 53 | * @param[in] node Data tree node to be checked. |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 54 | * @param[in] options Parser options, see @ref parseroptions. |
Michal Vasko | cf02470 | 2015-10-08 15:01:42 +0200 | [diff] [blame] | 55 | * @param[in] line Optional line of the input to be printed in case of an error. |
| 56 | * @param[out] unres Structure to store unresolved items into. Can be NULL. |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 57 | * @return EXIT_SUCCESS or EXIT_FAILURE with set ly_errno. If EXIT_FAILURE is returned |
| 58 | * but ly_errno is not set, the issue was internally resolved and caller is supposed to |
| 59 | * unlink and free the node and continue; |
| 60 | */ |
Michal Vasko | cf02470 | 2015-10-08 15:01:42 +0200 | [diff] [blame] | 61 | 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] | 62 | |
| 63 | #endif /* LY_VALIDATION_H_ */ |