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 |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame^] | 27 | * - data node's when-stmt condition - if false, 1 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. |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame^] | 34 | * @param[out] unres Structure to store unresolved items into. Cannot be NULL. |
| 35 | * @return 0 on success, non-zero on error. |
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. |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame^] | 48 | * @return 0 on success, non-zero on error. |
Radek Krejci | eab784a | 2015-08-27 09:56:53 +0200 | [diff] [blame] | 49 | */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 50 | 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] | 51 | |
Radek Krejci | 46c4cd7 | 2016-01-21 15:13:52 +0100 | [diff] [blame] | 52 | /** |
Radek Krejci | 63b79c8 | 2016-08-10 10:09:33 +0200 | [diff] [blame] | 53 | * @brief check for list/leaflist uniqueness. |
| 54 | * |
| 55 | * Function is used by lyv_data_context for inner lists/leaflists. Due to optimization, the function |
| 56 | * is used separatedly for the top-level lists/leaflists. |
| 57 | * |
| 58 | * @param[in] node List/leaflist node to be checked. |
| 59 | * @param[in] start First sibling of the \p node for searching for other instances of the same list/leaflist. |
| 60 | * Used for optimization, but can be NULL and the first sibling will be found. |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame^] | 61 | * @return 0 on success, non-zero on error. |
Radek Krejci | 63b79c8 | 2016-08-10 10:09:33 +0200 | [diff] [blame] | 62 | */ |
| 63 | int lyv_data_unique(struct lyd_node *node, struct lyd_node *start); |
| 64 | |
| 65 | /** |
Radek Krejci | 2d5525d | 2016-04-04 15:43:30 +0200 | [diff] [blame] | 66 | * @brief Validate if the \p node has a sibling from another choice's case. It can report an error or automatically |
| 67 | * remove the nodes from other case than \p node. |
| 68 | * |
| 69 | * @param[in] node Data tree node to be checked. |
Radek Krejci | 76fed2b | 2016-04-11 14:55:23 +0200 | [diff] [blame] | 70 | * @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] | 71 | * @param[in,out] first_sibling The first sibling of the node where the searching will always start. It is updated |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame^] | 72 | * when the first_sibling is (even repeatedly) autodeleted. |
| 73 | * @param[in] autodelete Flag to select if the conflicting nodes are supposed to be removed silently or reported. |
| 74 | * @param[in] nodel Exception for autodelete, if the \p nodel node would be removed, report an error. |
| 75 | * @return 0 on success (possible implicit autodelete), 1 on reported autodelete. |
Radek Krejci | 2d5525d | 2016-04-04 15:43:30 +0200 | [diff] [blame] | 76 | */ |
Radek Krejci | a1c33bf | 2016-09-07 12:38:49 +0200 | [diff] [blame] | 77 | 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] | 78 | struct lyd_node *nodel); |
Radek Krejci | 2d5525d | 2016-04-04 15:43:30 +0200 | [diff] [blame] | 79 | |
Radek Krejci | b1c1251 | 2015-08-11 11:22:04 +0200 | [diff] [blame] | 80 | #endif /* LY_VALIDATION_H_ */ |