updated makefile
[gnutls.git] / libdane / errors.c
blob0753265883383bb9835988445f569db98b9f87c4
1 /*
2 * Copyright (C) 2012 KU Leuven
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of libdane.
8 * libdane is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
23 #include <config.h>
24 #include <gnutls/dane.h>
26 /* I18n of error codes. */
27 #include "gettext.h"
28 #define _(String) dgettext (PACKAGE, String)
29 #define N_(String) gettext_noop (String)
31 #define ERROR_ENTRY(desc, name) \
32 { desc, #name, name}
34 struct error_entry
36 const char *desc;
37 const char *_name;
38 int number;
40 typedef struct error_entry error_entry;
42 static const error_entry error_algorithms[] = {
43 ERROR_ENTRY (N_("Success."), DANE_E_SUCCESS),
44 ERROR_ENTRY (N_("There was error initializing the DNS query."),
45 DANE_E_INITIALIZATION_ERROR),
46 ERROR_ENTRY (N_("There was an error while resolving."),
47 DANE_E_RESOLVING_ERROR),
48 ERROR_ENTRY (N_("No DANE data were found."),
49 DANE_E_NO_DANE_DATA),
50 ERROR_ENTRY (N_("No DNSSEC signature was found."),
51 DANE_E_NO_DNSSEC_SIG),
52 ERROR_ENTRY (N_("Received corrupt data."),
53 DANE_E_RECEIVED_CORRUPT_DATA),
54 ERROR_ENTRY (N_("The DNSSEC signature is invalid."),
55 DANE_E_INVALID_DNSSEC_SIG),
56 ERROR_ENTRY (N_("There was a memory error."),
57 DANE_E_MEMORY_ERROR),
58 ERROR_ENTRY (N_("There requested data are not available."),
59 DANE_E_REQUESTED_DATA_NOT_AVAILABLE),
60 ERROR_ENTRY (N_("There request is invalid."),
61 DANE_E_INVALID_REQUEST),
62 ERROR_ENTRY (N_("There was an error in the public key."),
63 DANE_E_PUBKEY_ERROR),
64 ERROR_ENTRY (N_("No certificate was found."),
65 DANE_E_NO_CERT),
66 {NULL, NULL, 0}
69 /**
70 * dane_strerror:
71 * @error: is a DANE error code, a negative error code
73 * This function is similar to strerror. The difference is that it
74 * accepts an error number returned by a gnutls function; In case of
75 * an unknown error a descriptive string is sent instead of %NULL.
77 * Error codes are always a negative error code.
79 * Returns: A string explaining the DANE error message.
80 **/
81 const char *
82 dane_strerror (int error)
84 const char *ret = NULL;
85 const error_entry *p;
87 for (p = error_algorithms; p->desc != NULL; p++)
89 if (p->number == error)
91 ret = p->desc;
92 break;
96 /* avoid prefix */
97 if (ret == NULL)
98 return _("(unknown error code)");
100 return _(ret);