Commit 62837b83 authored by Bob Halley's avatar Bob Halley
Browse files

version registry; API cleanups; comments; assertions

parent 48e6ddcb
......@@ -15,6 +15,10 @@
* SOFTWARE.
*/
/***
*** Imports
***/
#include <config.h>
#include <stddef.h>
......@@ -23,103 +27,160 @@
#include <isc/assertions.h>
#include <dns/db.h>
#include <dns/rdataset.h>
/***
*** Private Types
***/
typedef struct {
char * name;
dns_result_t (*create)(isc_mem_t *mctx, dns_name_t *name,
isc_boolean_t cache,
dns_rdataclass_t class,
unsigned int argc, char *argv[],
dns_db_t **dbp);
} impinfo_t;
/***
*** Supported DB Implementations Registry
***/
/*
* Supported database implementations must be registered here.
*
* It might be nice to generate this automatically some day.
*/
#include "rbtdb.h"
impinfo_t implementations[] = {
{ "rbt", dns_rbtdb_create },
{ NULL, NULL }
};
/***
*** Basic DB Methods
***/
dns_result_t
dns_db_create(isc_mem_t *mctx, char *db_type, dns_name_t *base,
dns_db_create(isc_mem_t *mctx, char *db_type, dns_name_t *origin,
isc_boolean_t cache, dns_rdataclass_t class,
unsigned int argc, char *argv[], dns_db_t **dbp)
{
/* find the create method for 'db_type', and call it. */
impinfo_t *impinfo;
/*
* Create a new database using implementation 'db_type'.
*/
REQUIRE(dbp != NULL && *dbp == NULL);
REQUIRE(dns_name_isabsolute(origin));
/* Temporary minor hack... */
if (strcasecmp(db_type, "rbt") == 0)
return (dns_rbtdb_create(mctx, base, cache, class, argc, argv,
dbp));
for (impinfo = implementations; impinfo->name != NULL; impinfo++)
if (strcasecmp(db_type, impinfo->name) == 0)
return ((impinfo->create)(mctx, origin, cache, class,
argc, argv, dbp));
return (DNS_R_NOTIMPLEMENTED);
return (DNS_R_NOTFOUND);
}
void
dns_db_attach(dns_db_t *source, dns_db_t **targetp) {
/*
* Attach *targetp to source.
*/
REQUIRE(DNS_DB_VALID(source));
REQUIRE(targetp != NULL);
(source->methods->attach)(source, targetp);
ENSURE(*targetp == source);
}
void
dns_db_detach(dns_db_t **dbp) {
REQUIRE(dbp != NULL);
REQUIRE(DNS_DB_VALID(*dbp));
((*dbp)->methods->detach)(dbp);
}
void
dns_db_shutdown(dns_db_t *db) {
/*
* db will go away when there are no open versions, no direct external
* references, and no in-use nodes (i.e. indirect external references).
* Detach *dbp from its database.
*/
REQUIRE(DNS_DB_VALID(db));
(db->methods->shutdown)(db);
}
void
dns_db_destroy(dns_db_t **dbp) {
REQUIRE(dbp != NULL);
REQUIRE(DNS_DB_VALID(*dbp));
((*dbp)->methods->shutdown)(*dbp);
((*dbp)->methods->detach)(dbp);
ENSURE(*dbp == NULL);
}
isc_boolean_t
dns_db_iscache(dns_db_t *db) {
/*
* Does 'db' have cache semantics?
*/
REQUIRE(DNS_DB_VALID(db));
return (db->cache);
if ((db->attributes & DNS_DBATTR_CACHE) != 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
isc_boolean_t
dns_db_iszone(dns_db_t *db) {
/*
* Does 'db' have zone semantics?
*/
REQUIRE(DNS_DB_VALID(db));
return (!db->cache);
if ((db->attributes & DNS_DBATTR_CACHE) == 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
dns_name_t *
dns_db_origin(dns_db_t *db) {
/*
* The origin of the database.
*/
REQUIRE(DNS_DB_VALID(db));
return (&db->base);
return (&db->origin);
}
dns_result_t
dns_db_load(dns_db_t *db, char *filename) {
/*
* Load master file 'filename' into 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE((db->attributes & DNS_DBATTR_LOADED) == 0);
return (db->methods->load(db, filename));
}
/*
* Version Operations.
*/
/***
*** Version Methods
***/
void
dns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp) {
/*
* Open the current version for reading.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(versionp != NULL && *versionp == NULL);
(db->methods->currentversion)(db, versionp);
}
......@@ -127,28 +188,52 @@ dns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp) {
dns_result_t
dns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp) {
/*
* Open a new version for reading and writing.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(versionp != NULL && *versionp == NULL);
return ((db->methods->newversion)(db, versionp));
}
void
dns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp) {
dns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp,
isc_boolean_t commit)
{
/*
* Close version '*versionp'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(versionp != NULL && *versionp != NULL);
(db->methods->closeversion)(db, versionp, commit);
(db->methods->closeversion)(db, versionp);
ENSURE(*versionp == NULL);
}
/*
* Node Operations.
*/
/***
*** Node Methods
***/
dns_result_t
dns_db_findnode(dns_db_t *db, dns_name_t *name,
isc_boolean_t create, dns_dbnode_t **nodep)
{
/*
* Find the node with name 'name'.
*
* WARNING: THIS API WILL BE CHANGING IN THE NEAR FUTURE.
*
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(dns_name_issubdomain(name, &db->origin));
REQUIRE(nodep != NULL && *nodep == NULL);
return ((db->methods->findnode)(db, name, create, nodep));
}
......@@ -156,7 +241,13 @@ dns_db_findnode(dns_db_t *db, dns_name_t *name,
void
dns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
/*
* Attach *targetp to source.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(source != NULL);
REQUIRE(targetp != NULL && *targetp == NULL);
(db->methods->attachnode)(db, source, targetp);
}
......@@ -164,17 +255,35 @@ dns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
void
dns_db_detachnode(dns_db_t *db, dns_dbnode_t **nodep) {
/*
* Detach *nodep from its node.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(nodep != NULL && *nodep != NULL);
(db->methods->detachnode)(db, nodep);
ENSURE(*nodep == NULL);
}
/***
*** Rdataset Methods
***/
dns_result_t
dns_db_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
dns_rdatatype_t type, dns_rdataset_t *rdataset)
{
/*
* Search for an rdataset of type 'type' at 'node' that are in version
* 'version' of 'db'. If found, make 'rdataset' refer to it.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(node != NULL);
REQUIRE(DNS_RDATASET_VALID(rdataset));
REQUIRE(rdataset->methods == NULL);
return ((db->methods->findrdataset)(db, node, version, type,
rdataset));
......@@ -182,20 +291,33 @@ dns_db_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
dns_result_t
dns_db_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
dns_rdataset_t *rdataset, dns_addmode_t mode)
dns_rdataset_t *rdataset)
{
/*
* Add 'rdataset' to 'node' in version 'version' of 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(node != NULL);
REQUIRE(version != NULL);
REQUIRE(DNS_RDATASET_VALID(rdataset));
REQUIRE(rdataset->methods != NULL);
return ((db->methods->addrdataset)(db, node, version, rdataset, mode));
return ((db->methods->addrdataset)(db, node, version, rdataset));
}
dns_result_t
dns_db_deleterdataset(dns_db_t *db, dns_dbnode_t *node,
dns_dbversion_t *version, dns_rdatatype_t type)
{
/*
* Make it so that no rdataset of type 'type' exists at 'node' in
* version version 'version' of 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(node != NULL);
REQUIRE(version != NULL);
return ((db->methods->deleterdataset)(db, node, version, type));
}
/* Need a node rdataset list iterator. */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment