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 | * |
Michal Vasko | 135719f | 2022-08-25 12:18:17 +0200 | [diff] [blame] | 6 | * Copyright (c) 2019 - 2022 CESNET, z.s.p.o. |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 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 | |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 18 | #include <stdint.h> |
| 19 | |
Michal Vasko | f07286b | 2021-09-22 12:18:05 +0200 | [diff] [blame] | 20 | #include "diff.h" |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 21 | #include "log.h" |
Michal Vasko | fbbea93 | 2022-06-07 11:00:55 +0200 | [diff] [blame] | 22 | #include "parser_data.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 23 | |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 24 | struct ly_ctx; |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 25 | struct ly_set; |
| 26 | struct lyd_node; |
| 27 | struct lys_module; |
| 28 | struct lysc_node; |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 29 | |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 30 | /** |
| 31 | * @brief Add new changes into a diff. They are always merged. |
| 32 | * |
| 33 | * @param[in] node Node/subtree to add. |
| 34 | * @param[in] op Operation of the change. |
| 35 | * @param[in,out] diff Diff to update. |
| 36 | * @return LY_ERR value. |
| 37 | */ |
| 38 | LY_ERR lyd_val_diff_add(const struct lyd_node *node, enum lyd_diff_op op, struct lyd_node **diff); |
| 39 | |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 40 | /** |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 41 | * @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] | 42 | * |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 43 | * !! It is assumed autodeleted nodes cannot be in the unresolved node type set !! |
| 44 | * |
| 45 | * @param[in,out] tree Data tree, is updated if some nodes are autodeleted. |
Michal Vasko | d3bb12f | 2020-12-04 14:33:09 +0100 | [diff] [blame] | 46 | * @param[in] mod Module of the @p tree to take into consideration when deleting @p tree and moving it. |
| 47 | * If set, it is expected @p tree should point to the first node of @p mod. Otherwise it will simply be |
| 48 | * the first top-level sibling. |
Michal Vasko | fbbea93 | 2022-06-07 11:00:55 +0200 | [diff] [blame] | 49 | * @param[in] data_type Validate data type. |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 50 | * @param[in] node_when Set with nodes with "when" conditions, can be NULL. |
Michal Vasko | 976ec43 | 2021-12-06 15:42:22 +0100 | [diff] [blame] | 51 | * @param[in] when_xp_opts Additional XPath options to use for evaluating "when". |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 52 | * @param[in] node_types Set with nodes with unresolved types, can be NULL |
aPiecek | b0445f2 | 2021-06-24 11:34:07 +0200 | [diff] [blame] | 53 | * @param[in] meta_types Set with metadata with unresolved types, can be NULL. |
Michal Vasko | 135719f | 2022-08-25 12:18:17 +0200 | [diff] [blame] | 54 | * @param[in] ext_node Set with nodes with extensions to validate, can be NULL. |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 55 | * @param[in] ext_val Set with extension data to validate, can be NULL. |
| 56 | * @param[in] val_opts Validation options, see @ref datavalidationoptions. |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 57 | * @param[in,out] diff Validation diff. |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 58 | * @return LY_ERR value. |
| 59 | */ |
Michal Vasko | fbbea93 | 2022-06-07 11:00:55 +0200 | [diff] [blame] | 60 | LY_ERR lyd_validate_unres(struct lyd_node **tree, const struct lys_module *mod, enum lyd_type data_type, |
| 61 | struct ly_set *node_when, uint32_t when_xp_opts, struct ly_set *node_types, struct ly_set *meta_types, |
Michal Vasko | 135719f | 2022-08-25 12:18:17 +0200 | [diff] [blame] | 62 | struct ly_set *ext_node, struct ly_set *ext_val, uint32_t val_opts, struct lyd_node **diff); |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 63 | |
| 64 | /** |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 65 | * @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] | 66 | * |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 67 | * !! It is assumed autodeleted nodes cannot yet be in the unresolved node type set !! |
| 68 | * |
| 69 | * @param[in,out] first First sibling. |
| 70 | * @param[in] sparent Schema parent of the siblings, NULL for top-level siblings. |
| 71 | * @param[in] mod Module of the siblings, NULL for nested siblings. |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 72 | * @param[in,out] diff Validation diff. |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 73 | * @return LY_ERR value. |
| 74 | */ |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 75 | LY_ERR lyd_validate_new(struct lyd_node **first, const struct lysc_node *sparent, const struct lys_module *mod, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 76 | struct lyd_node **diff); |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 77 | |
| 78 | /** |
Michal Vasko | 135719f | 2022-08-25 12:18:17 +0200 | [diff] [blame] | 79 | * @brief Validate data node with an extension instance, if any, by storing it in its unres set. |
| 80 | * |
| 81 | * @param[in] node Node to check for an extension instance with a node callback. |
| 82 | * @param[in,out] ext_node Set with data nodes to validate. |
| 83 | * @return LY_ERR value. |
| 84 | */ |
| 85 | LY_ERR lyd_validate_node_ext(struct lyd_node *node, struct ly_set *ext_node); |
| 86 | |
| 87 | /** |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 88 | * @brief Validate a data tree. |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 89 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 90 | * @param[in,out] tree Data tree to validate, nodes may be autodeleted. |
| 91 | * @param[in] module Module whose data (and schema restrictions) to validate, NULL for all modules. |
| 92 | * @param[in] ctx libyang context. |
| 93 | * @param[in] val_opts Validation options, see @ref datavalidationoptions. |
| 94 | * @param[in] validate_subtree Whether subtree was already validated (as part of data parsing) or not (separate validation). |
| 95 | * @param[in] node_when_p Set of nodes with when conditions, if NULL a local set is used. |
| 96 | * @param[in] node_types_p Set of unres node types, if NULL a local set is used. |
| 97 | * @param[in] meta_types_p Set of unres metadata types, if NULL a local set is used. |
Michal Vasko | 135719f | 2022-08-25 12:18:17 +0200 | [diff] [blame] | 98 | * @param[in] ext_node_p Set of unres nodes with extensions to validate, if NULL a local set is used. |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 99 | * @param[in] ext_val_p Set of unres extension data to validate, if NULL a local set is used. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 100 | * @param[out] diff Generated validation diff, not generated if NULL. |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 101 | * @return LY_ERR value. |
| 102 | */ |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 103 | LY_ERR lyd_validate(struct lyd_node **tree, const struct lys_module *module, const struct ly_ctx *ctx, uint32_t val_opts, |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 104 | ly_bool validate_subtree, struct ly_set *node_when_p, struct ly_set *node_types_p, struct ly_set *meta_types_p, |
Michal Vasko | 135719f | 2022-08-25 12:18:17 +0200 | [diff] [blame] | 105 | struct ly_set *ext_node_p, struct ly_set *ext_val_p, struct lyd_node **diff); |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 106 | |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 107 | #endif /* LY_VALIDATION_H_ */ |