dyndb.c revision 93c211afc97e7a072c12ef346581065e4065ff15
/*
* Copyright (C) 2015, 2016 Internet Systems Consortium, Inc. ("ISC")
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#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
}