blob: d8b62a48c7e3c1a5ca2642b727b9f8935e65a520 [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"
19#include "tree_data.h"
20
21/**
22 * @brief Finish validation of nodes and attributes. Specifically, type and when validation.
23 *
24 * @param[in] node_types Set with nodes with unresolved types, can be NULL
25 * @param[in] attr_types Set with attributes with unresolved types, can be NULL.
26 * @param[in] node_when Set with nodes with "when" conditions, can be NULL.
27 * @param[in] format Format of the unresolved data.
28 * @param[in] get_prefix_clb Format-specific getter to resolve prefixes.
29 * @param[in] parser_data Parser's data for @p get_prefix_clb.
Michal Vaskof03ed032020-03-04 13:31:44 +010030 * @param[in] tree Data tree.
Michal Vaskocde73ac2019-11-14 16:10:27 +010031 * @return LY_ERR value.
32 */
33LY_ERR lyd_validate_unres(struct ly_set *node_types, struct ly_set *attr_types, struct ly_set *node_when, LYD_FORMAT format,
Michal Vaskof03ed032020-03-04 13:31:44 +010034 ly_clb_resolve_prefix get_prefix_clb, void *parser_data, const struct lyd_node *tree);
Michal Vaskocde73ac2019-11-14 16:10:27 +010035
36/**
Michal Vasko9b368d32020-02-14 13:53:31 +010037 * @brief Perform all validation tasks, the data tree must be complete when calling this function.
Michal Vaskocde73ac2019-11-14 16:10:27 +010038 *
Michal Vaskof03ed032020-03-04 13:31:44 +010039 * @param[in,out] tree Data tree.
Michal Vaskocde73ac2019-11-14 16:10:27 +010040 * @param[in] modules Array of modules that should be validated, NULL for all modules.
41 * @param[in] mod_count Modules count.
42 * @param[in] ctx Context if all modules should be validated, NULL for only selected modules.
Michal Vaskof03ed032020-03-04 13:31:44 +010043 * @param[in] val_opts Validation options (@ref datavalidationoptions).
Michal Vaskocde73ac2019-11-14 16:10:27 +010044 * @return LY_ERR value.
45 */
Michal Vaskof03ed032020-03-04 13:31:44 +010046LY_ERR lyd_validate_data(struct lyd_node **tree, const struct lys_module **modules, int mod_count,
Michal Vasko9b368d32020-02-14 13:53:31 +010047 struct ly_ctx *ctx, int val_opts);
48
49/**
50 * @brief Check the existence and create any non-existing default siblings, recursively for the created nodes.
51 *
52 * @param[in] parent Parent of the potential default values.
53 * @param[in,out] first First sibling.
54 * @param[in] schema Schema parent of the default values, NULL for top-level siblings.
55 * @param[in] mod Module of the default values, NULL for nested (non top-level) siblings.
56 * @param[in] node_types Set to add nodes with unresolved types into.
57 * @param[in] node_when Set to add nodes with "when" conditions into.
58 * @return LY_ERR value.
59 */
60LY_ERR lyd_validate_defaults_r(struct lyd_node_inner *parent, struct lyd_node **first, const struct lysc_node *schema,
61 const struct lysc_module *mod, struct ly_set *node_types, struct ly_set *node_when);
62
63/**
64 * @brief Check the existence and create any non-existing default top-level nodes.
65 *
66 * @param[in,out] first First top-level sibling. There may be no explicit nodes.
67 * @param[in] modules Array of modules that should be considered, NULL for all modules.
68 * @param[in] mod_count Modules count.
69 * @param[in] ctx Context if all modules should be considered, NULL for only selected modules.
70 * @param[in] node_types Set to add nodes with unresolved types into, can be NULL if not needed.
71 * @param[in] node_when Set to add nodes with "when" conditions into, can be NULL if not needed.
72 * @param[in] val_opts Relevant validation options (#LYD_VALOPT_DATA_ONLY).
73 * @return LY_ERR value.
74 */
75LY_ERR lyd_validate_defaults_top(struct lyd_node **first, const struct lys_module **modules, int mod_count,
76 struct ly_ctx *ctx, struct ly_set *node_types, struct ly_set *node_when, int val_opts);
Michal Vaskocde73ac2019-11-14 16:10:27 +010077
78#endif /* LY_VALIDATION_H_ */