blob: ae286be4fa54910a25d2e00099d9e70d453b954b [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 Vaskocde73ac2019-11-14 16:10:27 +010020#include "log.h"
Michal Vaskofbed4ea2020-07-08 10:43:30 +020021#include "parser_data.h"
Radek Krejci47fab892020-11-05 17:02:41 +010022
23struct ly_set;
24struct lyd_node;
25struct lys_module;
26struct lysc_node;
Michal Vaskocde73ac2019-11-14 16:10:27 +010027
Michal Vaskoa6669ba2020-08-06 16:14:26 +020028enum lyd_diff_op;
29
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 */
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 Vaskob1b5c262020-03-05 14:29:47 +010049 * @param[in] node_when Set with nodes with "when" conditions, can be NULL.
Michal Vaskocde73ac2019-11-14 16:10:27 +010050 * @param[in] node_types Set with nodes with unresolved types, can be NULL
Michal Vasko9f96a052020-03-10 09:41:45 +010051 * @param[in] meta_types Set with metdata with unresolved types, can be NULL.
Michal Vasko8104fd42020-07-13 11:09:51 +020052 * @param[in,out] diff Validation diff.
Michal Vaskocde73ac2019-11-14 16:10:27 +010053 * @return LY_ERR value.
54 */
Michal Vaskod3bb12f2020-12-04 14:33:09 +010055LY_ERR lyd_validate_unres(struct lyd_node **tree, const struct lys_module *mod, struct ly_set *node_when,
56 struct ly_set *node_types, struct ly_set *meta_types, struct lyd_node **diff);
Michal Vaskocde73ac2019-11-14 16:10:27 +010057
58/**
Michal Vaskob1b5c262020-03-05 14:29:47 +010059 * @brief Validate new siblings. Specifically, check duplicated instances, autodelete default values and cases.
Michal Vaskocde73ac2019-11-14 16:10:27 +010060 *
Michal Vaskob1b5c262020-03-05 14:29:47 +010061 * !! It is assumed autodeleted nodes cannot yet be in the unresolved node type set !!
62 *
63 * @param[in,out] first First sibling.
64 * @param[in] sparent Schema parent of the siblings, NULL for top-level siblings.
65 * @param[in] mod Module of the siblings, NULL for nested siblings.
Michal Vasko8104fd42020-07-13 11:09:51 +020066 * @param[in,out] diff Validation diff.
Michal Vaskob1b5c262020-03-05 14:29:47 +010067 * @return LY_ERR value.
68 */
Michal Vasko8104fd42020-07-13 11:09:51 +020069LY_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 +020070 struct lyd_node **diff);
Michal Vaskob1b5c262020-03-05 14:29:47 +010071
72/**
73 * @brief Perform all remaining validation tasks, the data tree must be final when calling this function.
74 *
75 * @param[in] first First sibling.
Michal Vaskobd4db892020-11-23 16:58:20 +010076 * @param[in] parent Data parent.
Michal Vaskob1b5c262020-03-05 14:29:47 +010077 * @param[in] sparent Schema parent of the siblings, NULL for top-level siblings.
78 * @param[in] mod Module of the siblings, NULL for nested siblings.
Michal Vaskof03ed032020-03-04 13:31:44 +010079 * @param[in] val_opts Validation options (@ref datavalidationoptions).
Radek Krejci7931b192020-06-25 17:05:03 +020080 * @param[in] op Operation to validate (@ref datavalidateop) or 0 for data tree
Michal Vaskocde73ac2019-11-14 16:10:27 +010081 * @return LY_ERR value.
82 */
Michal Vaskobd4db892020-11-23 16:58:20 +010083LY_ERR lyd_validate_final_r(struct lyd_node *first, const struct lyd_node *parent, const struct lysc_node *sparent,
84 const struct lys_module *mod, uint32_t val_opts, LYD_VALIDATE_OP op);
Michal Vasko9b368d32020-02-14 13:53:31 +010085
Michal Vaskocde73ac2019-11-14 16:10:27 +010086#endif /* LY_VALIDATION_H_ */