db.c revision 62837b832f6a9999976d607eb0a9125bbbbb138b
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff/*
ca41b452ede6feaa9d8739ec3cae19389a7b0d03Bob Halley * Copyright (C) 1999 Internet Software Consortium.
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff *
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * Permission to use, copy, modify, and distribute this software for any
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * purpose with or without fee is hereby granted, provided that the above
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * copyright notice and this permission notice appear in all copies.
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff *
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * SOFTWARE.
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff */
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence/***
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence *** Imports
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff ***/
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff#include <config.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <stddef.h>
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff#include <string.h>
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
7df0472d8a76c83d2137bd9549414a30787d58cfBrian Wellington#include <isc/assertions.h>
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <dns/db.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <dns/rdataset.h>
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff/***
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff *** Private Types
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence ***/
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Grafftypedef struct {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff char * name;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff dns_result_t (*create)(isc_mem_t *mctx, dns_name_t *name,
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff isc_boolean_t cache,
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff dns_rdataclass_t class,
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff unsigned int argc, char *argv[],
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence dns_db_t **dbp);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff} impinfo_t;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff/***
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff *** Supported DB Implementations Registry
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ***/
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff/*
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * Supported database implementations must be registered here.
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff *
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * It might be nice to generate this automatically some day.
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff */
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff#include "rbtdb.h"
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffimpinfo_t implementations[] = {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff { "rbt", dns_rbtdb_create },
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff { NULL, NULL }
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff};
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff/***
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff *** Basic DB Methods
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ***/
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffdns_result_t
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencedns_db_create(isc_mem_t *mctx, char *db_type, dns_name_t *origin,
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff isc_boolean_t cache, dns_rdataclass_t class,
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff unsigned int argc, char *argv[], dns_db_t **dbp)
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff{
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence impinfo_t *impinfo;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff /*
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * Create a new database using implementation 'db_type'.
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff */
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff REQUIRE(dbp != NULL && *dbp == NULL);
58ff88cca7c169f7fbebc9b6e93bbba1fb345157Michael Graff REQUIRE(dns_name_isabsolute(origin));
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff for (impinfo = implementations; impinfo->name != NULL; impinfo++)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff if (strcasecmp(db_type, impinfo->name) == 0)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff return ((impinfo->create)(mctx, origin, cache, class,
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff argc, argv, dbp));
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence return (DNS_R_NOTFOUND);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff}
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffvoid
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffdns_db_attach(dns_db_t *source, dns_db_t **targetp) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff /*
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * Attach *targetp to source.
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff */
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff REQUIRE(DNS_DB_VALID(source));
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff REQUIRE(targetp != NULL);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff (source->methods->attach)(source, targetp);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ENSURE(*targetp == source);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff}
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffvoid
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffdns_db_detach(dns_db_t **dbp) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff /*
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * Detach *dbp from its database.
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff */
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff REQUIRE(dbp != NULL);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff REQUIRE(DNS_DB_VALID(*dbp));
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ((*dbp)->methods->detach)(dbp);
58ff88cca7c169f7fbebc9b6e93bbba1fb345157Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff ENSURE(*dbp == NULL);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff}
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffisc_boolean_t
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffdns_db_iscache(dns_db_t *db) {
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence /*
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff * Does 'db' have cache semantics?
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff */
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff REQUIRE(DNS_DB_VALID(db));
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff if ((db->attributes & DNS_DBATTR_CACHE) != 0)
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff return (ISC_TRUE);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff return (ISC_FALSE);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff}
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffisc_boolean_t
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffdns_db_iszone(dns_db_t *db) {
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff /*
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff * Does 'db' have zone semantics?
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff */
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff REQUIRE(DNS_DB_VALID(db));
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff if ((db->attributes & DNS_DBATTR_CACHE) == 0)
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff return (ISC_TRUE);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff return (ISC_FALSE);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff}
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffdns_name_t *
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffdns_db_origin(dns_db_t *db) {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff /*
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff * The origin of the database.
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence */
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff REQUIRE(DNS_DB_VALID(db));
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff return (&db->origin);
e24f605ad64182532640dc6721070456b13112d5Michael Graff}
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffdns_result_t
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graffdns_db_load(dns_db_t *db, char *filename) {
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff /*
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff * Load master file 'filename' into 'db'.
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff */
4e675038a097065ff13944232cd7c89ac5961984Michael Graff
4e675038a097065ff13944232cd7c89ac5961984Michael Graff REQUIRE(DNS_DB_VALID(db));
4e675038a097065ff13944232cd7c89ac5961984Michael Graff REQUIRE((db->attributes & DNS_DBATTR_LOADED) == 0);
4e675038a097065ff13944232cd7c89ac5961984Michael Graff
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff return (db->methods->load(db, filename));
4e675038a097065ff13944232cd7c89ac5961984Michael Graff}
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff/***
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff *** Version Methods
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff ***/
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graffvoid
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graffdns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp) {
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff /*
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff * Open the current version for reading.
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff */
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff REQUIRE(DNS_DB_VALID(db));
e24f605ad64182532640dc6721070456b13112d5Michael Graff REQUIRE(versionp != NULL && *versionp == NULL);
e24f605ad64182532640dc6721070456b13112d5Michael Graff
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff (db->methods->currentversion)(db, versionp);
e24f605ad64182532640dc6721070456b13112d5Michael Graff}
e24f605ad64182532640dc6721070456b13112d5Michael Graff
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graffdns_result_t
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graffdns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp) {
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff /*
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff * Open a new version for reading and writing.
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff */
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff REQUIRE(DNS_DB_VALID(db));
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence REQUIRE(versionp != NULL && *versionp == NULL);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff return ((db->methods->newversion)(db, versionp));
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff}
e24f605ad64182532640dc6721070456b13112d5Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graffvoid
e24f605ad64182532640dc6721070456b13112d5Michael Graffdns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp,
e24f605ad64182532640dc6721070456b13112d5Michael Graff isc_boolean_t commit)
e24f605ad64182532640dc6721070456b13112d5Michael Graff{
e24f605ad64182532640dc6721070456b13112d5Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graff /*
e24f605ad64182532640dc6721070456b13112d5Michael Graff * Close version '*versionp'.
e24f605ad64182532640dc6721070456b13112d5Michael Graff */
e24f605ad64182532640dc6721070456b13112d5Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graff REQUIRE(DNS_DB_VALID(db));
e24f605ad64182532640dc6721070456b13112d5Michael Graff REQUIRE(versionp != NULL && *versionp != NULL);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff (db->methods->closeversion)(db, versionp, commit);
e24f605ad64182532640dc6721070456b13112d5Michael Graff
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff ENSURE(*versionp == NULL);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff}
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff/***
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff *** Node Methods
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff ***/
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffdns_result_t
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffdns_db_findnode(dns_db_t *db, dns_name_t *name,
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_boolean_t create, dns_dbnode_t **nodep)
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff{
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff /*
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff * Find the node with name 'name'.
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff *
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff * WARNING: THIS API WILL BE CHANGING IN THE NEAR FUTURE.
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff *
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff */
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff REQUIRE(DNS_DB_VALID(db));
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff REQUIRE(dns_name_issubdomain(name, &db->origin));
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff REQUIRE(nodep != NULL && *nodep == NULL);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence return ((db->methods->findnode)(db, name, create, nodep));
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff}
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
74889a341cac183d477e15cfead391a8f7bdba95Michael Graffvoid
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffdns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff * Attach *targetp to source.
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff */
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff REQUIRE(DNS_DB_VALID(db));
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff REQUIRE(source != NULL);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff REQUIRE(targetp != NULL && *targetp == NULL);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff (db->methods->attachnode)(db, source, targetp);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff}
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffvoid
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffdns_db_detachnode(dns_db_t *db, dns_dbnode_t **nodep) {
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff /*
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff * Detach *nodep from its node.
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff */
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff
efe2f579ba6fbec4229129015780f2d925085b04Michael Graff REQUIRE(DNS_DB_VALID(db));
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff REQUIRE(nodep != NULL && *nodep != NULL);
efe2f579ba6fbec4229129015780f2d925085b04Michael Graff
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff (db->methods->detachnode)(db, nodep);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff ENSURE(*nodep == NULL);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff}
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff/***
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff *** Rdataset Methods
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff ***/
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffdns_result_t
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graffdns_db_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff dns_rdatatype_t type, dns_rdataset_t *rdataset)
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff{
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff /*
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff * Search for an rdataset of type 'type' at 'node' that are in version
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff * 'version' of 'db'. If found, make 'rdataset' refer to it.
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff */
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graff REQUIRE(DNS_DB_VALID(db));
4e675038a097065ff13944232cd7c89ac5961984Michael Graff REQUIRE(node != NULL);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff REQUIRE(DNS_RDATASET_VALID(rdataset));
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff REQUIRE(rdataset->methods == NULL);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff return ((db->methods->findrdataset)(db, node, version, type,
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff rdataset));
e24f605ad64182532640dc6721070456b13112d5Michael Graff}
e24f605ad64182532640dc6721070456b13112d5Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graffdns_result_t
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffdns_db_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff dns_rdataset_t *rdataset)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff{
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff /*
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff * Add 'rdataset' to 'node' in version 'version' of 'db'.
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff */
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff REQUIRE(DNS_DB_VALID(db));
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff REQUIRE(node != NULL);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff REQUIRE(version != NULL);
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff REQUIRE(DNS_RDATASET_VALID(rdataset));
REQUIRE(rdataset->methods != NULL);
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));
}