blob: 0fdd0273c61c1eb90cd6346488c0ad4d95dd7e35 [file] [log] [blame]
Michal Vaskocde73ac2019-11-14 16:10:27 +01001/**
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
Radek Krejci47fab892020-11-05 17:02:41 +010018#include <stdint.h>
19
Michal Vaskof07286b2021-09-22 12:18:05 +020020#include "diff.h"
Michal Vaskocde73ac2019-11-14 16:10:27 +010021#include "log.h"
Michal Vaskofbbea932022-06-07 11:00:55 +020022#include "parser_data.h"
Radek Krejci47fab892020-11-05 17:02:41 +010023
Radek Krejci77114102021-03-10 15:21:57 +010024struct ly_ctx;
Radek Krejci47fab892020-11-05 17:02:41 +010025struct ly_set;
26struct lyd_node;
27struct lys_module;
28struct lysc_node;
Michal Vaskocde73ac2019-11-14 16:10:27 +010029
Michal Vaskoa6669ba2020-08-06 16:14:26 +020030/**
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 */
38LY_ERR lyd_val_diff_add(const struct lyd_node *node, enum lyd_diff_op op, struct lyd_node **diff);
39
Michal Vaskocde73ac2019-11-14 16:10:27 +010040/**
Michal Vaskob1b5c262020-03-05 14:29:47 +010041 * @brief Finish validation of nodes and attributes. Specifically, when (is processed first) and type validation.
Michal Vaskocde73ac2019-11-14 16:10:27 +010042 *
Michal Vaskob1b5c262020-03-05 14:29:47 +010043 * !! 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 Vaskod3bb12f2020-12-04 14:33:09 +010046 * @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 Vaskofbbea932022-06-07 11:00:55 +020049 * @param[in] data_type Validate data type.
Michal Vaskob1b5c262020-03-05 14:29:47 +010050 * @param[in] node_when Set with nodes with "when" conditions, can be NULL.
Michal Vasko976ec432021-12-06 15:42:22 +010051 * @param[in] when_xp_opts Additional XPath options to use for evaluating "when".
Michal Vaskocde73ac2019-11-14 16:10:27 +010052 * @param[in] node_types Set with nodes with unresolved types, can be NULL
aPiecekb0445f22021-06-24 11:34:07 +020053 * @param[in] meta_types Set with metadata with unresolved types, can be NULL.
Michal Vaskoddd76592022-01-17 13:34:48 +010054 * @param[in] ext_val Set with extension data to validate, can be NULL.
55 * @param[in] val_opts Validation options, see @ref datavalidationoptions.
Michal Vasko8104fd42020-07-13 11:09:51 +020056 * @param[in,out] diff Validation diff.
Michal Vaskocde73ac2019-11-14 16:10:27 +010057 * @return LY_ERR value.
58 */
Michal Vaskofbbea932022-06-07 11:00:55 +020059LY_ERR lyd_validate_unres(struct lyd_node **tree, const struct lys_module *mod, enum lyd_type data_type,
60 struct ly_set *node_when, uint32_t when_xp_opts, struct ly_set *node_types, struct ly_set *meta_types,
61 struct ly_set *ext_val, uint32_t val_opts, struct lyd_node **diff);
Michal Vaskocde73ac2019-11-14 16:10:27 +010062
63/**
Michal Vaskob1b5c262020-03-05 14:29:47 +010064 * @brief Validate new siblings. Specifically, check duplicated instances, autodelete default values and cases.
Michal Vaskocde73ac2019-11-14 16:10:27 +010065 *
Michal Vaskob1b5c262020-03-05 14:29:47 +010066 * !! It is assumed autodeleted nodes cannot yet be in the unresolved node type set !!
67 *
68 * @param[in,out] first First sibling.
69 * @param[in] sparent Schema parent of the siblings, NULL for top-level siblings.
70 * @param[in] mod Module of the siblings, NULL for nested siblings.
Michal Vasko8104fd42020-07-13 11:09:51 +020071 * @param[in,out] diff Validation diff.
Michal Vaskob1b5c262020-03-05 14:29:47 +010072 * @return LY_ERR value.
73 */
Michal Vasko8104fd42020-07-13 11:09:51 +020074LY_ERR lyd_validate_new(struct lyd_node **first, const struct lysc_node *sparent, const struct lys_module *mod,
Radek Krejci0f969882020-08-21 16:56:47 +020075 struct lyd_node **diff);
Michal Vaskob1b5c262020-03-05 14:29:47 +010076
77/**
Michal Vaskoe0665742021-02-11 11:08:44 +010078 * @brief Validate a data tree.
Michal Vaskob1b5c262020-03-05 14:29:47 +010079 *
Michal Vaskoe0665742021-02-11 11:08:44 +010080 * @param[in,out] tree Data tree to validate, nodes may be autodeleted.
81 * @param[in] module Module whose data (and schema restrictions) to validate, NULL for all modules.
82 * @param[in] ctx libyang context.
83 * @param[in] val_opts Validation options, see @ref datavalidationoptions.
84 * @param[in] validate_subtree Whether subtree was already validated (as part of data parsing) or not (separate validation).
85 * @param[in] node_when_p Set of nodes with when conditions, if NULL a local set is used.
86 * @param[in] node_types_p Set of unres node types, if NULL a local set is used.
87 * @param[in] meta_types_p Set of unres metadata types, if NULL a local set is used.
Michal Vaskoddd76592022-01-17 13:34:48 +010088 * @param[in] ext_val_p Set of unres extension data to validate, if NULL a local set is used.
Michal Vaskoe0665742021-02-11 11:08:44 +010089 * @param[out] diff Generated validation diff, not generated if NULL.
Michal Vaskocde73ac2019-11-14 16:10:27 +010090 * @return LY_ERR value.
91 */
Michal Vaskoe0665742021-02-11 11:08:44 +010092LY_ERR lyd_validate(struct lyd_node **tree, const struct lys_module *module, const struct ly_ctx *ctx, uint32_t val_opts,
Michal Vaskoddd76592022-01-17 13:34:48 +010093 ly_bool validate_subtree, struct ly_set *node_when_p, struct ly_set *node_types_p, struct ly_set *meta_types_p,
94 struct ly_set *ext_val_p, struct lyd_node **diff);
Michal Vasko9b368d32020-02-14 13:53:31 +010095
Michal Vaskocde73ac2019-11-14 16:10:27 +010096#endif /* LY_VALIDATION_H_ */