2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-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: dbiterator.h,v 1.18.206.1 2004/03/06 08:13:54 marka Exp $ */
20 #ifndef DNS_DBITERATOR_H
21 #define DNS_DBITERATOR_H 1
30 * The DNS DB Iterator interface allows iteration of all of the nodes in a
33 * The dns_dbiterator_t type is like a "virtual class". To actually use
34 * it, an implementation of the class is required. This implementation is
35 * supplied by the database.
37 * It is the client's responsibility to call dns_db_detachnode() on all
43 * The iterator itself is not locked. The caller must ensure
46 * The iterator methods ensure appropriate database locking.
49 * No anticipated impact.
55 * No anticipated impact.
66 #include <isc/magic.h>
68 #include <dns/types.h>
76 typedef struct dns_dbiteratormethods {
77 void (*destroy)(dns_dbiterator_t **iteratorp);
78 isc_result_t (*first)(dns_dbiterator_t *iterator);
79 isc_result_t (*last)(dns_dbiterator_t *iterator);
80 isc_result_t (*seek)(dns_dbiterator_t *iterator, dns_name_t *name);
81 isc_result_t (*prev)(dns_dbiterator_t *iterator);
82 isc_result_t (*next)(dns_dbiterator_t *iterator);
83 isc_result_t (*current)(dns_dbiterator_t *iterator,
84 dns_dbnode_t **nodep, dns_name_t *name);
85 isc_result_t (*pause)(dns_dbiterator_t *iterator);
86 isc_result_t (*origin)(dns_dbiterator_t *iterator,
88 } dns_dbiteratormethods_t;
90 #define DNS_DBITERATOR_MAGIC ISC_MAGIC('D','N','S','I')
91 #define DNS_DBITERATOR_VALID(dbi) ISC_MAGIC_VALID(dbi, DNS_DBITERATOR_MAGIC)
93 * This structure is actually just the common prefix of a DNS db
94 * implementation's version of a dns_dbiterator_t.
96 * Clients may use the 'db' field of this structure. Except for that field,
97 * direct use of this structure by clients is forbidden. DB implementations
98 * may change the structure. 'magic' must be DNS_DBITERATOR_MAGIC for any of
99 * the dns_dbiterator routines to work. DB iterator implementations must
100 * maintain all DB iterator invariants.
102 struct dns_dbiterator {
105 dns_dbiteratormethods_t * methods;
107 isc_boolean_t relative_names;
108 isc_boolean_t cleaning;
112 dns_dbiterator_destroy(dns_dbiterator_t **iteratorp);
114 * Destroy '*iteratorp'.
118 * '*iteratorp' is a valid iterator.
122 * All resources used by the iterator are freed.
124 * *iteratorp == NULL.
128 dns_dbiterator_first(dns_dbiterator_t *iterator);
130 * Move the node cursor to the first node in the database (if any).
133 * 'iterator' is a valid iterator.
137 * ISC_R_NOMORE There are no nodes in the database.
139 * Other results are possible, depending on the DB implementation.
143 dns_dbiterator_last(dns_dbiterator_t *iterator);
145 * Move the node cursor to the last node in the database (if any).
148 * 'iterator' is a valid iterator.
152 * ISC_R_NOMORE There are no nodes in the database.
154 * Other results are possible, depending on the DB implementation.
158 dns_dbiterator_seek(dns_dbiterator_t *iterator, dns_name_t *name);
160 * Move the node cursor to the node with name 'name'.
163 * 'iterator' is a valid iterator.
165 * 'name' is a valid name.
171 * Other results are possible, depending on the DB implementation.
175 dns_dbiterator_prev(dns_dbiterator_t *iterator);
177 * Move the node cursor to the previous node in the database (if any).
180 * 'iterator' is a valid iterator.
184 * ISC_R_NOMORE There are no more nodes in the
187 * Other results are possible, depending on the DB implementation.
191 dns_dbiterator_next(dns_dbiterator_t *iterator);
193 * Move the node cursor to the next node in the database (if any).
196 * 'iterator' is a valid iterator.
200 * ISC_R_NOMORE There are no more nodes in the
203 * Other results are possible, depending on the DB implementation.
207 dns_dbiterator_current(dns_dbiterator_t *iterator, dns_dbnode_t **nodep,
210 * Return the current node.
213 * If 'name' is not NULL, it will be set to the name of the node.
216 * 'iterator' is a valid iterator.
218 * nodep != NULL && *nodep == NULL
220 * The node cursor of 'iterator' is at a valid location (i.e. the
221 * result of last call to a cursor movement command was ISC_R_SUCCESS).
223 * 'name' is NULL, or is a valid name with a dedicated buffer.
228 * DNS_R_NEWORIGIN If this iterator was created with
229 * 'relative_names' set to ISC_TRUE,
230 * then DNS_R_NEWORIGIN will be returned
231 * when the origin the names are
232 * relative to changes. This result
233 * can occur only when 'name' is not
234 * NULL. This is also a successful
237 * Other results are possible, depending on the DB implementation.
241 dns_dbiterator_pause(dns_dbiterator_t *iterator);
245 * Calling a cursor movement method or dns_dbiterator_current() may cause
246 * database locks to be acquired. Rather than reacquire these locks every
247 * time one of these routines is called, the locks may simply be held.
248 * Calling dns_dbiterator_pause() releases any such locks. Iterator clients
249 * should call this routine any time they are not going to execute another
250 * iterator method in the immediate future.
253 * 'iterator' is a valid iterator.
256 * Any database locks being held for efficiency of iterator access are
262 * Other results are possible, depending on the DB implementation.
266 dns_dbiterator_origin(dns_dbiterator_t *iterator, dns_name_t *name);
268 * Return the origin to which returned node names are relative.
272 * 'iterator' is a valid relative_names iterator.
274 * 'name' is a valid name with a dedicated buffer.
281 * Other results are possible, depending on the DB implementation.
285 dns_dbiterator_setcleanmode(dns_dbiterator_t *iterator, isc_boolean_t mode);
287 * Indicate that the given iterator is/is not cleaning the DB.
290 * When 'mode' is ISC_TRUE,
293 * 'iterator' is a valid iterator.
298 #endif /* DNS_DBITERATOR_H */