blob: f3404df17cc1ee1ce8a3a5a2f1f0797ff94f275a [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
18#include "log.h"
Michal Vaskofbed4ea2020-07-08 10:43:30 +020019#include "parser_data.h"
Michal Vaskof937cfe2020-08-03 16:07:12 +020020#include "plugins_types.h"
Michal Vaskocde73ac2019-11-14 16:10:27 +010021#include "tree_data.h"
22
Michal Vaskoa6669ba2020-08-06 16:14:26 +020023enum 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 */
33LY_ERR lyd_val_diff_add(const struct lyd_node *node, enum lyd_diff_op op, struct lyd_node **diff);
34
Michal Vaskocde73ac2019-11-14 16:10:27 +010035/**
Michal Vaskob1b5c262020-03-05 14:29:47 +010036 * @brief Finish validation of nodes and attributes. Specifically, when (is processed first) and type validation.
Michal Vaskocde73ac2019-11-14 16:10:27 +010037 *
Michal Vaskob1b5c262020-03-05 14:29:47 +010038 * !! 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 Vaskocde73ac2019-11-14 16:10:27 +010042 * @param[in] node_types Set with nodes with unresolved types, can be NULL
Michal Vasko9f96a052020-03-10 09:41:45 +010043 * @param[in] meta_types Set with metdata with unresolved types, can be NULL.
Michal Vaskocde73ac2019-11-14 16:10:27 +010044 * @param[in] format Format of the unresolved data.
Michal Vaskoc8a230d2020-08-14 12:17:10 +020045 * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix).
Michal Vasko8104fd42020-07-13 11:09:51 +020046 * @param[in,out] diff Validation diff.
Michal Vaskocde73ac2019-11-14 16:10:27 +010047 * @return LY_ERR value.
48 */
Michal Vasko9f96a052020-03-10 09:41:45 +010049LY_ERR lyd_validate_unres(struct lyd_node **tree, struct ly_set *node_when, struct ly_set *node_types, struct ly_set *meta_types,
Michal Vaskoc8a230d2020-08-14 12:17:10 +020050 LY_PREFIX_FORMAT format, void *prefix_data, struct lyd_node **diff);
Michal Vaskocde73ac2019-11-14 16:10:27 +010051
52/**
Michal Vaskob1b5c262020-03-05 14:29:47 +010053 * @brief Validate new siblings. Specifically, check duplicated instances, autodelete default values and cases.
Michal Vaskocde73ac2019-11-14 16:10:27 +010054 *
Michal Vaskob1b5c262020-03-05 14:29:47 +010055 * !! It is assumed autodeleted nodes cannot yet be in the unresolved node type set !!
56 *
57 * @param[in,out] first First sibling.
58 * @param[in] sparent Schema parent of the siblings, NULL for top-level siblings.
59 * @param[in] mod Module of the siblings, NULL for nested siblings.
Michal Vasko8104fd42020-07-13 11:09:51 +020060 * @param[in,out] diff Validation diff.
Michal Vaskob1b5c262020-03-05 14:29:47 +010061 * @return LY_ERR value.
62 */
Michal Vasko8104fd42020-07-13 11:09:51 +020063LY_ERR lyd_validate_new(struct lyd_node **first, const struct lysc_node *sparent, const struct lys_module *mod,
64 struct lyd_node **diff);
Michal Vaskob1b5c262020-03-05 14:29:47 +010065
66/**
67 * @brief Perform all remaining validation tasks, the data tree must be final when calling this function.
68 *
69 * @param[in] 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 Vaskof03ed032020-03-04 13:31:44 +010072 * @param[in] val_opts Validation options (@ref datavalidationoptions).
Radek Krejci7931b192020-06-25 17:05:03 +020073 * @param[in] op Operation to validate (@ref datavalidateop) or 0 for data tree
Michal Vaskocde73ac2019-11-14 16:10:27 +010074 * @return LY_ERR value.
75 */
Michal Vaskofea12c62020-03-30 11:00:15 +020076LY_ERR lyd_validate_final_r(struct lyd_node *first, const struct lysc_node *sparent, const struct lys_module *mod,
Radek Krejci7931b192020-06-25 17:05:03 +020077 int val_opts, LYD_VALIDATE_OP op);
Michal Vasko9b368d32020-02-14 13:53:31 +010078
Michal Vaskocde73ac2019-11-14 16:10:27 +010079#endif /* LY_VALIDATION_H_ */