2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: diff.h,v 1.4.12.3 2004/03/08 09:04:35 marka Exp $ */
28 * A diff is a convenience type representing a list of changes to be
37 #include <isc/magic.h>
40 #include <dns/rdata.h>
41 #include <dns/types.h>
48 * A dns_difftuple_t represents a single RR being added or deleted.
49 * The RR type and class are in the 'rdata' member; the class is always
50 * the real one, not a DynDNS meta-class, so that the rdatas can be
51 * compared using dns_rdata_compare(). The TTL is significant
52 * even for deletions, because a deletion/addition pair cannot
53 * be canceled out if the TTL differs (it might be an explicit
56 * Tuples are also used to represent complete RRs with owner
57 * names for a couple of other purposes, such as the
58 * individual RRs of a "RRset exists (value dependent)"
59 * prerequisite set. In this case, op==DNS_DIFFOP_EXISTS,
60 * and the TTL is ignored.
64 DNS_DIFFOP_ADD, /* Add an RR. */
65 DNS_DIFFOP_DEL, /* Delete an RR. */
66 DNS_DIFFOP_EXISTS /* Assert RR existence. */
69 typedef struct dns_difftuple dns_difftuple_t;
71 #define DNS_DIFFTUPLE_MAGIC ISC_MAGIC('D','I','F','T')
72 #define DNS_DIFFTUPLE_VALID(t) ISC_MAGIC_VALID(t, DNS_DIFFTUPLE_MAGIC)
74 struct dns_difftuple {
81 ISC_LINK(dns_difftuple_t) link;
82 /* Variable-size name data and rdata follows. */
86 * A dns_diff_t represents a set of changes being applied to
87 * a zone. Diffs are also used to represent "RRset exists
88 * (value dependent)" prerequisites.
90 typedef struct dns_diff dns_diff_t;
92 #define DNS_DIFF_MAGIC ISC_MAGIC('D','I','F','F')
93 #define DNS_DIFF_VALID(t) ISC_MAGIC_VALID(t, DNS_DIFF_MAGIC)
98 ISC_LIST(dns_difftuple_t) tuples;
101 /* Type of comparision function for sorting diffs. */
102 typedef int dns_diff_compare_func(const void *, const void *);
110 /**************************************************************************/
112 * Maniuplation of diffs and tuples.
116 dns_difftuple_create(isc_mem_t *mctx,
117 dns_diffop_t op, dns_name_t *name, dns_ttl_t ttl,
118 dns_rdata_t *rdata, dns_difftuple_t **tp);
120 * Create a tuple. Deep copies are made of the name and rdata, so
121 * they need not remain valid after the call.
124 * *tp != NULL && *tp == NULL.
132 dns_difftuple_free(dns_difftuple_t **tp);
137 * **tp is a valid tuple.
141 * All memory used by the tuple is freed.
145 dns_difftuple_copy(dns_difftuple_t *orig, dns_difftuple_t **copyp);
150 * 'orig' points to a valid tuple
151 * copyp != NULL && *copyp == NULL
155 dns_diff_init(isc_mem_t *mctx, dns_diff_t *diff);
160 * 'diff' points to an uninitialized dns_diff_t
161 * allocated by the caller.
164 * '*diff' is a valid, empty diff.
168 dns_diff_clear(dns_diff_t *diff);
170 * Clear a diff, destroying all its tuples.
173 * 'diff' points to a valid dns_diff_t.
176 * Any tuples in the diff are destroyed.
177 * The diff now empty, but it is still valid
178 * and may be reused without calling dns_diff_init
179 * again. The only memory used is that of the
180 * dns_diff_t structure itself.
183 * Managing the memory of the dns_diff_t structure itself
184 * is the caller's responsibility.
188 dns_diff_append(dns_diff_t *diff, dns_difftuple_t **tuple);
190 * Append a single tuple to a diff.
192 * 'diff' is a valid diff.
193 * '*tuple' is a valid tuple.
197 * The tuple has been freed, or will be freed when the diff is cleared.
201 dns_diff_appendminimal(dns_diff_t *diff, dns_difftuple_t **tuple);
203 * Append 'tuple' to 'diff', removing any duplicate
204 * or conflicting updates as needed to create a minimal diff.
207 * 'diff' is a minimal diff.
210 * 'diff' is still a minimal diff.
212 * The tuple has been freed, or will be freed when the diff is cleared.
217 dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare);
219 * Sort 'diff' in-place according to the comparison function 'compare'.
223 dns_diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver);
225 dns_diff_applysilently(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver);
227 * Apply 'diff' to the database 'db'.
229 * dns_diff_apply() logs warnings about updates with no effect or
230 * with inconsistent TTLs; dns_diff_applysilently() does not.
232 * For efficiency, the diff should be sorted by owner name.
233 * If it is not sorted, operation will still be correct,
234 * but less efficient.
237 * *diff is a valid diff (possibly empty), containing
238 * tuples of type DNS_DIFFOP_ADD and/or
239 * For DNS_DIFFOP_DEL tuples, the TTL is ignored.
244 dns_diff_load(dns_diff_t *diff, dns_addrdatasetfunc_t addfunc,
247 * Like dns_diff_apply, but for use when loading a new database
248 * instead of modifying an existing one. This bypasses the
249 * database transaction mechanisms.
252 * 'addfunc' is a valid dns_addradatasetfunc_t obtained from
255 * 'add_private' points to a corresponding dns_dbload_t *
256 * (XXX why is it a void pointer, then?)
260 dns_diff_print(dns_diff_t *diff, FILE *file);
263 * Print the differences to 'file' or if 'file' is NULL via the
267 * 'diff' to be valid.
268 * 'file' to refer to a open file or NULL.
274 * any error from dns_rdataset_totext()
279 #endif /* DNS_DIFF_H */