Blame src/validation.h

Packit 8fb591
/**
Packit 8fb591
 * @file validation.h
Packit 8fb591
 * @author Radek Krejci <rkrejci@cesnet.cz>
Packit 8fb591
 * @brief Data tree validation for libyang
Packit 8fb591
 *
Packit 8fb591
 * Copyright (c) 2015 CESNET, z.s.p.o.
Packit 8fb591
 *
Packit 8fb591
 * This source code is licensed under BSD 3-Clause License (the "License").
Packit 8fb591
 * You may not use this file except in compliance with the License.
Packit 8fb591
 * You may obtain a copy of the License at
Packit 8fb591
 *
Packit 8fb591
 *     https://opensource.org/licenses/BSD-3-Clause
Packit 8fb591
 */
Packit 8fb591
Packit 8fb591
#ifndef LY_VALIDATION_H_
Packit 8fb591
#define LY_VALIDATION_H_
Packit 8fb591
Packit 8fb591
#include "libyang.h"
Packit 8fb591
#include "resolve.h"
Packit 8fb591
#include "tree_data.h"
Packit 8fb591
Packit 8fb591
/**
Packit 8fb591
 * @brief Check, that the data node of the given schema node can even appear in a data tree.
Packit 8fb591
 *
Packit 8fb591
 * Checks included:
Packit 8fb591
 * - data node is not disabled via if-features
Packit 8fb591
 * - data node's when-stmt condition - if false, 1 is returned and ly_vecode is set to LYE_NOCOND,
Packit 8fb591
 * - data node is not status in case of edit-config content (options includes LYD_OPT_EDIT)
Packit 8fb591
 * - data node is in correct place (options includes LYD_OPT_RPC or LYD_OPT_RPCREPLY), since elements order matters
Packit 8fb591
 *   in RPCs and RPC replies.
Packit 8fb591
 *
Packit 8fb591
 * @param[in] node Data tree node to be checked.
Packit 8fb591
 * @param[in] options Parser options, see @ref parseroptions.
Packit 8fb591
 * @param[out] unres Structure to store unresolved items into. Cannot be NULL.
Packit 8fb591
 * @return 0 on success, non-zero on error.
Packit 8fb591
 */
Packit 8fb591
int lyv_data_context(const struct lyd_node *node, int options, struct unres_data *unres);
Packit 8fb591
Packit 8fb591
/**
Packit 8fb591
 * @brief Validate if the node's content is valid in the context it is placed.
Packit 8fb591
 *
Packit 8fb591
 * Expects that the node is already interconnected to the target tree and all its children
Packit 8fb591
 * are already resolved. All currently connected siblings are included to the tests.
Packit 8fb591
 *
Packit 8fb591
 * @param[in] node Data tree node to be checked.
Packit 8fb591
 * @param[in] options Parser options, see @ref parseroptions.
Packit 8fb591
 * @param[out] unres Structure to store unresolved items into. Cannot be NULL.
Packit 8fb591
 * @return 0 on success, non-zero on error.
Packit 8fb591
 */
Packit 8fb591
int lyv_data_content(struct lyd_node *node, int options, struct unres_data *unres);
Packit 8fb591
Packit 8fb591
/**
Packit 8fb591
 * @brief Check list unique leaves.
Packit 8fb591
 *
Packit 8fb591
 * @param[in] list List node to be checked.
Packit 8fb591
 * @return 0 on success, non-zero on error.
Packit 8fb591
 */
Packit 8fb591
int lyv_data_unique(struct lyd_node *list);
Packit 8fb591
Packit 8fb591
/**
Packit 8fb591
 * @brief Check for list/leaflist instance duplications.
Packit 8fb591
 *
Packit 8fb591
 * Function is used by lyv_data_context for inner lists/leaflists. Due to optimization, the function
Packit 8fb591
 * is used separatedly for the top-level lists/leaflists.
Packit 8fb591
 *
Packit 8fb591
 * @param[in] node List/leaflist node to be checked.
Packit 8fb591
 * @param[in] start First sibling of the \p node for searching for other instances of the same list/leaflist.
Packit 8fb591
 *                  Used for optimization, but can be NULL and the first sibling will be found.
Packit 8fb591
 * @return 0 on success, non-zero on error.
Packit 8fb591
 */
Packit 8fb591
int lyv_data_dup(struct lyd_node *node, struct lyd_node *start);
Packit 8fb591
Packit 8fb591
/**
Packit 8fb591
 * @brief Validate if the \p node has a sibling from another choice's case. It can report an error or automatically
Packit 8fb591
 * remove the nodes from other case than \p node.
Packit 8fb591
 *
Packit 8fb591
 * @param[in] node Data tree node to be checked.
Packit 8fb591
 * @param[in] schemanode Alternative to \p node (node is preferred), schema of the (potential) node
Packit 8fb591
 * @param[in,out] first_sibling The first sibling of the node where the searching will always start. It is updated
Packit 8fb591
 * when the first_sibling is (even repeatedly) autodeleted.
Packit 8fb591
 * @param[in] autodelete Flag to select if the conflicting nodes are supposed to be removed silently or reported.
Packit 8fb591
 * @param[in] nodel Exception for autodelete, if the \p nodel node would be removed, report an error.
Packit 8fb591
 * @return 0 on success (possible implicit autodelete), 1 on reported autodelete.
Packit 8fb591
 */
Packit 8fb591
int lyv_multicases(struct lyd_node *node, struct lys_node *schemanode, struct lyd_node **first_sibling, int autodelete,
Packit 8fb591
                   struct lyd_node *nodel);
Packit 8fb591
Packit 8fb591
#endif /* LY_VALIDATION_H_ */