blob: dab161445927bbcf2af535bc1bbeb70b737c2b3f [file] [log] [blame]
Michal Vaskod59035b2020-07-08 12:00:06 +02001/**
2 * @file diff.h
3 * @author Michal Vasko <mvasko@cesnet.cz>
4 * @brief internal diff header
5 *
6 * Copyright (c) 2020 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_DIFF_H_
16#define LY_DIFF_H_
17
18#include <stdint.h>
19
20#include "log.h"
21
22struct lyd_node;
23
24/**
25 * @brief Internal structure for storing current (virtual) user-ordered instances order.
26 */
27struct lyd_diff_userord {
28 const struct lysc_node *schema; /**< User-ordered list/leaf-list schema node. */
29 uint64_t pos; /**< Current position in the second tree. */
30 const struct lyd_node **inst; /**< Sized array of current instance order. */
31};
32
33/**
34 * @brief Diff operations.
35 */
36enum lyd_diff_op {
37 LYD_DIFF_OP_CREATE, /**< Subtree created. */
38 LYD_DIFF_OP_DELETE, /**< Subtree deleted. */
39 LYD_DIFF_OP_REPLACE, /**< Node value changed or (leaf-)list instance moved. */
Michal Vasko69730152020-10-09 16:30:07 +020040 LYD_DIFF_OP_NONE /**< No change of an existing inner node or default flag change of a term node. */
Michal Vaskod59035b2020-07-08 12:00:06 +020041};
42
43/**
44 * @brief Add a new change into diff.
45 *
46 * @param[in] node Node (subtree) to add into diff.
47 * @param[in] op Operation to set.
48 * @param[in] orig_default Original default metadata to set.
49 * @param[in] orig_value Original value metadata to set.
50 * @param[in] key Key metadata to set.
51 * @param[in] value Value metadata to set.
Michal Vaskoe78faec2021-04-08 17:24:43 +020052 * @param[in] position Position metadata to set.
Michal Vaskod59035b2020-07-08 12:00:06 +020053 * @param[in] orig_key Original key metadata to set.
Michal Vaskoe78faec2021-04-08 17:24:43 +020054 * @param[in] orig_position Original position metadata to set.
Michal Vaskod59035b2020-07-08 12:00:06 +020055 * @param[in,out] diff Diff to append to.
56 * @return LY_ERR value.
57 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +010058LIBYANG_API_DECL LY_ERR lyd_diff_add(const struct lyd_node *node, enum lyd_diff_op op, const char *orig_default, const char *orig_value,
Michal Vaskoe78faec2021-04-08 17:24:43 +020059 const char *key, const char *value, const char *position, const char *orig_key, const char *orig_position,
60 struct lyd_node **diff);
Michal Vaskod59035b2020-07-08 12:00:06 +020061
62#endif /* LY_DIFF_H_ */