2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 23:25:38 +00:00

add class; minor cleanups

This commit is contained in:
Bob Halley
1999-04-20 22:26:50 +00:00
parent 48481c9b6e
commit d94c5ba48b
2 changed files with 27 additions and 20 deletions

View File

@@ -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. */ /* Unlocked. */
unsigned int magic; unsigned int magic;
isc_mem_t * mctx; isc_mem_t * mctx;
dns_rdataclass_t rdclass;
isc_rwlock_t tree_lock; isc_rwlock_t tree_lock;
/* XXXRTH need reference count? */
/* Locked by tree_lock. */ /* Locked by tree_lock. */
dns_rbt_t * rbt; dns_rbt_t * rbt;
dns_db_t * default_db; dns_db_t * default_db;
@@ -49,10 +49,11 @@ struct dns_dbtable {
(dbtable)->magic == DBTABLE_MAGIC) (dbtable)->magic == DBTABLE_MAGIC)
dns_result_t 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_dbtable_t *dbtable;
dns_result_t dresult; dns_result_t result;
dns_result_t iresult;
REQUIRE(mctx != NULL); REQUIRE(mctx != NULL);
REQUIRE(dbtablep != NULL && *dbtablep == NULL); REQUIRE(dbtablep != NULL && *dbtablep == NULL);
@@ -61,24 +62,25 @@ dns_dbtable_create(isc_mem_t *mctx, dns_dbtable_t **dbtablep) {
if (dbtable == NULL) if (dbtable == NULL)
return (DNS_R_NOMEMORY); return (DNS_R_NOMEMORY);
dresult = dns_rbt_create(mctx, NULL, NULL, &dbtable->rbt); result = dns_rbt_create(mctx, NULL, NULL, &dbtable->rbt);
if (dresult != DNS_R_SUCCESS) { if (result != DNS_R_SUCCESS) {
isc_mem_put(mctx, dbtable, sizeof(*dbtable)); isc_mem_put(mctx, dbtable, sizeof(*dbtable));
return (dresult); return (result);
} }
iresult = isc_rwlock_init(&dbtable->tree_lock, 0, 0); result = isc_rwlock_init(&dbtable->tree_lock, 0, 0);
if (iresult != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
dns_rbt_destroy(&dbtable->rbt); dns_rbt_destroy(&dbtable->rbt);
isc_mem_put(mctx, dbtable, sizeof(*dbtable)); isc_mem_put(mctx, dbtable, sizeof(*dbtable));
UNEXPECTED_ERROR(__FILE__, __LINE__, UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_rwlock_init() failed: %s", "isc_rwlock_init() failed: %s",
isc_result_totext(iresult)); isc_result_totext(result));
return (DNS_R_UNEXPECTED); return (DNS_R_UNEXPECTED);
} }
dbtable->default_db = NULL; dbtable->default_db = NULL;
dbtable->mctx = mctx; dbtable->mctx = mctx;
dbtable->rdclass = rdclass;
dbtable->magic = DBTABLE_MAGIC; dbtable->magic = DBTABLE_MAGIC;
*dbtablep = dbtable; *dbtablep = dbtable;
@@ -120,6 +122,7 @@ dns_dbtable_add(dns_dbtable_t *dbtable, dns_db_t *db) {
dns_db_t *clone; dns_db_t *clone;
REQUIRE(VALID_DBTABLE(dbtable)); REQUIRE(VALID_DBTABLE(dbtable));
REQUIRE(dns_db_class(db) == dbtable->rdclass);
clone = NULL; clone = NULL;
dns_db_attach(db, &clone); dns_db_attach(db, &clone);

View File

@@ -18,24 +18,23 @@
#include <isc/mem.h> #include <isc/mem.h>
#include <dns/result.h> #include <dns/result.h>
#include <dns/name.h> #include <dns/types.h>
typedef struct dns_dbtable dns_dbtable_t;
dns_result_t 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: * Requires:
* mctx != NULL * mctx != NULL
* dbtablep != NULL && *dptablep == NULL * dbtablep != NULL && *dptablep == NULL
* * 'rdclass' is a valid class
* Ensures:
*
* *
* Returns: * Returns:
* * DNS_R_SUCCESS
* DNS_R_NOMEMORY
* DNS_R_UNEXPECTED
*/ */
void void
@@ -52,6 +51,11 @@ dns_result_t
dns_dbtable_add(dns_dbtable_t *dbtable, dns_db_t *db); dns_dbtable_add(dns_dbtable_t *dbtable, dns_db_t *db);
/* /*
* Add 'db' to 'dbtable'. * Add 'db' to 'dbtable'.
*
* Requires:
* 'dbtable' is a valid dbtable.
*
* 'db' is a valid database with the same class as 'dbtable'
*/ */
void void