pk11_result.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 #include <config.h>
00018 #include <stddef.h>
00019 
00020 #include <isc/once.h>
00021 #include <isc/msgcat.h>
00022 #include <isc/util.h>
00023 
00024 #include <pk11/result.h>
00025 
00026 LIBISC_EXTERNAL_DATA isc_msgcat_t *             pk11_msgcat = NULL;
00027 
00028 static isc_once_t               msgcat_once = ISC_ONCE_INIT;
00029 
00030 static const char *text[PK11_R_NRESULTS] = {
00031         "PKCS#11 initialization failed",                /*%< 0 */
00032         "no PKCS#11 provider",                          /*%< 1 */
00033         "PKCS#11 provider has no random service",       /*%< 2 */
00034         "PKCS#11 provider has no digest service",       /*%< 3 */
00035         "PKCS#11 provider has no AES service",          /*%< 4 */
00036 };
00037 
00038 #define PK11_RESULT_RESULTSET                   2
00039 
00040 static isc_once_t               once = ISC_ONCE_INIT;
00041 
00042 static void
00043 open_msgcat(void) {
00044         isc_msgcat_open("libpk11.cat", &pk11_msgcat);
00045 }
00046 
00047 void
00048 pk11_initmsgcat(void) {
00049 
00050         /*
00051          * Initialize the PKCS#11 support's message catalog,
00052          * pk11_msgcat, if it has not already been initialized.
00053          */
00054 
00055         RUNTIME_CHECK(isc_once_do(&msgcat_once, open_msgcat) == ISC_R_SUCCESS);
00056 }
00057 
00058 static void
00059 initialize_action(void) {
00060         isc_result_t result;
00061 
00062         result = isc_result_register(ISC_RESULTCLASS_PK11, PK11_R_NRESULTS,
00063                                      text, pk11_msgcat, PK11_RESULT_RESULTSET);
00064         if (result != ISC_R_SUCCESS)
00065                 UNEXPECTED_ERROR(__FILE__, __LINE__,
00066                                  "isc_result_register() failed: %u", result);
00067 }
00068 
00069 static void
00070 initialize(void) {
00071         pk11_initmsgcat();
00072         RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
00073 }
00074 
00075 const char *
00076 pk11_result_totext(isc_result_t result) {
00077         initialize();
00078 
00079         return (isc_result_totext(result));
00080 }
00081 
00082 void
00083 pk11_result_register(void) {
00084         initialize();
00085 }

Generated on Tue Apr 28 17:41:05 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha