blob: 407709176d9681e78253c2e45a2517623e2e16cc [file] [log] [blame]
Radek Krejcib1c12512015-08-11 11:22:04 +02001/**
2 * @file validation.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief Data tree validation for libyang
5 *
6 * Copyright (c) 2015 CESNET, z.s.p.o.
7 *
Radek Krejci54f6fb32016-02-24 12:56:39 +01008 * 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
Michal Vasko8de098c2016-02-26 10:00:25 +010011 *
Radek Krejci54f6fb32016-02-24 12:56:39 +010012 * https://opensource.org/licenses/BSD-3-Clause
Radek Krejcib1c12512015-08-11 11:22:04 +020013 */
14
15#ifndef LY_VALIDATION_H_
16#define LY_VALIDATION_H_
17
18#include "libyang.h"
Michal Vaskocf024702015-10-08 15:01:42 +020019#include "resolve.h"
Michal Vasko2d162e12015-09-24 14:33:29 +020020#include "tree_data.h"
Radek Krejcib1c12512015-08-11 11:22:04 +020021
22/**
Radek Krejcieab784a2015-08-27 09:56:53 +020023 * @brief Check, that the data node of the given schema node can even appear in a data tree.
Radek Krejcib1c12512015-08-11 11:22:04 +020024 *
Radek Krejcieab784a2015-08-27 09:56:53 +020025 * Checks included:
26 * - data node is not disabled via if-features
Michal Vasko53b7da02018-02-13 15:28:42 +010027 * - data node's when-stmt condition - if false, 1 is returned and ly_vecode is set to LYE_NOCOND,
Radek Krejcieab784a2015-08-27 09:56:53 +020028 * - data node is not status in case of edit-config content (options includes LYD_OPT_EDIT)
Radek Krejci4a49bdf2016-01-12 17:17:01 +010029 * - data node is in correct place (options includes LYD_OPT_RPC or LYD_OPT_RPCREPLY), since elements order matters
30 * in RPCs and RPC replies.
Radek Krejcib1c12512015-08-11 11:22:04 +020031 *
Michal Vaskocf024702015-10-08 15:01:42 +020032 * @param[in] node Data tree node to be checked.
Radek Krejcieab784a2015-08-27 09:56:53 +020033 * @param[in] options Parser options, see @ref parseroptions.
Michal Vasko53b7da02018-02-13 15:28:42 +010034 * @param[out] unres Structure to store unresolved items into. Cannot be NULL.
35 * @return 0 on success, non-zero on error.
Radek Krejcib1c12512015-08-11 11:22:04 +020036 */
Radek Krejci48464ed2016-03-17 15:44:09 +010037int lyv_data_context(const struct lyd_node *node, int options, struct unres_data *unres);
Radek Krejcieab784a2015-08-27 09:56:53 +020038
39/**
40 * @brief Validate if the node's content is valid in the context it is placed.
41 *
42 * Expects that the node is already interconnected to the target tree and all its children
43 * are already resolved. All currently connected siblings are included to the tests.
44 *
45 * @param[in] node Data tree node to be checked.
Radek Krejcieab784a2015-08-27 09:56:53 +020046 * @param[in] options Parser options, see @ref parseroptions.
Radek Krejci0b7704f2016-03-18 12:16:14 +010047 * @param[out] unres Structure to store unresolved items into. Cannot be NULL.
Michal Vasko53b7da02018-02-13 15:28:42 +010048 * @return 0 on success, non-zero on error.
Radek Krejcieab784a2015-08-27 09:56:53 +020049 */
Radek Krejci48464ed2016-03-17 15:44:09 +010050int lyv_data_content(struct lyd_node *node, int options, struct unres_data *unres);
Radek Krejcib1c12512015-08-11 11:22:04 +020051
Radek Krejci46c4cd72016-01-21 15:13:52 +010052/**
Michal Vasko185b5272018-09-13 14:26:12 +020053 * @brief Check list unique leaves.
54 *
55 * @param[in] list List node to be checked.
56 * @return 0 on success, non-zero on error.
57 */
58int lyv_data_unique(struct lyd_node *list);
59
60/**
61 * @brief Check for list/leaflist instance duplications.
Radek Krejci63b79c82016-08-10 10:09:33 +020062 *
63 * Function is used by lyv_data_context for inner lists/leaflists. Due to optimization, the function
64 * is used separatedly for the top-level lists/leaflists.
65 *
66 * @param[in] node List/leaflist node to be checked.
67 * @param[in] start First sibling of the \p node for searching for other instances of the same list/leaflist.
68 * Used for optimization, but can be NULL and the first sibling will be found.
Michal Vasko53b7da02018-02-13 15:28:42 +010069 * @return 0 on success, non-zero on error.
Radek Krejci63b79c82016-08-10 10:09:33 +020070 */
Michal Vasko185b5272018-09-13 14:26:12 +020071int lyv_data_dup(struct lyd_node *node, struct lyd_node *start);
Radek Krejci63b79c82016-08-10 10:09:33 +020072
73/**
Radek Krejci2d5525d2016-04-04 15:43:30 +020074 * @brief Validate if the \p node has a sibling from another choice's case. It can report an error or automatically
75 * remove the nodes from other case than \p node.
76 *
77 * @param[in] node Data tree node to be checked.
Radek Krejci76fed2b2016-04-11 14:55:23 +020078 * @param[in] schemanode Alternative to \p node (node is preferred), schema of the (potential) node
Radek Krejcia1c33bf2016-09-07 12:38:49 +020079 * @param[in,out] first_sibling The first sibling of the node where the searching will always start. It is updated
Michal Vasko53b7da02018-02-13 15:28:42 +010080 * when the first_sibling is (even repeatedly) autodeleted.
81 * @param[in] autodelete Flag to select if the conflicting nodes are supposed to be removed silently or reported.
82 * @param[in] nodel Exception for autodelete, if the \p nodel node would be removed, report an error.
83 * @return 0 on success (possible implicit autodelete), 1 on reported autodelete.
Radek Krejci2d5525d2016-04-04 15:43:30 +020084 */
Radek Krejcia1c33bf2016-09-07 12:38:49 +020085int lyv_multicases(struct lyd_node *node, struct lys_node *schemanode, struct lyd_node **first_sibling, int autodelete,
Radek Krejci76fed2b2016-04-11 14:55:23 +020086 struct lyd_node *nodel);
Radek Krejci2d5525d2016-04-04 15:43:30 +020087
Radek Krejcib1c12512015-08-11 11:22:04 +020088#endif /* LY_VALIDATION_H_ */