blob: dbfa37cb4d08e550deb46940981bc2e3cafad09b [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. */
40 LYD_DIFF_OP_NONE, /**< No change of an existing inner node or default flag change of a term node. */
41};
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.
52 * @param[in] orig_key Original key metadata to set.
53 * @param[in,out] diff Diff to append to.
54 * @return LY_ERR value.
55 */
56LY_ERR lyd_diff_add(const struct lyd_node *node, enum lyd_diff_op op, const char *orig_default, const char *orig_value,
Radek Krejci0f969882020-08-21 16:56:47 +020057 const char *key, const char *value, const char *orig_key, struct lyd_node **diff);
Michal Vaskod59035b2020-07-08 12:00:06 +020058
59#endif /* LY_DIFF_H_ */