2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +00:00

use a 'dns_sdbmethods_t' instead of passing all of the functions to

dns_sdb_register as parameters.
This commit is contained in:
Brian Wellington 2000-08-22 22:06:46 +00:00
parent ce2d576f3c
commit 75e1e12f48
2 changed files with 41 additions and 40 deletions

View File

@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: sdb.h,v 1.4 2000/08/22 01:46:12 gson Exp $ */
/* $Id: sdb.h,v 1.5 2000/08/22 22:06:46 bwelling Exp $ */
#ifndef DNS_SDB_H
#define DNS_SDB_H 1
@ -52,12 +52,6 @@ typedef struct dns_sdb dns_sdb_t;
typedef struct dns_sdblookup dns_sdblookup_t;
typedef struct dns_sdblookup dns_sdbnode_t;
/***
*** Functions
***/
ISC_LANG_BEGINDECLS
typedef isc_result_t
(*dns_sdblookupfunc_t)(const char *zone, const char *name, void *dbdata,
dns_sdblookup_t *);
@ -72,18 +66,31 @@ typedef isc_result_t
typedef void
(*dns_sdbdestroyfunc_t)(const char *zone, void *driverdata, void **dbdata);
typedef struct dns_sdbmethods {
dns_sdblookupfunc_t lookup;
dns_sdbauthorityfunc_t authority;
dns_sdbcreatefunc_t create;
dns_sdbdestroyfunc_t destroy;
} dns_sdbmethods_t;
/***
*** Functions
***/
ISC_LANG_BEGINDECLS
#define DNS_SDBFLAG_RELATIVEOWNER 0x00000001U
#define DNS_SDBFLAG_RELATIVERDATA 0x00000002U
isc_result_t
dns_sdb_register(const char *drivername, dns_sdblookupfunc_t lookup,
dns_sdbauthorityfunc_t authority, dns_sdbcreatefunc_t create,
dns_sdbdestroyfunc_t destroy, void *driverdata,
unsigned int flags);
dns_sdb_register(const char *drivername, const dns_sdbmethods_t *methods,
void *driverdata, unsigned int flags);
/*
* Register a simple database driver of name 'drivername'. The name
* server will perform lookups in the database by calling the function
* 'lookup', passing it a printable zone name 'zone', a printable
* Register a simple database driver of name 'drivername' with the
* specified functions.
*
* The name server will perform lookups in the database by calling the
* function 'lookup', passing it a printable zone name 'zone', a printable
* domain name 'name', and a copy of the argument 'dbdata' that
* was potentially returned by the create function. The 'dns_sdblookup_t'
* argument to 'lookup' and 'authority' is an opaque pointer to be passed to
@ -93,9 +100,10 @@ dns_sdb_register(const char *drivername, dns_sdblookupfunc_t lookup,
* by calling ns_sdb_putrr() once for each record found.
*
* Lookups at the zone apex will cause the server to also call the
* function 'authority', which must provide an SOA record and NS
* records for the zone by calling ns_sdb_putrr() once for each of
* these records.
* function 'authority' (if non-NULL), which must provide an SOA record
* and NS records for the zone by calling ns_sdb_putrr() once for each of
* these records. The 'authority' function may be NULL if invoking
* the 'lookup' function on the zone apex will return SOA and NS records.
*
* The create function will be called when a database is created, and
* allows the implementation to create database specific data.

View File

@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: sdb.c,v 1.4 2000/08/22 17:32:07 gson Exp $ */
/* $Id: sdb.c,v 1.5 2000/08/22 22:06:44 bwelling Exp $ */
#include <config.h>
@ -44,10 +44,7 @@
typedef struct sdbimp {
const char *drivername;
dns_sdblookupfunc_t lookup;
dns_sdbauthorityfunc_t authority;
dns_sdbcreatefunc_t create;
dns_sdbdestroyfunc_t destroy;
const dns_sdbmethods_t *methods;
void *driverdata;
unsigned int flags;
} sdbimp_t;
@ -142,18 +139,16 @@ initialize(void) {
* Functions used by implementors of simple databases
*/
isc_result_t
dns_sdb_register(const char *drivername, dns_sdblookupfunc_t lookup,
dns_sdbauthorityfunc_t authority, dns_sdbcreatefunc_t create,
dns_sdbdestroyfunc_t destroy, void *driverdata,
unsigned int flags)
dns_sdb_register(const char *drivername, const dns_sdbmethods_t *methods,
void *driverdata, unsigned int flags)
{
int i;
int slot = -1;
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
REQUIRE(drivername != NULL);
REQUIRE(lookup != NULL);
REQUIRE(authority != NULL);
REQUIRE(methods != NULL);
REQUIRE(methods->lookup != NULL);
LOCK(&implock);
for (i = 0; i < nimps; i++) {
@ -174,10 +169,7 @@ dns_sdb_register(const char *drivername, dns_sdblookupfunc_t lookup,
}
INSIST(slot >= 0 && slot < MAXSDBIMP);
imps[slot].drivername = drivername;
imps[slot].lookup = lookup;
imps[slot].authority = authority;
imps[slot].create = create;
imps[slot].destroy = destroy;
imps[slot].methods = methods;
imps[slot].driverdata = driverdata;
imps[slot].flags = flags;
UNLOCK(&implock);
@ -355,8 +347,9 @@ destroy(dns_sdb_t *sdb) {
mctx = sdb->common.mctx;
if (imp->destroy != NULL)
imp->destroy(sdb->zone, imp->driverdata, &sdb->dbdata);
if (imp->methods->destroy != NULL)
imp->methods->destroy(sdb->zone, imp->driverdata,
&sdb->dbdata);
isc_mem_free(mctx, sdb->zone);
isc_mutex_destroy(&sdb->lock);
@ -560,14 +553,14 @@ findnode(dns_db_t *db, dns_name_t *name, isc_boolean_t create,
isorigin = dns_name_equal(name, &sdb->common.origin);
result = imp->lookup(sdb->zone, namestr, sdb->dbdata, node);
result = imp->methods->lookup(sdb->zone, namestr, sdb->dbdata, node);
if (result != ISC_R_SUCCESS && !isorigin) {
destroynode(node);
return (result);
}
if (isorigin) {
result = imp->authority(sdb->zone, sdb->dbdata, node);
if (isorigin && imp->methods->authority != NULL) {
result = imp->methods->authority(sdb->zone, sdb->dbdata, node);
if (result != ISC_R_SUCCESS) {
destroynode(node);
return (result);
@ -1038,9 +1031,9 @@ dns_sdb_create(isc_mem_t *mctx, dns_name_t *origin, dns_dbtype_t type,
return (ISC_R_NOMEMORY);
}
sdb->dbdata = NULL;
if (imp->create != NULL) {
result = imp->create(sdb->zone, argc - 1, argv + 1,
imp->driverdata, &sdb->dbdata);
if (imp->methods->create != NULL) {
result = imp->methods->create(sdb->zone, argc - 1, argv + 1,
imp->driverdata, &sdb->dbdata);
if (result != ISC_R_SUCCESS) {
destroy(sdb);
return (result);