db.c revision 62837b832f6a9999976d607eb0a9125bbbbb138b
ca41b452ede6feaa9d8739ec3cae19389a7b0d03Bob Halley * Copyright (C) 1999 Internet Software Consortium.
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 * 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
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff *** Private Types
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Grafftypedef struct {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff dns_result_t (*create)(isc_mem_t *mctx, dns_name_t *name,
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff *** Supported DB Implementations Registry
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * Supported database implementations must be registered here.
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * It might be nice to generate this automatically some day.
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff *** Basic DB Methods
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencedns_db_create(isc_mem_t *mctx, char *db_type, dns_name_t *origin,
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff unsigned int argc, char *argv[], dns_db_t **dbp)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * Create a new database using implementation 'db_type'.
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff for (impinfo = implementations; impinfo->name != NULL; impinfo++)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff return ((impinfo->create)(mctx, origin, cache, class,
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffdns_db_attach(dns_db_t *source, dns_db_t **targetp) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * Attach *targetp to source.
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * Detach *dbp from its database.
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff * Does 'db' have cache semantics?
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff * Does 'db' have zone semantics?
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff * The origin of the database.
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff * Load master file 'filename' into 'db'.
4e675038a097065ff13944232cd7c89ac5961984Michael Graff REQUIRE((db->attributes & DNS_DBATTR_LOADED) == 0);
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff *** Version Methods
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graffdns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp) {
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff * Open the current version for reading.
e24f605ad64182532640dc6721070456b13112d5Michael Graff REQUIRE(versionp != NULL && *versionp == NULL);
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graffdns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp) {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff * Open a new version for reading and writing.
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence REQUIRE(versionp != NULL && *versionp == NULL);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff return ((db->methods->newversion)(db, versionp));
e24f605ad64182532640dc6721070456b13112d5Michael Graffdns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp,
e24f605ad64182532640dc6721070456b13112d5Michael Graff * Close version '*versionp'.
e24f605ad64182532640dc6721070456b13112d5Michael Graff REQUIRE(versionp != NULL && *versionp != NULL);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff (db->methods->closeversion)(db, versionp, commit);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff *** Node Methods
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffdns_db_findnode(dns_db_t *db, dns_name_t *name,
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff * Find the node with name 'name'.
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff * WARNING: THIS API WILL BE CHANGING IN THE NEAR FUTURE.
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff REQUIRE(dns_name_issubdomain(name, &db->origin));
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence return ((db->methods->findnode)(db, name, create, nodep));
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffdns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff * Attach *targetp to source.
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff (db->methods->attachnode)(db, source, targetp);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffdns_db_detachnode(dns_db_t *db, dns_dbnode_t **nodep) {
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff * Detach *nodep from its node.
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff *** Rdataset Methods
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 * 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 return ((db->methods->findrdataset)(db, node, version, type,
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffdns_db_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff * Add 'rdataset' to 'node' in version 'version' of 'db'.