From d94c5ba48b42a7ba28c9669b62f2790b30ce99d7 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Tue, 20 Apr 1999 22:26:50 +0000 Subject: [PATCH] add class; minor cleanups --- lib/dns/dbtable.c | 25 ++++++++++++++----------- lib/dns/include/dns/dbtable.h | 22 +++++++++++++--------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/lib/dns/dbtable.c b/lib/dns/dbtable.c index 6418950d8c..20f02776d7 100644 --- a/lib/dns/dbtable.c +++ b/lib/dns/dbtable.c @@ -16,7 +16,7 @@ */ /* - * $Id: dbtable.c,v 1.5 1999/04/14 12:29:39 tale Exp $ + * $Id: dbtable.c,v 1.6 1999/04/20 22:26:49 halley Exp $ */ /* @@ -37,8 +37,8 @@ struct dns_dbtable { /* Unlocked. */ unsigned int magic; isc_mem_t * mctx; + dns_rdataclass_t rdclass; isc_rwlock_t tree_lock; - /* XXXRTH need reference count? */ /* Locked by tree_lock. */ dns_rbt_t * rbt; dns_db_t * default_db; @@ -49,10 +49,11 @@ struct dns_dbtable { (dbtable)->magic == DBTABLE_MAGIC) dns_result_t -dns_dbtable_create(isc_mem_t *mctx, dns_dbtable_t **dbtablep) { +dns_dbtable_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, + dns_dbtable_t **dbtablep) +{ dns_dbtable_t *dbtable; - dns_result_t dresult; - dns_result_t iresult; + dns_result_t result; REQUIRE(mctx != NULL); REQUIRE(dbtablep != NULL && *dbtablep == NULL); @@ -61,24 +62,25 @@ dns_dbtable_create(isc_mem_t *mctx, dns_dbtable_t **dbtablep) { if (dbtable == NULL) return (DNS_R_NOMEMORY); - dresult = dns_rbt_create(mctx, NULL, NULL, &dbtable->rbt); - if (dresult != DNS_R_SUCCESS) { + result = dns_rbt_create(mctx, NULL, NULL, &dbtable->rbt); + if (result != DNS_R_SUCCESS) { isc_mem_put(mctx, dbtable, sizeof(*dbtable)); - return (dresult); + return (result); } - iresult = isc_rwlock_init(&dbtable->tree_lock, 0, 0); - if (iresult != ISC_R_SUCCESS) { + result = isc_rwlock_init(&dbtable->tree_lock, 0, 0); + if (result != ISC_R_SUCCESS) { dns_rbt_destroy(&dbtable->rbt); isc_mem_put(mctx, dbtable, sizeof(*dbtable)); UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_rwlock_init() failed: %s", - isc_result_totext(iresult)); + isc_result_totext(result)); return (DNS_R_UNEXPECTED); } dbtable->default_db = NULL; dbtable->mctx = mctx; + dbtable->rdclass = rdclass; dbtable->magic = DBTABLE_MAGIC; *dbtablep = dbtable; @@ -120,6 +122,7 @@ dns_dbtable_add(dns_dbtable_t *dbtable, dns_db_t *db) { dns_db_t *clone; REQUIRE(VALID_DBTABLE(dbtable)); + REQUIRE(dns_db_class(db) == dbtable->rdclass); clone = NULL; dns_db_attach(db, &clone); diff --git a/lib/dns/include/dns/dbtable.h b/lib/dns/include/dns/dbtable.h index ed8bdceb67..03018ec561 100644 --- a/lib/dns/include/dns/dbtable.h +++ b/lib/dns/include/dns/dbtable.h @@ -18,24 +18,23 @@ #include #include -#include - -typedef struct dns_dbtable dns_dbtable_t; +#include dns_result_t -dns_dbtable_create(isc_mem_t *mctx, dns_dbtable_t **dbtablep); +dns_dbtable_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, + dns_dbtable_t **dbtablep); /* - * Make a new dbtable. + * Make a new dbtable of class 'rdclass' * * Requires: * mctx != NULL * dbtablep != NULL && *dptablep == NULL - * - * Ensures: - * + * 'rdclass' is a valid class * * Returns: - * + * DNS_R_SUCCESS + * DNS_R_NOMEMORY + * DNS_R_UNEXPECTED */ void @@ -52,6 +51,11 @@ dns_result_t dns_dbtable_add(dns_dbtable_t *dbtable, dns_db_t *db); /* * Add 'db' to 'dbtable'. + * + * Requires: + * 'dbtable' is a valid dbtable. + * + * 'db' is a valid database with the same class as 'dbtable' */ void