blob: 35492af5577575c5a1f9c377e73979623917c97d [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 Vaskocde73ac2019-11-14 16:10:27 +010020#include "tree_data.h"
21
22/**
Michal Vaskob1b5c262020-03-05 14:29:47 +010023 * @brief Finish validation of nodes and attributes. Specifically, when (is processed first) and type validation.
Michal Vaskocde73ac2019-11-14 16:10:27 +010024 *
Michal Vaskob1b5c262020-03-05 14:29:47 +010025 * !! It is assumed autodeleted nodes cannot be in the unresolved node type set !!
26 *
27 * @param[in,out] tree Data tree, is updated if some nodes are autodeleted.
28 * @param[in] node_when Set with nodes with "when" conditions, can be NULL.
Michal Vaskocde73ac2019-11-14 16:10:27 +010029 * @param[in] node_types Set with nodes with unresolved types, can be NULL
Michal Vasko9f96a052020-03-10 09:41:45 +010030 * @param[in] meta_types Set with metdata with unresolved types, can be NULL.
Michal Vaskocde73ac2019-11-14 16:10:27 +010031 * @param[in] format Format of the unresolved data.
32 * @param[in] get_prefix_clb Format-specific getter to resolve prefixes.
33 * @param[in] parser_data Parser's data for @p get_prefix_clb.
Michal Vaskocde73ac2019-11-14 16:10:27 +010034 * @return LY_ERR value.
35 */
Michal Vasko9f96a052020-03-10 09:41:45 +010036LY_ERR lyd_validate_unres(struct lyd_node **tree, struct ly_set *node_when, struct ly_set *node_types, struct ly_set *meta_types,
Michal Vaskob1b5c262020-03-05 14:29:47 +010037 LYD_FORMAT format, ly_clb_resolve_prefix get_prefix_clb, void *parser_data);
Michal Vaskocde73ac2019-11-14 16:10:27 +010038
39/**
Michal Vaskob1b5c262020-03-05 14:29:47 +010040 * @brief Validate new siblings. Specifically, check duplicated instances, autodelete default values and cases.
Michal Vaskocde73ac2019-11-14 16:10:27 +010041 *
Michal Vaskob1b5c262020-03-05 14:29:47 +010042 * !! It is assumed autodeleted nodes cannot yet be in the unresolved node type set !!
43 *
44 * @param[in,out] first First sibling.
45 * @param[in] sparent Schema parent of the siblings, NULL for top-level siblings.
46 * @param[in] mod Module of the siblings, NULL for nested siblings.
47 * @return LY_ERR value.
48 */
49LY_ERR lyd_validate_new(struct lyd_node **first, const struct lysc_node *sparent, const struct lys_module *mod);
50
51/**
52 * @brief Perform all remaining validation tasks, the data tree must be final when calling this function.
53 *
54 * @param[in] first First sibling.
55 * @param[in] sparent Schema parent of the siblings, NULL for top-level siblings.
56 * @param[in] mod Module of the siblings, NULL for nested siblings.
Michal Vaskof03ed032020-03-04 13:31:44 +010057 * @param[in] val_opts Validation options (@ref datavalidationoptions).
Radek Krejci7931b192020-06-25 17:05:03 +020058 * @param[in] op Operation to validate (@ref datavalidateop) or 0 for data tree
Michal Vaskocde73ac2019-11-14 16:10:27 +010059 * @return LY_ERR value.
60 */
Michal Vaskofea12c62020-03-30 11:00:15 +020061LY_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 +020062 int val_opts, LYD_VALIDATE_OP op);
Michal Vasko9b368d32020-02-14 13:53:31 +010063
64/**
65 * @brief Check the existence and create any non-existing default siblings, recursively for the created nodes.
66 *
Michal Vaskob1b5c262020-03-05 14:29:47 +010067 * @param[in] parent Parent of the potential default values, NULL for top-level siblings.
Michal Vasko9b368d32020-02-14 13:53:31 +010068 * @param[in,out] first First sibling.
Michal Vaskob1b5c262020-03-05 14:29:47 +010069 * @param[in] sparent Schema parent of the siblings, NULL if schema of @p parent can be used.
70 * @param[in] mod Module of the default values, NULL for nested siblings.
Michal Vasko9b368d32020-02-14 13:53:31 +010071 * @param[in] node_types Set to add nodes with unresolved types into.
72 * @param[in] node_when Set to add nodes with "when" conditions into.
Michal Vaskoe75ecfd2020-03-06 14:12:28 +010073 * @param[in] val_opts Validation options (@ref datavalidationoptions).
Michal Vasko9b368d32020-02-14 13:53:31 +010074 * @return LY_ERR value.
75 */
Michal Vaskofbed4ea2020-07-08 10:43:30 +020076LY_ERR lyd_validate_defaults_r(struct lyd_node *parent, struct lyd_node **first, const struct lysc_node *sparent,
Michal Vaskoe75ecfd2020-03-06 14:12:28 +010077 const struct lys_module *mod, struct ly_set *node_types, struct ly_set *node_when, int val_opts);
Michal Vaskocde73ac2019-11-14 16:10:27 +010078
79#endif /* LY_VALIDATION_H_ */