2 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: lib.c,v 1.19 2009/09/03 00:12:23 each Exp $ */
28 #include <isc/msgcat.h>
29 #include <isc/mutex.h>
36 #include <dns/result.h>
45 LIBDNS_EXTERNAL_DATA unsigned int dns_pps = 0U;
46 LIBDNS_EXTERNAL_DATA isc_msgcat_t * dns_msgcat = NULL;
53 static isc_once_t msgcat_once = ISC_ONCE_INIT;
62 isc_msgcat_open("libdns.cat", &dns_msgcat);
66 dns_lib_initmsgcat(void) {
69 * Initialize the DNS library's message catalog, dns_msgcat, if it
70 * has not already been initialized.
73 RUNTIME_CHECK(isc_once_do(&msgcat_once, open_msgcat) == ISC_R_SUCCESS);
76 static isc_once_t init_once = ISC_ONCE_INIT;
77 static isc_mem_t *dns_g_mctx = NULL;
79 static dns_dbimplementation_t *dbimp = NULL;
81 static isc_boolean_t initialize_done = ISC_FALSE;
82 static isc_mutex_t reflock;
83 static unsigned int references = 0;
89 REQUIRE(initialize_done == ISC_FALSE);
91 result = isc_mem_create(0, 0, &dns_g_mctx);
92 if (result != ISC_R_SUCCESS)
94 dns_result_register();
96 result = dns_ecdb_register(dns_g_mctx, &dbimp);
97 if (result != ISC_R_SUCCESS)
100 result = isc_hash_create(dns_g_mctx, NULL, DNS_NAME_MAXWIRE);
101 if (result != ISC_R_SUCCESS)
104 result = dst_lib_init(dns_g_mctx, NULL, 0);
105 if (result != ISC_R_SUCCESS)
108 result = isc_mutex_init(&reflock);
109 if (result != ISC_R_SUCCESS)
112 initialize_done = ISC_TRUE;
121 dns_ecdb_unregister(&dbimp);
124 isc_mem_detach(&dns_g_mctx);
132 * Since this routine is expected to be used by a normal application,
133 * it should be better to return an error, instead of an emergency
134 * abort, on any failure.
136 result = isc_once_do(&init_once, initialize);
137 if (result != ISC_R_SUCCESS)
140 if (!initialize_done)
141 return (ISC_R_FAILURE);
147 return (ISC_R_SUCCESS);
151 dns_lib_shutdown(void) {
152 isc_boolean_t cleanup_ok = ISC_FALSE;
155 if (--references == 0)
156 cleanup_ok = ISC_TRUE;
165 dns_ecdb_unregister(&dbimp);
167 isc_mem_detach(&dns_g_mctx);