1999-06-23 18:28:27 -04:00
|
|
|
/*
|
2018-02-23 03:53:12 -05:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-07-31 21:33:37 -04:00
|
|
|
*
|
2016-06-27 00:56:38 -04:00
|
|
|
* 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/.
|
2018-02-23 03:53:12 -05:00
|
|
|
*
|
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
|
* information regarding copyright ownership.
|
1999-06-23 18:28:27 -04:00
|
|
|
*/
|
|
|
|
|
|
2005-04-27 00:57:32 -04:00
|
|
|
/*! \file */
|
2000-06-22 18:00:42 -04:00
|
|
|
|
2018-04-17 11:29:14 -04:00
|
|
|
#include <stdbool.h>
|
2000-08-29 21:24:20 -04:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
2009-08-31 20:22:28 -04:00
|
|
|
#include <isc/hash.h>
|
|
|
|
|
#include <isc/mem.h>
|
|
|
|
|
#include <isc/mutex.h>
|
|
|
|
|
#include <isc/once.h>
|
2019-05-20 10:41:36 -04:00
|
|
|
#include <isc/refcount.h>
|
2000-04-27 21:12:23 -04:00
|
|
|
#include <isc/util.h>
|
1999-06-23 18:28:27 -04:00
|
|
|
|
2009-08-31 20:22:28 -04:00
|
|
|
#include <dns/db.h>
|
|
|
|
|
#include <dns/ecdb.h>
|
1999-06-23 18:28:27 -04:00
|
|
|
#include <dns/lib.h>
|
2009-08-31 20:22:28 -04:00
|
|
|
#include <dns/result.h>
|
|
|
|
|
|
|
|
|
|
#include <dst/dst.h>
|
|
|
|
|
|
1999-06-23 18:28:27 -04:00
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Globals
|
|
|
|
|
***/
|
|
|
|
|
|
2005-08-14 21:21:07 -04:00
|
|
|
LIBDNS_EXTERNAL_DATA unsigned int dns_pps = 0U;
|
1999-06-23 18:28:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Functions
|
|
|
|
|
***/
|
|
|
|
|
|
2009-08-31 20:22:28 -04:00
|
|
|
static isc_once_t init_once = ISC_ONCE_INIT;
|
|
|
|
|
static isc_mem_t *dns_g_mctx = NULL;
|
|
|
|
|
static dns_dbimplementation_t *dbimp = NULL;
|
2018-04-17 11:29:14 -04:00
|
|
|
static bool initialize_done = false;
|
2019-07-08 11:30:06 -04:00
|
|
|
static isc_refcount_t references;
|
2009-08-31 20:22:28 -04:00
|
|
|
|
|
|
|
|
static void
|
2009-09-02 20:12:23 -04:00
|
|
|
initialize(void) {
|
2009-08-31 20:22:28 -04:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
2018-04-17 11:29:14 -04:00
|
|
|
REQUIRE(initialize_done == false);
|
2009-08-31 20:22:28 -04:00
|
|
|
|
2019-07-08 11:30:06 -04:00
|
|
|
isc_refcount_init(&references, 0);
|
|
|
|
|
|
2019-09-05 12:40:57 -04:00
|
|
|
isc_mem_create(&dns_g_mctx);
|
2009-08-31 20:22:28 -04:00
|
|
|
dns_result_register();
|
|
|
|
|
result = dns_ecdb_register(dns_g_mctx, &dbimp);
|
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
|
goto cleanup_mctx;
|
|
|
|
|
|
2018-04-22 08:56:28 -04:00
|
|
|
result = dst_lib_init(dns_g_mctx, NULL);
|
2009-08-31 20:22:28 -04:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2018-04-22 08:56:28 -04:00
|
|
|
goto cleanup_db;
|
2009-08-31 20:22:28 -04:00
|
|
|
|
2018-04-17 11:29:14 -04:00
|
|
|
initialize_done = true;
|
2009-08-31 20:22:28 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
cleanup_db:
|
2013-04-10 16:49:57 -04:00
|
|
|
if (dbimp != NULL)
|
|
|
|
|
dns_ecdb_unregister(&dbimp);
|
2009-08-31 20:22:28 -04:00
|
|
|
cleanup_mctx:
|
2013-04-10 16:49:57 -04:00
|
|
|
if (dns_g_mctx != NULL)
|
|
|
|
|
isc_mem_detach(&dns_g_mctx);
|
2009-08-31 20:22:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
|
dns_lib_init(void) {
|
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Since this routine is expected to be used by a normal application,
|
|
|
|
|
* it should be better to return an error, instead of an emergency
|
|
|
|
|
* abort, on any failure.
|
|
|
|
|
*/
|
|
|
|
|
result = isc_once_do(&init_once, initialize);
|
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
|
|
if (!initialize_done)
|
|
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
|
|
2019-05-20 10:41:36 -04:00
|
|
|
isc_refcount_increment(&references);
|
2009-08-31 20:22:28 -04:00
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
dns_lib_shutdown(void) {
|
2019-05-20 10:41:36 -04:00
|
|
|
if (isc_refcount_decrement(&references) == 1) {
|
|
|
|
|
dst_lib_destroy();
|
|
|
|
|
|
|
|
|
|
isc_refcount_destroy(&references);
|
|
|
|
|
|
|
|
|
|
if (dbimp != NULL) {
|
|
|
|
|
dns_ecdb_unregister(&dbimp);
|
|
|
|
|
}
|
|
|
|
|
if (dns_g_mctx != NULL) {
|
|
|
|
|
isc_mem_detach(&dns_g_mctx);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-31 20:22:28 -04:00
|
|
|
}
|