blob: c2f1d068150df42a761fffdb81ef78b012af15ba [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/**
Michal Vaskoe78faec2021-04-08 17:24:43 +020034 * @brief Internal structure for remembering "used" instances of lists with duplicate instances allowed.
35 */
36struct lyd_diff_dup_inst {
37 struct ly_set *inst_set;
38 uint32_t used;
39};
40
41/**
Michal Vaskod59035b2020-07-08 12:00:06 +020042 * @brief Diff operations.
43 */
44enum lyd_diff_op {
45 LYD_DIFF_OP_CREATE, /**< Subtree created. */
46 LYD_DIFF_OP_DELETE, /**< Subtree deleted. */
47 LYD_DIFF_OP_REPLACE, /**< Node value changed or (leaf-)list instance moved. */
Michal Vasko69730152020-10-09 16:30:07 +020048 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 +020049};
50
51/**
52 * @brief Add a new change into diff.
53 *
54 * @param[in] node Node (subtree) to add into diff.
55 * @param[in] op Operation to set.
56 * @param[in] orig_default Original default metadata to set.
57 * @param[in] orig_value Original value metadata to set.
58 * @param[in] key Key metadata to set.
59 * @param[in] value Value metadata to set.
Michal Vaskoe78faec2021-04-08 17:24:43 +020060 * @param[in] position Position metadata to set.
Michal Vaskod59035b2020-07-08 12:00:06 +020061 * @param[in] orig_key Original key metadata to set.
Michal Vaskoe78faec2021-04-08 17:24:43 +020062 * @param[in] orig_position Original position metadata to set.
Michal Vaskod59035b2020-07-08 12:00:06 +020063 * @param[in,out] diff Diff to append to.
64 * @return LY_ERR value.
65 */
66LY_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 +020067 const char *key, const char *value, const char *position, const char *orig_key, const char *orig_position,
68 struct lyd_node **diff);
Michal Vaskod59035b2020-07-08 12:00:06 +020069
70#endif /* LY_DIFF_H_ */