2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 15:05:23 +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. * 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 #ifndef DNS_SDB_H
#define DNS_SDB_H 1 #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_sdblookup_t;
typedef struct dns_sdblookup dns_sdbnode_t; typedef struct dns_sdblookup dns_sdbnode_t;
/***
*** Functions
***/
ISC_LANG_BEGINDECLS
typedef isc_result_t typedef isc_result_t
(*dns_sdblookupfunc_t)(const char *zone, const char *name, void *dbdata, (*dns_sdblookupfunc_t)(const char *zone, const char *name, void *dbdata,
dns_sdblookup_t *); dns_sdblookup_t *);
@@ -72,18 +66,31 @@ typedef isc_result_t
typedef void typedef void
(*dns_sdbdestroyfunc_t)(const char *zone, void *driverdata, void **dbdata); (*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_RELATIVEOWNER 0x00000001U
#define DNS_SDBFLAG_RELATIVERDATA 0x00000002U #define DNS_SDBFLAG_RELATIVERDATA 0x00000002U
isc_result_t isc_result_t
dns_sdb_register(const char *drivername, dns_sdblookupfunc_t lookup, dns_sdb_register(const char *drivername, const dns_sdbmethods_t *methods,
dns_sdbauthorityfunc_t authority, dns_sdbcreatefunc_t create, void *driverdata, unsigned int flags);
dns_sdbdestroyfunc_t destroy, void *driverdata,
unsigned int flags);
/* /*
* Register a simple database driver of name 'drivername'. The name * Register a simple database driver of name 'drivername' with the
* server will perform lookups in the database by calling the function * specified functions.
* 'lookup', passing it a printable zone name 'zone', a printable *
* 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 * domain name 'name', and a copy of the argument 'dbdata' that
* was potentially returned by the create function. The 'dns_sdblookup_t' * was potentially returned by the create function. The 'dns_sdblookup_t'
* argument to 'lookup' and 'authority' is an opaque pointer to be passed to * 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. * by calling ns_sdb_putrr() once for each record found.
* *
* Lookups at the zone apex will cause the server to also call the * Lookups at the zone apex will cause the server to also call the
* function 'authority', which must provide an SOA record and NS * function 'authority' (if non-NULL), which must provide an SOA record
* records for the zone by calling ns_sdb_putrr() once for each of * and NS records for the zone by calling ns_sdb_putrr() once for each of
* these records. * 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 * The create function will be called when a database is created, and
* allows the implementation to create database specific data. * allows the implementation to create database specific data.

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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> #include <config.h>
@@ -44,10 +44,7 @@
typedef struct sdbimp { typedef struct sdbimp {
const char *drivername; const char *drivername;
dns_sdblookupfunc_t lookup; const dns_sdbmethods_t *methods;
dns_sdbauthorityfunc_t authority;
dns_sdbcreatefunc_t create;
dns_sdbdestroyfunc_t destroy;
void *driverdata; void *driverdata;
unsigned int flags; unsigned int flags;
} sdbimp_t; } sdbimp_t;
@@ -142,18 +139,16 @@ initialize(void) {
* Functions used by implementors of simple databases * Functions used by implementors of simple databases
*/ */
isc_result_t isc_result_t
dns_sdb_register(const char *drivername, dns_sdblookupfunc_t lookup, dns_sdb_register(const char *drivername, const dns_sdbmethods_t *methods,
dns_sdbauthorityfunc_t authority, dns_sdbcreatefunc_t create, void *driverdata, unsigned int flags)
dns_sdbdestroyfunc_t destroy, void *driverdata,
unsigned int flags)
{ {
int i; int i;
int slot = -1; int slot = -1;
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
REQUIRE(drivername != NULL); REQUIRE(drivername != NULL);
REQUIRE(lookup != NULL); REQUIRE(methods != NULL);
REQUIRE(authority != NULL); REQUIRE(methods->lookup != NULL);
LOCK(&implock); LOCK(&implock);
for (i = 0; i < nimps; i++) { 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); INSIST(slot >= 0 && slot < MAXSDBIMP);
imps[slot].drivername = drivername; imps[slot].drivername = drivername;
imps[slot].lookup = lookup; imps[slot].methods = methods;
imps[slot].authority = authority;
imps[slot].create = create;
imps[slot].destroy = destroy;
imps[slot].driverdata = driverdata; imps[slot].driverdata = driverdata;
imps[slot].flags = flags; imps[slot].flags = flags;
UNLOCK(&implock); UNLOCK(&implock);
@@ -355,8 +347,9 @@ destroy(dns_sdb_t *sdb) {
mctx = sdb->common.mctx; mctx = sdb->common.mctx;
if (imp->destroy != NULL) if (imp->methods->destroy != NULL)
imp->destroy(sdb->zone, imp->driverdata, &sdb->dbdata); imp->methods->destroy(sdb->zone, imp->driverdata,
&sdb->dbdata);
isc_mem_free(mctx, sdb->zone); isc_mem_free(mctx, sdb->zone);
isc_mutex_destroy(&sdb->lock); 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); 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) { if (result != ISC_R_SUCCESS && !isorigin) {
destroynode(node); destroynode(node);
return (result); return (result);
} }
if (isorigin) { if (isorigin && imp->methods->authority != NULL) {
result = imp->authority(sdb->zone, sdb->dbdata, node); result = imp->methods->authority(sdb->zone, sdb->dbdata, node);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
destroynode(node); destroynode(node);
return (result); return (result);
@@ -1038,8 +1031,8 @@ dns_sdb_create(isc_mem_t *mctx, dns_name_t *origin, dns_dbtype_t type,
return (ISC_R_NOMEMORY); return (ISC_R_NOMEMORY);
} }
sdb->dbdata = NULL; sdb->dbdata = NULL;
if (imp->create != NULL) { if (imp->methods->create != NULL) {
result = imp->create(sdb->zone, argc - 1, argv + 1, result = imp->methods->create(sdb->zone, argc - 1, argv + 1,
imp->driverdata, &sdb->dbdata); imp->driverdata, &sdb->dbdata);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
destroy(sdb); destroy(sdb);