4 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: lib.c,v 1.19 2009/09/03 00:12:23 each Exp */
30 #include <isc/msgcat.h>
31 #include <isc/mutex.h>
38 #include <dns/result.h>
47 LIBDNS_EXTERNAL_DATA
unsigned int dns_pps
= 0U;
48 LIBDNS_EXTERNAL_DATA isc_msgcat_t
* dns_msgcat
= NULL
;
55 static isc_once_t msgcat_once
= ISC_ONCE_INIT
;
64 isc_msgcat_open("libdns.cat", &dns_msgcat
);
68 dns_lib_initmsgcat(void) {
71 * Initialize the DNS library's message catalog, dns_msgcat, if it
72 * has not already been initialized.
75 RUNTIME_CHECK(isc_once_do(&msgcat_once
, open_msgcat
) == ISC_R_SUCCESS
);
78 static isc_once_t init_once
= ISC_ONCE_INIT
;
79 static isc_mem_t
*dns_g_mctx
= NULL
;
81 static dns_dbimplementation_t
*dbimp
= NULL
;
83 static isc_boolean_t initialize_done
= ISC_FALSE
;
84 static isc_mutex_t reflock
;
85 static unsigned int references
= 0;
91 REQUIRE(initialize_done
== ISC_FALSE
);
93 result
= isc_mem_create(0, 0, &dns_g_mctx
);
94 if (result
!= ISC_R_SUCCESS
)
96 dns_result_register();
98 result
= dns_ecdb_register(dns_g_mctx
, &dbimp
);
99 if (result
!= ISC_R_SUCCESS
)
102 result
= isc_hash_create(dns_g_mctx
, NULL
, DNS_NAME_MAXWIRE
);
103 if (result
!= ISC_R_SUCCESS
)
106 result
= dst_lib_init(dns_g_mctx
, NULL
, 0);
107 if (result
!= ISC_R_SUCCESS
)
110 result
= isc_mutex_init(&reflock
);
111 if (result
!= ISC_R_SUCCESS
)
114 initialize_done
= ISC_TRUE
;
123 dns_ecdb_unregister(&dbimp
);
126 isc_mem_detach(&dns_g_mctx
);
134 * Since this routine is expected to be used by a normal application,
135 * it should be better to return an error, instead of an emergency
136 * abort, on any failure.
138 result
= isc_once_do(&init_once
, initialize
);
139 if (result
!= ISC_R_SUCCESS
)
142 if (!initialize_done
)
143 return (ISC_R_FAILURE
);
149 return (ISC_R_SUCCESS
);
153 dns_lib_shutdown(void) {
154 isc_boolean_t cleanup_ok
= ISC_FALSE
;
157 if (--references
== 0)
158 cleanup_ok
= ISC_TRUE
;
167 dns_ecdb_unregister(&dbimp
);
169 isc_mem_detach(&dns_g_mctx
);