Removal of library result registering code

The new result API won't require each library to register their result
codes, as result we can remove this code now.
This commit is contained in:
Diego Fronza
2021-03-31 14:45:47 +00:00
committed by Diego dos Santos Fronza
parent 22459f25a3
commit 75c39475cf
8 changed files with 3 additions and 306 deletions
+1 -41
View File
@@ -9,8 +9,7 @@
* information regarding copyright ownership.
*/
#include <isc/once.h>
#include <isc/util.h>
#include <isc/result.h>
static const char *text[DST_R_NRESULTS] = {
"algorithm is unsupported", /*%< 0 */
@@ -64,43 +63,4 @@ static const char *ids[DST_R_NRESULTS] = {
"DST_R_EXTERNALKEY",
};
#define DST_RESULT_RESULTSET 2
static isc_once_t once = ISC_ONCE_INIT;
static void
initialize_action(void) {
isc_result_t result;
result = isc_result_register(ISC_RESULTCLASS_DST, DST_R_NRESULTS, text,
DST_RESULT_RESULTSET);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_result_register() failed: %u", result);
}
result = isc_result_registerids(ISC_RESULTCLASS_DST, DST_R_NRESULTS,
ids, DST_RESULT_RESULTSET);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_result_registerids() failed: %u", result);
}
}
static void
initialize(void) {
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
}
const char *
dst_result_totext(isc_result_t result) {
initialize();
return (isc_result_totext(result));
}
void
dst_result_register(void) {
initialize();
}
/*! \file */
-1
View File
@@ -14,7 +14,6 @@
/*! \file dst/result.h */
#include <isc/lang.h>
#include <isc/resultclass.h>
/*
+1 -56
View File
@@ -11,11 +11,7 @@
/*! \file */
#include <isc/once.h>
#include <isc/util.h>
#include <dns/lib.h>
#include <dns/result.h>
#include <isc/result.h>
static const char *text[DNS_R_NRESULTS] = {
"label too long", /*%< 0 DNS_R_LABELTOOLONG */
@@ -341,57 +337,6 @@ static const char *rcode_ids[DNS_R_NRCODERESULTS] = {
"DNS_R_BADVERS",
};
#define DNS_RESULT_RESULTSET 2
#define DNS_RESULT_RCODERESULTSET 3
static isc_once_t once = ISC_ONCE_INIT;
static void
initialize_action(void) {
isc_result_t result;
result = isc_result_register(ISC_RESULTCLASS_DNS, DNS_R_NRESULTS, text,
DNS_RESULT_RESULTSET);
if (result == ISC_R_SUCCESS) {
result = isc_result_register(ISC_RESULTCLASS_DNSRCODE,
DNS_R_NRCODERESULTS, rcode_text,
DNS_RESULT_RCODERESULTSET);
}
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_result_register() failed: %u", result);
}
result = isc_result_registerids(ISC_RESULTCLASS_DNS, DNS_R_NRESULTS,
ids, DNS_RESULT_RESULTSET);
if (result == ISC_R_SUCCESS) {
result = isc_result_registerids(ISC_RESULTCLASS_DNSRCODE,
DNS_R_NRCODERESULTS, rcode_ids,
DNS_RESULT_RCODERESULTSET);
}
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_result_registerids() failed: %u", result);
}
}
static void
initialize(void) {
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
}
const char *
dns_result_totext(isc_result_t result) {
initialize();
return (isc_result_totext(result));
}
void
dns_result_register(void) {
initialize();
}
dns_rcode_t
dns_result_torcode(isc_result_t result) {
dns_rcode_t rcode = dns_rcode_servfail;
-8
View File
@@ -107,14 +107,6 @@ const char *isc_result_toid(isc_result_t);
* "ISC_R_SUCCESS".
*/
isc_result_t
isc_result_register(unsigned int base, unsigned int nresults, const char **text,
int set);
isc_result_t
isc_result_registerids(unsigned int base, unsigned int nresults,
const char **ids, int set);
ISC_LANG_ENDDECLS
#endif /* ISC_RESULT_H */
-40
View File
@@ -27,43 +27,3 @@ static const char *ids[PK11_R_NRESULTS] = {
"PK11_R_NORANDOMSERVICE", "PK11_R_NODIGESTSERVICE",
"PK11_R_NOAESSERVICE",
};
#define PK11_RESULT_RESULTSET 2
static isc_once_t once = ISC_ONCE_INIT;
static void
initialize_action(void) {
isc_result_t result;
result = isc_result_register(ISC_RESULTCLASS_PK11, PK11_R_NRESULTS,
text, PK11_RESULT_RESULTSET);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_result_register() failed: %u", result);
}
result = isc_result_registerids(ISC_RESULTCLASS_PK11, PK11_R_NRESULTS,
ids, PK11_RESULT_RESULTSET);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_result_registerids() failed: %u", result);
}
}
static void
initialize(void) {
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
}
const char *
pk11_result_totext(isc_result_t result) {
initialize();
return (isc_result_totext(result));
}
void
pk11_result_register(void) {
initialize();
}
-101
View File
@@ -15,21 +15,9 @@
#include <stdlib.h>
#include <isc/lib.h>
#include <isc/once.h>
#include <isc/resultclass.h>
#include <isc/rwlock.h>
#include <isc/util.h>
typedef struct resulttable {
unsigned int base;
unsigned int last;
const char **text;
int set;
ISC_LINK(struct resulttable) link;
} resulttable;
typedef ISC_LIST(resulttable) resulttable_list_t;
static const char *description[ISC_R_NRESULTS] = {
"success", /*%< 0 */
"out of memory", /*%< 1 */
@@ -178,75 +166,8 @@ static const char *identifier[ISC_R_NRESULTS] = { "ISC_R_SUCCESS",
"ISC_R_TLSERROR",
"ISC_R_HTTP2ALPNERROR" };
#define ISC_RESULT_RESULTSET 2
#define ISC_RESULT_UNAVAILABLESET 3
static isc_once_t once = ISC_ONCE_INIT;
static resulttable_list_t description_tables;
static resulttable_list_t identifier_tables;
static isc_rwlock_t lock;
static isc_result_t
register_table(resulttable_list_t *tables, unsigned int base,
unsigned int nresults, const char **text, int set) {
resulttable *table;
REQUIRE(base % ISC_RESULTCLASS_SIZE == 0);
REQUIRE(nresults <= ISC_RESULTCLASS_SIZE);
REQUIRE(text != NULL);
/*
* We use malloc() here because we we want to be able to use
* isc_result_totext() even if there is no memory context.
*/
table = malloc(sizeof(*table));
if (table == NULL) {
return (ISC_R_NOMEMORY);
}
table->base = base;
table->last = base + nresults - 1;
table->text = text;
table->set = set;
ISC_LINK_INIT(table, link);
RWLOCK(&lock, isc_rwlocktype_write);
ISC_LIST_APPEND(*tables, table, link);
RWUNLOCK(&lock, isc_rwlocktype_write);
return (ISC_R_SUCCESS);
}
static void
initialize_action(void) {
isc_result_t result;
isc_rwlock_init(&lock, 0, 0);
ISC_LIST_INIT(description_tables);
ISC_LIST_INIT(identifier_tables);
result = register_table(&description_tables, ISC_RESULTCLASS_ISC,
ISC_R_NRESULTS, description,
ISC_RESULT_RESULTSET);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"register_table() failed: %u", result);
}
result = register_table(&identifier_tables, ISC_RESULTCLASS_ISC,
ISC_R_NRESULTS, identifier,
ISC_RESULT_RESULTSET);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"register_table() failed: %u", result);
}
}
static void
initialize(void) {
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
}
static const char *
isc_result_tomany_helper(resulttable_list_t *tables, isc_result_t result) {
@@ -254,10 +175,6 @@ isc_result_tomany_helper(resulttable_list_t *tables, isc_result_t result) {
const char *text;
int index;
initialize();
RWLOCK(&lock, isc_rwlocktype_read);
text = NULL;
for (table = ISC_LIST_HEAD(*tables); table != NULL;
table = ISC_LIST_NEXT(table, link))
@@ -272,8 +189,6 @@ isc_result_tomany_helper(resulttable_list_t *tables, isc_result_t result) {
text = "(result code text not available)";
}
RWUNLOCK(&lock, isc_rwlocktype_read);
return (text);
}
@@ -286,19 +201,3 @@ const char *
isc_result_toid(isc_result_t result) {
return (isc_result_tomany_helper(&identifier_tables, result));
}
isc_result_t
isc_result_register(unsigned int base, unsigned int nresults, const char **text,
int set) {
initialize();
return (register_table(&description_tables, base, nresults, text, set));
}
isc_result_t
isc_result_registerids(unsigned int base, unsigned int nresults,
const char **ids, int set) {
initialize();
return (register_table(&identifier_tables, base, nresults, ids, set));
}
-17
View File
@@ -28,12 +28,8 @@
/*! \file isccc/result.h */
#include <isc/lang.h>
#include <isc/result.h>
#include <isc/resultclass.h>
#include <isccc/types.h>
/*% Unknown Version */
#define ISCCC_R_UNKNOWNVERSION (ISC_RESULTCLASS_ISCCC + 0)
/*% Syntax Error */
@@ -49,17 +45,4 @@
#define ISCCC_R_NRESULTS 6 /*%< Number of results */
ISC_LANG_BEGINDECLS
const char *
isccc_result_totext(isc_result_t result);
/*%
* Convert a isccc_result_t into a string message describing the result.
*/
void
isccc_result_register(void);
ISC_LANG_ENDDECLS
#endif /* ISCCC_RESULT_H */
+1 -42
View File
@@ -25,8 +25,7 @@
/*! \file */
#include <isc/once.h>
#include <isc/util.h>
#include <isc/result.h>
static const char *text[ISCCC_R_NRESULTS] = {
"unknown version", /* 1 */
@@ -41,43 +40,3 @@ static const char *ids[ISCCC_R_NRESULTS] = {
"ISCCC_R_UNKNOWNVERSION", "ISCCC_R_SYNTAX", "ISCCC_R_BADAUTH",
"ISCCC_R_EXPIRED", "ISCCC_R_CLOCKSKEW", "ISCCC_R_DUPLICATE",
};
#define ISCCC_RESULT_RESULTSET 2
static isc_once_t once = ISC_ONCE_INIT;
static void
initialize_action(void) {
isc_result_t result;
result = isc_result_register(ISC_RESULTCLASS_ISCCC, ISCCC_R_NRESULTS,
text, ISCCC_RESULT_RESULTSET);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_result_register() failed: %u", result);
}
result = isc_result_registerids(ISC_RESULTCLASS_ISCCC, ISCCC_R_NRESULTS,
ids, ISCCC_RESULT_RESULTSET);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_result_registerids() failed: %u", result);
}
}
static void
initialize(void) {
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
}
const char *
isccc_result_totext(isc_result_t result) {
initialize();
return (isc_result_totext(result));
}
void
isccc_result_register(void) {
initialize();
}