blob: b8b1a9837d262eae3216792360c90d13b3cce697 [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"
Radek Krejci47fab892020-11-05 17:02:41 +010022
Radek Krejci77114102021-03-10 15:21:57 +010023struct ly_ctx;
Radek Krejci47fab892020-11-05 17:02:41 +010024struct ly_set;
25struct lyd_node;
26struct lys_module;
27struct lysc_node;
Michal Vaskocde73ac2019-11-14 16:10:27 +010028
Michal Vaskoa6669ba2020-08-06 16:14:26 +020029/**
Radek Krejci4f2e3e52021-03-30 14:20:28 +020030 * @brief Add information about the node's extensions having their own validation callback into an unres set.
31 *
32 * @param[in,out] node_exts Unres set for holding information for validating extension instances.
33 * @param[in] node Data node to be examined.
34 * @return LY_ERR values.
35 */
36LY_ERR lysc_node_ext_tovalidate(struct ly_set *node_exts, struct lyd_node *node);
37
38/**
Michal Vaskoa6669ba2020-08-06 16:14:26 +020039 * @brief Add new changes into a diff. They are always merged.
40 *
41 * @param[in] node Node/subtree to add.
42 * @param[in] op Operation of the change.
43 * @param[in,out] diff Diff to update.
44 * @return LY_ERR value.
45 */
46LY_ERR lyd_val_diff_add(const struct lyd_node *node, enum lyd_diff_op op, struct lyd_node **diff);
47
Michal Vaskocde73ac2019-11-14 16:10:27 +010048/**
Michal Vaskob1b5c262020-03-05 14:29:47 +010049 * @brief Finish validation of nodes and attributes. Specifically, when (is processed first) and type validation.
Michal Vaskocde73ac2019-11-14 16:10:27 +010050 *
Michal Vaskob1b5c262020-03-05 14:29:47 +010051 * !! It is assumed autodeleted nodes cannot be in the unresolved node type set !!
52 *
53 * @param[in,out] tree Data tree, is updated if some nodes are autodeleted.
Michal Vaskod3bb12f2020-12-04 14:33:09 +010054 * @param[in] mod Module of the @p tree to take into consideration when deleting @p tree and moving it.
55 * If set, it is expected @p tree should point to the first node of @p mod. Otherwise it will simply be
56 * the first top-level sibling.
Michal Vaskob1b5c262020-03-05 14:29:47 +010057 * @param[in] node_when Set with nodes with "when" conditions, can be NULL.
Michal Vasko0110cc92021-12-06 15:42:22 +010058 * @param[in] when_xp_opts Additional XPath options to use for evaluating "when".
Radek Krejci4f2e3e52021-03-30 14:20:28 +020059 * @param[in] node_exts Set with nodes with extension instances with validation plugin callback, can be NULL.
Michal Vaskocde73ac2019-11-14 16:10:27 +010060 * @param[in] node_types Set with nodes with unresolved types, can be NULL
aPiecekb0445f22021-06-24 11:34:07 +020061 * @param[in] meta_types Set with metadata with unresolved types, can be NULL.
Michal Vasko8104fd42020-07-13 11:09:51 +020062 * @param[in,out] diff Validation diff.
Michal Vaskocde73ac2019-11-14 16:10:27 +010063 * @return LY_ERR value.
64 */
Michal Vaskod3bb12f2020-12-04 14:33:09 +010065LY_ERR lyd_validate_unres(struct lyd_node **tree, const struct lys_module *mod, struct ly_set *node_when,
Michal Vasko0110cc92021-12-06 15:42:22 +010066 uint32_t when_xp_opts, struct ly_set *node_exts, struct ly_set *node_types, struct ly_set *meta_types,
67 struct lyd_node **diff);
Michal Vaskocde73ac2019-11-14 16:10:27 +010068
69/**
Michal Vaskob1b5c262020-03-05 14:29:47 +010070 * @brief Validate new siblings. Specifically, check duplicated instances, autodelete default values and cases.
Michal Vaskocde73ac2019-11-14 16:10:27 +010071 *
Michal Vaskob1b5c262020-03-05 14:29:47 +010072 * !! It is assumed autodeleted nodes cannot yet be in the unresolved node type set !!
73 *
74 * @param[in,out] first First sibling.
75 * @param[in] sparent Schema parent of the siblings, NULL for top-level siblings.
76 * @param[in] mod Module of the siblings, NULL for nested siblings.
Michal Vasko8104fd42020-07-13 11:09:51 +020077 * @param[in,out] diff Validation diff.
Michal Vaskob1b5c262020-03-05 14:29:47 +010078 * @return LY_ERR value.
79 */
Michal Vasko8104fd42020-07-13 11:09:51 +020080LY_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 +020081 struct lyd_node **diff);
Michal Vaskob1b5c262020-03-05 14:29:47 +010082
83/**
Michal Vaskoe0665742021-02-11 11:08:44 +010084 * @brief Validate a data tree.
Michal Vaskob1b5c262020-03-05 14:29:47 +010085 *
Michal Vaskoe0665742021-02-11 11:08:44 +010086 * @param[in,out] tree Data tree to validate, nodes may be autodeleted.
87 * @param[in] module Module whose data (and schema restrictions) to validate, NULL for all modules.
88 * @param[in] ctx libyang context.
89 * @param[in] val_opts Validation options, see @ref datavalidationoptions.
90 * @param[in] validate_subtree Whether subtree was already validated (as part of data parsing) or not (separate validation).
91 * @param[in] node_when_p Set of nodes with when conditions, if NULL a local set is used.
Radek Krejci84d7fd72021-07-14 18:32:21 +020092 * @param[in] node_exts_p Set with nodes with extension instances with validation plugin callback, if NULL a local set is used.
Michal Vaskoe0665742021-02-11 11:08:44 +010093 * @param[in] node_types_p Set of unres node types, if NULL a local set is used.
94 * @param[in] meta_types_p Set of unres metadata types, if NULL a local set is used.
95 * @param[out] diff Generated validation diff, not generated if NULL.
Michal Vaskocde73ac2019-11-14 16:10:27 +010096 * @return LY_ERR value.
97 */
Michal Vaskoe0665742021-02-11 11:08:44 +010098LY_ERR lyd_validate(struct lyd_node **tree, const struct lys_module *module, const struct ly_ctx *ctx, uint32_t val_opts,
Radek Krejci4f2e3e52021-03-30 14:20:28 +020099 ly_bool validate_subtree, struct ly_set *node_when_p, struct ly_set *node_exts_p,
100 struct ly_set *node_types_p, struct ly_set *meta_types_p, struct lyd_node **diff);
Michal Vasko9b368d32020-02-14 13:53:31 +0100101
Michal Vaskocde73ac2019-11-14 16:10:27 +0100102#endif /* LY_VALIDATION_H_ */