Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 1 | /** |
| 2 | * @file validation.h |
| 3 | * @author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * @brief Validation routines. |
| 5 | * |
| 6 | * Copyright (c) 2019 CESNET, z.s.p.o. |
| 7 | * |
| 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 |
| 13 | */ |
| 14 | |
| 15 | #ifndef LY_VALIDATION_H_ |
| 16 | #define LY_VALIDATION_H_ |
| 17 | |
| 18 | #include "log.h" |
Michal Vasko | fbed4ea | 2020-07-08 10:43:30 +0200 | [diff] [blame] | 19 | #include "parser_data.h" |
Michal Vasko | f937cfe | 2020-08-03 16:07:12 +0200 | [diff] [blame] | 20 | #include "plugins_types.h" |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 21 | #include "tree_data.h" |
| 22 | |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 23 | enum lyd_diff_op; |
| 24 | |
| 25 | /** |
| 26 | * @brief Add new changes into a diff. They are always merged. |
| 27 | * |
| 28 | * @param[in] node Node/subtree to add. |
| 29 | * @param[in] op Operation of the change. |
| 30 | * @param[in,out] diff Diff to update. |
| 31 | * @return LY_ERR value. |
| 32 | */ |
| 33 | LY_ERR lyd_val_diff_add(const struct lyd_node *node, enum lyd_diff_op op, struct lyd_node **diff); |
| 34 | |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 35 | /** |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 36 | * @brief Finish validation of nodes and attributes. Specifically, when (is processed first) and type validation. |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 37 | * |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 38 | * !! It is assumed autodeleted nodes cannot be in the unresolved node type set !! |
| 39 | * |
| 40 | * @param[in,out] tree Data tree, is updated if some nodes are autodeleted. |
| 41 | * @param[in] node_when Set with nodes with "when" conditions, can be NULL. |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 42 | * @param[in] node_types Set with nodes with unresolved types, can be NULL |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 43 | * @param[in] meta_types Set with metdata with unresolved types, can be NULL. |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 44 | * @param[in] format Format of the unresolved data. |
| 45 | * @param[in] get_prefix_clb Format-specific getter to resolve prefixes. |
| 46 | * @param[in] parser_data Parser's data for @p get_prefix_clb. |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 47 | * @param[in,out] diff Validation diff. |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 48 | * @return LY_ERR value. |
| 49 | */ |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 50 | LY_ERR lyd_validate_unres(struct lyd_node **tree, struct ly_set *node_when, struct ly_set *node_types, struct ly_set *meta_types, |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 51 | LYD_FORMAT format, ly_resolve_prefix_clb get_prefix_clb, void *parser_data, struct lyd_node **diff); |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 52 | |
| 53 | /** |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 54 | * @brief Validate new siblings. Specifically, check duplicated instances, autodelete default values and cases. |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 55 | * |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 56 | * !! It is assumed autodeleted nodes cannot yet be in the unresolved node type set !! |
| 57 | * |
| 58 | * @param[in,out] first First sibling. |
| 59 | * @param[in] sparent Schema parent of the siblings, NULL for top-level siblings. |
| 60 | * @param[in] mod Module of the siblings, NULL for nested siblings. |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 61 | * @param[in,out] diff Validation diff. |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 62 | * @return LY_ERR value. |
| 63 | */ |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 64 | LY_ERR lyd_validate_new(struct lyd_node **first, const struct lysc_node *sparent, const struct lys_module *mod, |
| 65 | struct lyd_node **diff); |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * @brief Perform all remaining validation tasks, the data tree must be final when calling this function. |
| 69 | * |
| 70 | * @param[in] first First sibling. |
| 71 | * @param[in] sparent Schema parent of the siblings, NULL for top-level siblings. |
| 72 | * @param[in] mod Module of the siblings, NULL for nested siblings. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 73 | * @param[in] val_opts Validation options (@ref datavalidationoptions). |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 74 | * @param[in] op Operation to validate (@ref datavalidateop) or 0 for data tree |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 75 | * @return LY_ERR value. |
| 76 | */ |
Michal Vasko | fea12c6 | 2020-03-30 11:00:15 +0200 | [diff] [blame] | 77 | LY_ERR lyd_validate_final_r(struct lyd_node *first, const struct lysc_node *sparent, const struct lys_module *mod, |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 78 | int val_opts, LYD_VALIDATE_OP op); |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 79 | |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 80 | #endif /* LY_VALIDATION_H_ */ |