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 |
Michal Vasko | 8de098c | 2016-02-26 10:00:25 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 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 |
Radek Krejci | 03b71f7 | 2016-03-16 11:10:09 +0100 | [diff] [blame] | 27 | * - data node's when-stmt condition - if false, EXIT_FAILURE is returned and ly_vecode is set to LYE_NOCOND, |
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. |
Radek Krejci | 03b71f7 | 2016-03-16 11:10:09 +0100 | [diff] [blame] | 34 | * @param[out] unres Structure to store unresolved items into. Can not be NULL. |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 35 | * @return EXIT_SUCCESS or EXIT_FAILURE with ly_errno set. |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 36 | */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 37 | int lyv_data_context(const struct lyd_node *node, int options, struct unres_data *unres); |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 38 | |
| 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 Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 46 | * @param[in] options Parser options, see @ref parseroptions. |
Radek Krejci | 0b7704f | 2016-03-18 12:16:14 +0100 | [diff] [blame] | 47 | * @param[out] unres Structure to store unresolved items into. Cannot be NULL. |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 48 | * @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 Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 52 | int lyv_data_content(struct lyd_node *node, int options, struct unres_data *unres); |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 53 | |
Radek Krejci | 46c4cd7 | 2016-01-21 15:13:52 +0100 | [diff] [blame] | 54 | /** |
Radek Krejci | 63b79c8 | 2016-08-10 10:09:33 +0200 | [diff] [blame] | 55 | * @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 | */ |
| 64 | int lyv_data_unique(struct lyd_node *node, struct lyd_node *start); |
| 65 | |
| 66 | /** |
Radek Krejci | 2d5525d | 2016-04-04 15:43:30 +0200 | [diff] [blame] | 67 | * @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 Krejci | 76fed2b | 2016-04-11 14:55:23 +0200 | [diff] [blame] | 71 | * @param[in] schemanode Alternative to \p node (node is preferred), schema of the (potential) node |
Radek Krejci | a1c33bf | 2016-09-07 12:38:49 +0200 | [diff] [blame^] | 72 | * @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 Krejci | 2d5525d | 2016-04-04 15:43:30 +0200 | [diff] [blame] | 74 | * @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 Krejci | a1c33bf | 2016-09-07 12:38:49 +0200 | [diff] [blame^] | 78 | int lyv_multicases(struct lyd_node *node, struct lys_node *schemanode, struct lyd_node **first_sibling, int autodelete, |
Radek Krejci | 76fed2b | 2016-04-11 14:55:23 +0200 | [diff] [blame] | 79 | struct lyd_node *nodel); |
Radek Krejci | 2d5525d | 2016-04-04 15:43:30 +0200 | [diff] [blame] | 80 | |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 81 | #endif /* LY_VALIDATION_H_ */ |