db.c revision 1ccbfca64ae86ace521053773001cb995352f96f
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1999 Internet Software Consortium.
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * copyright notice and this permission notice appear in all copies.
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt *
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
aa7b16ec2a5dacda1d65b64e0f7af434d02cbba4Tinderbox User * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt * SOFTWARE.
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt */
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt#include <config.h>
aa7b16ec2a5dacda1d65b64e0f7af434d02cbba4Tinderbox User
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt#include <stddef.h>
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt#include <string.h>
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt#include <isc/assertions.h>
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt#include <dns/db.h>
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt#include "rbtdb.h"
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
e45d0508c3460db87afb1f743bc5210522721bb3Evan Huntdns_result_t
aa7b16ec2a5dacda1d65b64e0f7af434d02cbba4Tinderbox Userdns_db_create(isc_mem_t *mctx, char *db_type, isc_boolean_t cache,
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt dns_rdataclass_t class,
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt unsigned int argc, char *argv[], dns_db_t **dbp)
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt{
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt /* find the create method for 'db_type', and call it. */
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt /* Temporary minor hack... */
aa7b16ec2a5dacda1d65b64e0f7af434d02cbba4Tinderbox User if (strcasecmp(db_type, "rbt") == 0)
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt return (dns_rbtdb_create(mctx, cache, class, argc, argv,
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt dbp));
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt return (DNS_R_NOTIMPLEMENTED);
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt}
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
e45d0508c3460db87afb1f743bc5210522721bb3Evan Huntvoid
e45d0508c3460db87afb1f743bc5210522721bb3Evan Huntdns_db_attach(dns_db_t *source, dns_db_t **targetp) {
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
aa7b16ec2a5dacda1d65b64e0f7af434d02cbba4Tinderbox User REQUIRE(DNS_DB_VALID(source));
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt REQUIRE(targetp != NULL);
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt (source->methods->attach)(source, targetp);
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt}
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
e45d0508c3460db87afb1f743bc5210522721bb3Evan Huntvoid
e45d0508c3460db87afb1f743bc5210522721bb3Evan Huntdns_db_detach(dns_db_t **dbp) {
aa7b16ec2a5dacda1d65b64e0f7af434d02cbba4Tinderbox User
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt REQUIRE(dbp != NULL);
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt REQUIRE(DNS_DB_VALID(*dbp));
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt ((*dbp)->methods->detach)(dbp);
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt}
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
e45d0508c3460db87afb1f743bc5210522721bb3Evan Huntvoid
e45d0508c3460db87afb1f743bc5210522721bb3Evan Huntdns_db_shutdown(dns_db_t *db) {
aa7b16ec2a5dacda1d65b64e0f7af434d02cbba4Tinderbox User /*
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt * db will go away when there are no open versions, no direct external
aa7b16ec2a5dacda1d65b64e0f7af434d02cbba4Tinderbox User * references, and no in-use nodes (i.e. indirect external references).
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt */
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt REQUIRE(DNS_DB_VALID(db));
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt (db->methods->shutdown)(db);
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt}
aa7b16ec2a5dacda1d65b64e0f7af434d02cbba4Tinderbox User
e45d0508c3460db87afb1f743bc5210522721bb3Evan Huntvoid
e45d0508c3460db87afb1f743bc5210522721bb3Evan Huntdns_db_destroy(dns_db_t **dbp) {
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
aa7b16ec2a5dacda1d65b64e0f7af434d02cbba4Tinderbox User REQUIRE(dbp != NULL);
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt REQUIRE(DNS_DB_VALID(*dbp));
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt
((*dbp)->methods->shutdown)(*dbp);
((*dbp)->methods->detach)(dbp);
}
isc_boolean_t
dns_db_iscache(dns_db_t *db) {
REQUIRE(DNS_DB_VALID(db));
return (db->cache);
}
isc_boolean_t
dns_db_iszone(dns_db_t *db) {
REQUIRE(DNS_DB_VALID(db));
return (!db->cache);
}
/*
* Version Operations.
*/
void
dns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp) {
REQUIRE(DNS_DB_VALID(db));
(db->methods->currentversion)(db, versionp);
}
dns_result_t
dns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp) {
REQUIRE(DNS_DB_VALID(db));
return ((db->methods->newversion)(db, versionp));
}
void
dns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp) {
REQUIRE(DNS_DB_VALID(db));
(db->methods->closeversion)(db, versionp);
}
/*
* Node Operations.
*/
dns_result_t
dns_db_findnode(dns_db_t *db, dns_name_t *name,
isc_boolean_t create, dns_dbnode_t **nodep)
{
REQUIRE(DNS_DB_VALID(db));
return ((db->methods->findnode)(db, name, create, nodep));
}
void
dns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
REQUIRE(DNS_DB_VALID(db));
(db->methods->attachnode)(db, source, targetp);
}
void
dns_db_detachnode(dns_db_t *db, dns_dbnode_t **nodep) {
REQUIRE(DNS_DB_VALID(db));
(db->methods->detachnode)(db, nodep);
}
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)
{
REQUIRE(DNS_DB_VALID(db));
return ((db->methods->findrdataset)(db, node, version, type,
rdataset));
}
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)
{
REQUIRE(DNS_DB_VALID(db));
return ((db->methods->addrdataset)(db, node, version, rdataset, mode));
}
dns_result_t
dns_db_deleterdataset(dns_db_t *db, dns_dbnode_t *node,
dns_dbversion_t *version, dns_rdatatype_t type)
{
REQUIRE(DNS_DB_VALID(db));
return ((db->methods->deleterdataset)(db, node, version, type));
}
/* Need a node rdataset list iterator. */