dyndb.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2015, 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <config.h>
#if HAVE_DLFCN_H
#include <dlfcn.h>
#include <windows.h>
#endif
#include <string.h>
} while (0)
typedef struct dyndb_implementation dyndb_implementation_t;
struct dyndb_implementation {
void *handle;
char *name;
void *inst;
};
/*
* List of dyndb implementations. Locked by dyndb_lock.
*
* These are stored here so they can be cleaned up on shutdown.
* (The order in which they are stored is not important.)
*/
/* Locks dyndb_implementations. */
static isc_mutex_t dyndb_lock;
static void
dyndb_initialize(void) {
}
static dyndb_implementation_t *
return (imp);
return (NULL);
}
#if HAVE_DLFCN_H
static isc_result_t
const char *symbol_name, void **symbolp)
{
const char *errmsg;
void *symbol;
errmsg = "returned function pointer is NULL";
"failed to lookup symbol %s in "
"dyndb module '%s': %s",
return (ISC_R_FAILURE);
}
dlerror();
return (ISC_R_SUCCESS);
}
static isc_result_t
{
"loading DynDB instance '%s' driver '%s'",
#ifdef RTLD_DEEPBIND
flags |= RTLD_DEEPBIND;
#endif
/* Clear dlerror */
dlerror();
(void **)&version_func));
{
"driver API version mismatch: %d/%d",
}
(void **)®ister_func));
(void **)&destroy_func));
if (result != ISC_R_SUCCESS)
"failed to dynamically load instance '%s' "
return (result);
}
static void
}
static isc_result_t
const char *symbol_name, void **symbolp)
{
void *symbol;
int errstatus = GetLastError();
"failed to lookup symbol %s in "
"dyndb module '%s': %d",
return (ISC_R_FAILURE);
}
return (ISC_R_SUCCESS);
}
static isc_result_t
{
int version;
"loading DynDB instance '%s' driver '%s'",
(void **)&version_func));
{
"driver API version mismatch: %d/%d",
}
(void **)®ister_func));
(void **)&destroy_func));
if (result != ISC_R_SUCCESS)
"failed to dynamically load instance '%s' "
return (result);
}
static void
}
#else /* HAVE_DLFCN_H || _WIN32 */
static isc_result_t
{
"dynamic database support is not implemented");
return (ISC_R_NOTIMPLEMENTED);
}
static void
{
}
#endif /* HAVE_DLFCN_H */
{
LOCK(&dyndb_lock);
/* duplicate instance names are not allowed */
&implementation->inst));
if (result != ISC_R_SUCCESS)
if (implementation != NULL)
UNLOCK(&dyndb_lock);
return (result);
}
void
LOCK(&dyndb_lock);
}
UNLOCK(&dyndb_lock);
}
{
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
}
void
}