dbiterator.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1999-2001  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: dbiterator.h,v 1.25 2007/06/19 23:47:16 tbox Exp $ */
00019 
00020 #ifndef DNS_DBITERATOR_H
00021 #define DNS_DBITERATOR_H 1
00022 
00023 /*****
00024  ***** Module Info
00025  *****/
00026 
00027 /*! \file dns/dbiterator.h
00028  * \brief
00029  * The DNS DB Iterator interface allows iteration of all of the nodes in a
00030  * database.
00031  *
00032  * The dns_dbiterator_t type is like a "virtual class".  To actually use
00033  * it, an implementation of the class is required.  This implementation is
00034  * supplied by the database.
00035  *
00036  * It is the client's responsibility to call dns_db_detachnode() on all
00037  * nodes returned.
00038  *
00039  * XXX <more> XXX
00040  *
00041  * MP:
00042  *\li   The iterator itself is not locked.  The caller must ensure
00043  *      synchronization.
00044  *
00045  *\li   The iterator methods ensure appropriate database locking.
00046  *
00047  * Reliability:
00048  *\li   No anticipated impact.
00049  *
00050  * Resources:
00051  *\li   TBS
00052  *
00053  * Security:
00054  *\li   No anticipated impact.
00055  *
00056  * Standards:
00057  *\li   None.
00058  */
00059 
00060 /*****
00061  ***** Imports
00062  *****/
00063 
00064 #include <isc/lang.h>
00065 #include <isc/magic.h>
00066 
00067 #include <dns/types.h>
00068 
00069 ISC_LANG_BEGINDECLS
00070 
00071 /*****
00072  ***** Types
00073  *****/
00074 
00075 typedef struct dns_dbiteratormethods {
00076         void            (*destroy)(dns_dbiterator_t **iteratorp);
00077         isc_result_t    (*first)(dns_dbiterator_t *iterator);
00078         isc_result_t    (*last)(dns_dbiterator_t *iterator);
00079         isc_result_t    (*seek)(dns_dbiterator_t *iterator, dns_name_t *name);
00080         isc_result_t    (*prev)(dns_dbiterator_t *iterator);
00081         isc_result_t    (*next)(dns_dbiterator_t *iterator);
00082         isc_result_t    (*current)(dns_dbiterator_t *iterator,
00083                                    dns_dbnode_t **nodep, dns_name_t *name);
00084         isc_result_t    (*pause)(dns_dbiterator_t *iterator);
00085         isc_result_t    (*origin)(dns_dbiterator_t *iterator,
00086                                   dns_name_t *name);
00087 } dns_dbiteratormethods_t;
00088 
00089 #define DNS_DBITERATOR_MAGIC         ISC_MAGIC('D','N','S','I')
00090 #define DNS_DBITERATOR_VALID(dbi)    ISC_MAGIC_VALID(dbi, DNS_DBITERATOR_MAGIC)
00091 /*%
00092  * This structure is actually just the common prefix of a DNS db
00093  * implementation's version of a dns_dbiterator_t.
00094  *
00095  * Clients may use the 'db' field of this structure.  Except for that field,
00096  * direct use of this structure by clients is forbidden.  DB implementations
00097  * may change the structure.  'magic' must be DNS_DBITERATOR_MAGIC for any of
00098  * the dns_dbiterator routines to work.  DB iterator implementations must
00099  * maintain all DB iterator invariants.
00100  */
00101 struct dns_dbiterator {
00102         /* Unlocked. */
00103         unsigned int                    magic;
00104         dns_dbiteratormethods_t *       methods;
00105         dns_db_t *                      db;
00106         isc_boolean_t                   relative_names;
00107         isc_boolean_t                   cleaning;
00108 };
00109 
00110 void
00111 dns_dbiterator_destroy(dns_dbiterator_t **iteratorp);
00112 /*%<
00113  * Destroy '*iteratorp'.
00114  *
00115  * Requires:
00116  *
00117  *\li   '*iteratorp' is a valid iterator.
00118  *
00119  * Ensures:
00120  *
00121  *\li   All resources used by the iterator are freed.
00122  *
00123  *\li   *iteratorp == NULL.
00124  */
00125 
00126 isc_result_t
00127 dns_dbiterator_first(dns_dbiterator_t *iterator);
00128 /*%<
00129  * Move the node cursor to the first node in the database (if any).
00130  *
00131  * Requires:
00132  *\li   'iterator' is a valid iterator.
00133  *
00134  * Returns:
00135  *\li   #ISC_R_SUCCESS
00136  *\li   #ISC_R_NOMORE                   There are no nodes in the database.
00137  *
00138  *\li   Other results are possible, depending on the DB implementation.
00139  */
00140 
00141 isc_result_t
00142 dns_dbiterator_last(dns_dbiterator_t *iterator);
00143 /*%<
00144  * Move the node cursor to the last node in the database (if any).
00145  *
00146  * Requires:
00147  *\li   'iterator' is a valid iterator.
00148  *
00149  * Returns:
00150  *\li   #ISC_R_SUCCESS
00151  *\li   #ISC_R_NOMORE                   There are no nodes in the database.
00152  *
00153  *\li   Other results are possible, depending on the DB implementation.
00154  */
00155 
00156 isc_result_t
00157 dns_dbiterator_seek(dns_dbiterator_t *iterator, dns_name_t *name);
00158 /*%<
00159  * Move the node cursor to the node with name 'name'.
00160  *
00161  * Requires:
00162  *\li   'iterator' is a valid iterator.
00163  *
00164  *\li   'name' is a valid name.
00165  *
00166  * Returns:
00167  *\li   #ISC_R_SUCCESS
00168  *\li   #ISC_R_NOTFOUND
00169  *
00170  *\li   Other results are possible, depending on the DB implementation.
00171  */
00172 
00173 isc_result_t
00174 dns_dbiterator_prev(dns_dbiterator_t *iterator);
00175 /*%<
00176  * Move the node cursor to the previous node in the database (if any).
00177  *
00178  * Requires:
00179  *\li   'iterator' is a valid iterator.
00180  *
00181  * Returns:
00182  *\li   #ISC_R_SUCCESS
00183  *\li   #ISC_R_NOMORE                   There are no more nodes in the
00184  *                                      database.
00185  *
00186  *\li   Other results are possible, depending on the DB implementation.
00187  */
00188 
00189 isc_result_t
00190 dns_dbiterator_next(dns_dbiterator_t *iterator);
00191 /*%<
00192  * Move the node cursor to the next node in the database (if any).
00193  *
00194  * Requires:
00195  *\li   'iterator' is a valid iterator.
00196  *
00197  * Returns:
00198  *\li   #ISC_R_SUCCESS
00199  *\li   #ISC_R_NOMORE                   There are no more nodes in the
00200  *                                      database.
00201  *
00202  *\li   Other results are possible, depending on the DB implementation.
00203  */
00204 
00205 isc_result_t
00206 dns_dbiterator_current(dns_dbiterator_t *iterator, dns_dbnode_t **nodep,
00207                        dns_name_t *name);
00208 /*%<
00209  * Return the current node.
00210  *
00211  * Notes:
00212  *\li   If 'name' is not NULL, it will be set to the name of the node.
00213  *
00214  * Requires:
00215  *\li   'iterator' is a valid iterator.
00216  *
00217  *\li   nodep != NULL && *nodep == NULL
00218  *
00219  *\li   The node cursor of 'iterator' is at a valid location (i.e. the
00220  *      result of last call to a cursor movement command was ISC_R_SUCCESS).
00221  *
00222  *\li   'name' is NULL, or is a valid name with a dedicated buffer.
00223  *
00224  * Returns:
00225  *
00226  *\li   #ISC_R_SUCCESS
00227  *\li   #DNS_R_NEWORIGIN                        If this iterator was created with
00228  *                                      'relative_names' set to ISC_TRUE,
00229  *                                      then #DNS_R_NEWORIGIN will be returned
00230  *                                      when the origin the names are
00231  *                                      relative to changes.  This result
00232  *                                      can occur only when 'name' is not
00233  *                                      NULL.  This is also a successful
00234  *                                      result.
00235  *
00236  *\li   Other results are possible, depending on the DB implementation.
00237  */
00238 
00239 isc_result_t
00240 dns_dbiterator_pause(dns_dbiterator_t *iterator);
00241 /*%<
00242  * Pause iteration.
00243  *
00244  * Calling a cursor movement method or dns_dbiterator_current() may cause
00245  * database locks to be acquired.  Rather than reacquire these locks every
00246  * time one of these routines is called, the locks may simply be held.
00247  * Calling dns_dbiterator_pause() releases any such locks.  Iterator clients
00248  * should call this routine any time they are not going to execute another
00249  * iterator method in the immediate future.
00250  *
00251  * Requires:
00252  *\li   'iterator' is a valid iterator.
00253  *
00254  * Ensures:
00255  *\li   Any database locks being held for efficiency of iterator access are
00256  *      released.
00257  *
00258  * Returns:
00259  *\li   #ISC_R_SUCCESS
00260  *
00261  *\li   Other results are possible, depending on the DB implementation.
00262  */
00263 
00264 isc_result_t
00265 dns_dbiterator_origin(dns_dbiterator_t *iterator, dns_name_t *name);
00266 /*%<
00267  * Return the origin to which returned node names are relative.
00268  *
00269  * Requires:
00270  *
00271  *\li   'iterator' is a valid relative_names iterator.
00272  *
00273  *\li   'name' is a valid name with a dedicated buffer.
00274  *
00275  * Returns:
00276  *
00277  *\li   #ISC_R_SUCCESS
00278  *\li   #ISC_R_NOSPACE
00279  *
00280  *\li   Other results are possible, depending on the DB implementation.
00281  */
00282 
00283 void
00284 dns_dbiterator_setcleanmode(dns_dbiterator_t *iterator, isc_boolean_t mode);
00285 /*%<
00286  * Indicate that the given iterator is/is not cleaning the DB.
00287  *
00288  * Notes:
00289  *\li   When 'mode' is ISC_TRUE, 
00290  *
00291  * Requires:
00292  *\li   'iterator' is a valid iterator.
00293  */
00294 
00295 ISC_LANG_ENDDECLS
00296 
00297 #endif /* DNS_DBITERATOR_H */

Generated on Tue Apr 28 17:40:57 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha