1633838b8255282d10af15c5c84cee5a51466712Bob Halley/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1998-2001, 2003-2005, 2007, 2008, 2012, 2014-2016 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley */
fda0ab6a96a7edb1acbde0c77ead0542979b0f24Bob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley#include <config.h>
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley
e7fb847ed570dd8c1bcdacabb3d69bd81feb79aeMark Andrews#include <stddef.h>
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley#include <stdlib.h>
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/lib.h>
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence#include <isc/msgs.h>
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley#include <isc/mutex.h>
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley#include <isc/once.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/resultclass.h>
440be4c866f6935ac069db79a414304507a664c2Michael Graff#include <isc/util.h>
fda0ab6a96a7edb1acbde0c77ead0542979b0f24Bob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halleytypedef struct resulttable {
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley unsigned int base;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley unsigned int last;
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence const char ** text;
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley isc_msgcat_t * msgcat;
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley int set;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley ISC_LINK(struct resulttable) link;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley} resulttable;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunttypedef ISC_LIST(resulttable) resulttable_list_t;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Huntstatic const char *description[ISC_R_NRESULTS] = {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "success", /*%< 0 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "out of memory", /*%< 1 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "timed out", /*%< 2 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "no available threads", /*%< 3 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "address not available", /*%< 4 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "address in use", /*%< 5 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "permission denied", /*%< 6 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "no pending connections", /*%< 7 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "network unreachable", /*%< 8 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "host unreachable", /*%< 9 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "network down", /*%< 10 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "host down", /*%< 11 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "connection refused", /*%< 12 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "not enough free resources", /*%< 13 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "end of file", /*%< 14 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "socket already bound", /*%< 15 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "reload", /*%< 16 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "lock busy", /*%< 17 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "already exists", /*%< 18 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "ran out of space", /*%< 19 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "operation canceled", /*%< 20 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "socket is not bound", /*%< 21 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "shutting down", /*%< 22 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "not found", /*%< 23 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "unexpected end of input", /*%< 24 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "failure", /*%< 25 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "I/O error", /*%< 26 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "not implemented", /*%< 27 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "unbalanced parentheses", /*%< 28 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "no more", /*%< 29 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "invalid file", /*%< 30 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "bad base64 encoding", /*%< 31 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "unexpected token", /*%< 32 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "quota reached", /*%< 33 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "unexpected error", /*%< 34 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "already running", /*%< 35 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "ignore", /*%< 36 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "address mask not contiguous", /*%< 37 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "file not found", /*%< 38 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "file already exists", /*%< 39 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "socket is not connected", /*%< 40 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "out of range", /*%< 41 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "out of entropy", /*%< 42 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "invalid use of multicast address", /*%< 43 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "not a file", /*%< 44 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "not a directory", /*%< 45 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "queue is full", /*%< 46 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "address family mismatch", /*%< 47 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "address family not supported", /*%< 48 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "bad hex encoding", /*%< 49 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "too many open files", /*%< 50 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "not blocking", /*%< 51 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "unbalanced quotes", /*%< 52 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "operation in progress", /*%< 53 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "connection reset", /*%< 54 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "soft quota reached", /*%< 55 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "not a valid number", /*%< 56 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "disabled", /*%< 57 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "max size", /*%< 58 */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "invalid address format", /*%< 59 */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "bad base32 encoding", /*%< 60 */
1bb3831e13a65afd87078c88e0285d23b1e0bcdfMark Andrews "unset", /*%< 61 */
c38341ec435fb78de6d12c1001201f9ac7487b68Mark Andrews "multiple", /*%< 62 */
a21c415687a855f84fbf10db91671b1341e8b990Mark Andrews "would block", /*%< 63 */
fda0ab6a96a7edb1acbde0c77ead0542979b0f24Bob Halley};
fda0ab6a96a7edb1acbde0c77ead0542979b0f24Bob Halley
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntstatic const char *identifier[ISC_R_NRESULTS] = {
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_SUCCESS",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NOMEMORY",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_TIMEDOUT",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NOTHREADS",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_ADDRNOTAVAIL",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_ADDRINUSE",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NOPERM",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NOCONN",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NETUNREACH",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_HOSTUNREACH",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NETDOWN",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_HOSTDOWN",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_CONNREFUSED",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NORESOURCES",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_EOF",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_BOUND",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_RELOAD",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_LOCKBUSY",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_EXISTS",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NOSPACE",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_CANCELED",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NOTBOUND",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_SHUTTINGDOWN",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NOTFOUND",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_UNEXPECTEDEND",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_FAILURE",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_IOERROR",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NOTIMPLEMENTED",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_UNBALANCED",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NOMORE",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_INVALIDFILE",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_BADBASE64",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_UNEXPECTEDTOKEN",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_QUOTA",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_UNEXPECTED",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_ALREADYRUNNING",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_IGNORE",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_MASKNONCONTIG",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_FILENOTFOUND",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_FILEEXISTS",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NOTCONNECTED",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_RANGE",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NOENTROPY",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_MULTICAST",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NOTFILE",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NOTDIRECTORY",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_QUEUEFULL",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_FAMILYMISMATCH",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_FAMILYNOSUPPORT",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_BADHEX",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_TOOMANYOPENFILES",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_NOTBLOCKING",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_UNBALANCEDQUOTES",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_INPROGRESS",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_CONNECTIONRESET",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_SOFTQUOTA",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_BADNUMBER",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_DISABLED",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_MAXSIZE",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_BADADDRESSFORM",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_BADBASE32",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_UNSET",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "ISC_R_MULTIPLE",
a21c415687a855f84fbf10db91671b1341e8b990Mark Andrews "ISC_R_WOULDBLOCK",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt};
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
5804af97ab0875fafd233f486aa1c1899ed5c00aBob Halley#define ISC_RESULT_RESULTSET 2
5804af97ab0875fafd233f486aa1c1899ed5c00aBob Halley#define ISC_RESULT_UNAVAILABLESET 3
5804af97ab0875fafd233f486aa1c1899ed5c00aBob Halley
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntstatic isc_once_t once = ISC_ONCE_INIT;
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntstatic resulttable_list_t description_tables;
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntstatic resulttable_list_t identifier_tables;
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntstatic isc_mutex_t lock;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halleystatic isc_result_t
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntregister_table(resulttable_list_t *tables, unsigned int base,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt unsigned int nresults, const char **text,
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley isc_msgcat_t *msgcat, int set)
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley{
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley resulttable *table;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley REQUIRE(base % ISC_RESULTCLASS_SIZE == 0);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley REQUIRE(nresults <= ISC_RESULTCLASS_SIZE);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley REQUIRE(text != NULL);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley /*
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley * We use malloc() here because we we want to be able to use
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley * isc_result_totext() even if there is no memory context.
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley */
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson table = malloc(sizeof(*table));
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley if (table == NULL)
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley return (ISC_R_NOMEMORY);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley table->base = base;
23fdb6a5a3d3d0e427682b68eea9553d2d326ad4Mark Andrews table->last = base + nresults - 1;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley table->text = text;
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley table->msgcat = msgcat;
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley table->set = set;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley ISC_LINK_INIT(table, link);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley LOCK(&lock);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt ISC_LIST_APPEND(*tables, table, link);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley UNLOCK(&lock);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley return (ISC_R_SUCCESS);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley}
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halleystatic void
e4e071ae12aee942fefc2c0a3280e402938669deBob Halleyinitialize_action(void) {
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley isc_result_t result;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley RUNTIME_CHECK(isc_mutex_init(&lock) == ISC_R_SUCCESS);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt ISC_LIST_INIT(description_tables);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt ISC_LIST_INIT(identifier_tables);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt result = register_table(&description_tables,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt ISC_RESULTCLASS_ISC, ISC_R_NRESULTS,
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt description, isc_msgcat, ISC_RESULT_RESULTSET);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley if (result != ISC_R_SUCCESS)
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley UNEXPECTED_ERROR(__FILE__, __LINE__,
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence "register_table() %s: %u",
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence ISC_MSG_FAILED, "failed"),
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence result);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt result = register_table(&identifier_tables,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt ISC_RESULTCLASS_ISC, ISC_R_NRESULTS,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt identifier, isc_msgcat, ISC_RESULT_RESULTSET);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (result != ISC_R_SUCCESS)
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt UNEXPECTED_ERROR(__FILE__, __LINE__,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "register_table() %s: %u",
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt ISC_MSG_FAILED, "failed"),
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt result);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley}
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halleystatic void
e4e071ae12aee942fefc2c0a3280e402938669deBob Halleyinitialize(void) {
96754ed7b400ce080279de2f92111ad868105290Bob Halley isc_lib_initmsgcat();
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley}
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntstatic const char *
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntisc_result_tomany_helper(resulttable_list_t *tables, isc_result_t result) {
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley resulttable *table;
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence const char *text, *default_text;
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley int index;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley initialize();
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley LOCK(&lock);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
5804af97ab0875fafd233f486aa1c1899ed5c00aBob Halley text = NULL;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt for (table = ISC_LIST_HEAD(*tables);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley table != NULL;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley table = ISC_LIST_NEXT(table, link)) {
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley if (result >= table->base && result <= table->last) {
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley index = (int)(result - table->base);
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley default_text = table->text[index];
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley /*
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley * Note: we use 'index + 1' as the message number
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley * instead of index because isc_msgcat_get() requires
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley * the message number to be > 0.
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley */
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley text = isc_msgcat_get(table->msgcat, table->set,
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley index + 1, default_text);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley break;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley }
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley }
5804af97ab0875fafd233f486aa1c1899ed5c00aBob Halley if (text == NULL)
5804af97ab0875fafd233f486aa1c1899ed5c00aBob Halley text = isc_msgcat_get(isc_msgcat, ISC_RESULT_UNAVAILABLESET,
5804af97ab0875fafd233f486aa1c1899ed5c00aBob Halley 1, "(result code text not available)");
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley UNLOCK(&lock);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley return (text);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley}
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntconst char *
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntisc_result_totext(isc_result_t result) {
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt return (isc_result_tomany_helper(&description_tables, result));
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt}
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntconst char *
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntisc_result_toid(isc_result_t result) {
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt return (isc_result_tomany_helper(&identifier_tables, result));
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt}
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
e4e071ae12aee942fefc2c0a3280e402938669deBob Halleyisc_result_t
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrenceisc_result_register(unsigned int base, unsigned int nresults,
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence const char **text, isc_msgcat_t *msgcat, int set)
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley{
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley initialize();
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt return (register_table(&description_tables, base, nresults, text,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt msgcat, set));
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt}
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntisc_result_t
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntisc_result_registerids(unsigned int base, unsigned int nresults,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt const char **ids, isc_msgcat_t *msgcat, int set)
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt{
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt initialize();
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt return (register_table(&identifier_tables, base, nresults, ids,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt msgcat, set));
fda0ab6a96a7edb1acbde0c77ead0542979b0f24Bob Halley}