From d7eef25fbeccafffef76596fcfcf09809235cafc Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Thu, 11 Mar 1999 00:43:43 +0000 Subject: [PATCH] rdataset iterator support --- lib/dns/Makefile.in | 5 +- lib/dns/include/dns/Makefile.in | 4 +- lib/dns/include/dns/rdatasetiter.h | 177 +++++++++++++++++++++++++++++ lib/dns/rdatasetiter.c | 75 ++++++++++++ 4 files changed, 257 insertions(+), 4 deletions(-) create mode 100644 lib/dns/include/dns/rdatasetiter.h create mode 100644 lib/dns/rdatasetiter.c diff --git a/lib/dns/Makefile.in b/lib/dns/Makefile.in index e7aeea590a..280a880158 100644 --- a/lib/dns/Makefile.in +++ b/lib/dns/Makefile.in @@ -31,8 +31,9 @@ CDEFINES = CWARNINGS = OBJS = name.o db.o dbiterator.o rbt.o rbtdb.o rbtdb64.o \ - rdata.o rdatalist.o rdataset.o result.o version.o \ - rdataslab.o master.o callbacks.o compress.o + rdata.o rdatalist.o rdataset.o rdatasetiter.c \ + rdataslab.o master.o callbacks.o compress.o \ + result.o version.o SUBDIRS = include TARGETS = include/dns/enumtype.h include/dns/enumclass.h timestamp diff --git a/lib/dns/include/dns/Makefile.in b/lib/dns/include/dns/Makefile.in index 82436488f8..bf9b714e3a 100644 --- a/lib/dns/include/dns/Makefile.in +++ b/lib/dns/include/dns/Makefile.in @@ -21,8 +21,8 @@ top_srcdir = @top_srcdir@ HEADERS = callbacks.h cert.h compress.h db.h dbiterator.h fixedname.h \ master.h name.h rbt.h rcode.h rdata.h rdataclass.h \ - rdatalist.h rdataset.h rdataslab.h rdatatype.h result.h \ - secalg.h types.h + rdatalist.h rdataset.h rdatasetiter.h rdataslab.h \ + rdatatype.h result.h secalg.h types.h GENHEADERS = enumclass.h enumtype.h SUBDIRS = diff --git a/lib/dns/include/dns/rdatasetiter.h b/lib/dns/include/dns/rdatasetiter.h new file mode 100644 index 0000000000..079e310f93 --- /dev/null +++ b/lib/dns/include/dns/rdatasetiter.h @@ -0,0 +1,177 @@ +/* + * Copyright (C) 1999 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#ifndef DNS_RDATASETITER_H +#define DNS_RDATASETITER_H 1 + +/***** + ***** Module Info + *****/ + +/* + * DNS Rdataset Iterator + * + * The DNS Rdataset Iterator interface allows iteration of all of the + * rdatasets at a node. + * + * The dns_rdatasetiter_t type is like a "virtual class". To actually use + * it, an implementation of the class is required. This implementation is + * supplied by the database. + * + * It is the client's responsibility to call dns_db_detachnode() on all + * nodes returned. + * + * XXX XXX + * + * MP: + * The iterator itself is not locked. The caller must ensure + * synchronization. + * + * The iterator methods ensure appropriate database locking. + * + * Reliability: + * No anticipated impact. + * + * Resources: + * + * + * Security: + * No anticipated impact. + * + * Standards: + * None. + */ + +/***** + ***** Imports + *****/ + +#include +#include +#include + +#include +#include + +ISC_LANG_BEGINDECLS + +/***** + ***** Types + *****/ + +typedef struct dns_rdatasetitermethods { + void (*destroy)(dns_rdatasetiter_t **iteratorp); + dns_result_t (*first)(dns_rdatasetiter_t *iterator); + dns_result_t (*next)(dns_rdatasetiter_t *iterator); + dns_result_t (*current)(dns_rdatasetiter_t *iterator, + dns_rdataset_t *rdataset); +} dns_rdatasetitermethods_t; + +#define DNS_RDATASETITER_MAGIC 0x444E5369U /* DNSi. */ +#define DNS_RDATASETITER_VALID(dbi) ((dbi) != NULL && \ + (dbi)->magic == \ + DNS_RDATASETITER_MAGIC) + +/* + * This structure is actually just the common prefix of a DNS db + * implementation's version of a dns_rdatasetiter_t. + * + * Direct use of this structure by clients is forbidden. DB implementations + * may change the structure. 'magic' must be DNS_RDATASETITER_MAGIC for + * any of the dns_rdatasetiter routines to work. DB implementations must + * maintain all DB rdataset iterator invariants. + */ +struct dns_rdatasetiter { + /* Unlocked. */ + unsigned int magic; + dns_rdatasetitermethods_t * methods; + dns_db_t * db; + dns_dbnode_t * node; + dns_dbversion_t * version; +}; + +void +dns_rdatasetiter_destroy(dns_rdatasetiter_t **iteratorp); +/* + * Destroy '*iteratorp'. + * + * Requires: + * + * '*iteratorp' is a valid iterator. + * + * Ensures: + * + * All resources used by the iterator are freed. + * + * *iteratorp == NULL. + */ + +dns_result_t +dns_rdatasetiter_first(dns_rdatasetiter_t *iterator); +/* + * Move the rdataset cursor to the first rdataset at the node (if any). + * + * Requires: + * 'iterator' is a valid iterator. + * + * Returns: + * DNS_R_SUCCESS + * DNS_R_NOMORE There are no rdatasets at the node. + * + * Other results are possible, depending on the DB implementation. + */ + +dns_result_t +dns_rdatasetiter_next(dns_rdatasetiter_t *iterator); +/* + * Move the rdataset cursor to the next rdataset at the node (if any). + * + * Requires: + * 'iterator' is a valid iterator. + * + * Returns: + * DNS_R_SUCCESS + * DNS_R_NOMORE There are no more rdatasets at the + * node. + * + * Other results are possible, depending on the DB implementation. + */ + +dns_result_t +dns_rdatasetiter_current(dns_rdatasetiter_t *iterator, + dns_rdataset_t *rdataset); +/* + * Return the current rdataset. + * + * Requires: + * 'iterator' is a valid iterator. + * + * 'rdataset' is a valid, disassociated rdataset. + * + * The rdataset cursor of 'iterator' is at a valid location (i.e. the + * result of last call to a cursor movement command was DNS_R_SUCCESS). + * + * Returns: + * + * DNS_R_SUCCESS + * + * Other results are possible, depending on the DB implementation. + */ + +ISC_LANG_ENDDECLS + +#endif /* DNS_RDATASETITER_H */ diff --git a/lib/dns/rdatasetiter.c b/lib/dns/rdatasetiter.c new file mode 100644 index 0000000000..88f583dc2e --- /dev/null +++ b/lib/dns/rdatasetiter.c @@ -0,0 +1,75 @@ +/* + * Copyright (C) 1999 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#include + +#include + +#include + +#include + +void +dns_rdatasetiter_destroy(dns_rdatasetiter_t **iteratorp) { + /* + * Destroy '*iteratorp'. + */ + + REQUIRE(iteratorp != NULL); + REQUIRE(DNS_RDATASETITER_VALID(*iteratorp)); + + (*iteratorp)->methods->destroy(iteratorp); + + ENSURE(*iteratorp == NULL); +} + +dns_result_t +dns_rdatasetiter_first(dns_rdatasetiter_t *iterator) { + /* + * Move the rdataset cursor to the first rdataset at the node (if any). + */ + + REQUIRE(DNS_RDATASETITER_VALID(iterator)); + + return (iterator->methods->first(iterator)); +} + +dns_result_t +dns_rdatasetiter_next(dns_rdatasetiter_t *iterator) { + /* + * Move the rdataset cursor to the next rdataset at the node (if any). + */ + + REQUIRE(DNS_RDATASETITER_VALID(iterator)); + + return (iterator->methods->next(iterator)); +} + +dns_result_t +dns_rdatasetiter_current(dns_rdatasetiter_t *iterator, + dns_rdataset_t *rdataset) +{ + /* + * Return the current rdataset. + */ + + REQUIRE(DNS_RDATASETITER_VALID(iterator)); + REQUIRE(DNS_RDATASET_VALID(rdataset)); + REQUIRE(rdataset->methods == NULL); + + return (iterator->methods->current(iterator, rdataset)); +}