GNUnet 0.22.2
gnunet_error_codes.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012-2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20#include "gnunet_error_codes.h"
21#include <stddef.h>
22#include <microhttpd.h>
23#include <gettext.h>
24
28#define MHD_HTTP_UNINITIALIZED 0
29
34{
39
43 const char *hint;
44
48 unsigned int http_code;
49};
50
51
55static const struct ErrorCodeAndHint code_hint_pairs[] = {
56
57 {
59 .hint = gettext_noop ("No error (success)."),
60 .http_code = MHD_HTTP_UNINITIALIZED
61 },
62
63 {
65 .hint = gettext_noop ("Unknown and unspecified error."),
67 },
68
69 {
71 .hint = gettext_noop ("Communication with service failed."),
73 },
74
75 {
77 .hint = gettext_noop ("Ego not found."),
78 .http_code = MHD_HTTP_NOT_FOUND
79 },
80
81 {
83 .hint = gettext_noop ("Identifier already in use for another ego."),
84 .http_code = MHD_HTTP_CONFLICT
85 },
86
87 {
89 .hint = gettext_noop ("The given ego is invalid or malformed."),
91 },
92
93 {
95 .hint = gettext_noop ("Unknown namestore error."),
97 },
98
99 {
101 .hint = gettext_noop ("Zone iteration failed."),
103 },
104
105 {
107 .hint = gettext_noop ("Zone not found."),
108 .http_code = MHD_HTTP_NOT_FOUND
109 },
110
111 {
113 .hint = gettext_noop ("Record not found."),
114 .http_code = MHD_HTTP_NOT_FOUND
115 },
116
117 {
119 .hint = gettext_noop ("Zone iteration failed."),
121 },
122
123 {
125 .hint = gettext_noop ("Zone does not contain any records."),
126 .http_code = MHD_HTTP_NOT_FOUND
127 },
128
129 {
131 .hint = gettext_noop ("Failed to lookup record."),
133 },
134
135 {
137 .hint = gettext_noop ("No records given."),
138 .http_code = MHD_HTTP_BAD_REQUEST
139 },
140
141 {
143 .hint = gettext_noop ("Record data invalid."),
144 .http_code = MHD_HTTP_BAD_REQUEST
145 },
146
147 {
149 .hint = gettext_noop ("No label given."),
150 .http_code = MHD_HTTP_BAD_REQUEST
151 },
152
153 {
155 .hint = gettext_noop ("No results given."),
156 .http_code = MHD_HTTP_NOT_FOUND
157 },
158
159 {
161 .hint = gettext_noop ("Record already exists."),
162 .http_code = MHD_HTTP_CONFLICT
163 },
164
165 {
167 .hint = gettext_noop ("Record size exceeds maximum limit."),
169 },
170
171 {
173 .hint = gettext_noop ("There was an error in the database backend."),
175 },
176
177 {
179 .hint = gettext_noop ("Failed to store the given records."),
181 },
182
183 {
185 .hint = gettext_noop ("Label invalid or malformed."),
186 .http_code = MHD_HTTP_BAD_REQUEST
187 },
188
189
190};
191
192
196static const unsigned int code_hint_pairs_length = 22;
197
198
199
200const char *
202{
203 unsigned int lower = 0;
204 unsigned int upper = code_hint_pairs_length - 1;
205 unsigned int mid = upper / 2;
206 while (lower <= upper)
207 {
208 mid = (upper + lower) / 2;
209 if (code_hint_pairs[mid].ec < ec)
210 {
211 lower = mid + 1;
212 }
213 else if (code_hint_pairs[mid].ec > ec)
214 {
215 upper = mid - 1;
216 }
217 else
218 {
219 return code_hint_pairs[mid].hint;
220 }
221 }
222 return "<no hint found>";
223}
224
225
226unsigned int
228{
229 unsigned int lower = 0;
230 unsigned int upper = code_hint_pairs_length - 1;
231 unsigned int mid = upper / 2;
232 while (lower <= upper)
233 {
234 mid = (upper + lower) / 2;
235 if (code_hint_pairs[mid].ec < ec)
236 {
237 lower = mid + 1;
238 }
239 else if (code_hint_pairs[mid].ec > ec)
240 {
241 upper = mid - 1;
242 }
243 else
244 {
245 return code_hint_pairs[mid].http_code;
246 }
247 }
248 return UINT_MAX;
249}
250
251
252unsigned int
254{
255 unsigned int hc;
256
258 if ( (0 == hc) ||
259 (UINT_MAX == hc) )
261 return hc;
262}
static const unsigned int code_hint_pairs_length
The length of code_hint_pairs.
#define MHD_HTTP_UNINITIALIZED
MHD does not define our value for 0 (client-side generated code).
static const struct ErrorCodeAndHint code_hint_pairs[]
The list of all error codes with their hints.
#define gettext_noop(String)
Definition: gettext.h:74
@ MHD_HTTP_BAD_REQUEST
Bad Request [RFC7231, Section 6.5.1].
@ MHD_HTTP_NOT_FOUND
Not Found [RFC7231, Section 6.5.4].
@ MHD_HTTP_INTERNAL_SERVER_ERROR
Internal Server Error [RFC7231, Section 6.6.1].
@ MHD_HTTP_CONFLICT
Conflict [RFC7231, Section 6.5.8].
GNUNET_ErrorCode
Taler error codes.
@ GNUNET_EC_NAMESTORE_NO_RESULTS
No results given.
@ GNUNET_EC_NAMESTORE_RECORD_DELETE_FAILED
Zone iteration failed.
@ GNUNET_EC_NAMESTORE_LABEL_INVALID
Label invalid or malformed.
@ GNUNET_EC_NAMESTORE_LOOKUP_ERROR
Failed to lookup record.
@ GNUNET_EC_IDENTITY_INVALID
The given ego is invalid or malformed.
@ GNUNET_EC_NAMESTORE_BACKEND_FAILED
There was an error in the database backend.
@ GNUNET_EC_NAMESTORE_ITERATION_FAILED
Zone iteration failed.
@ GNUNET_EC_NAMESTORE_ZONE_EMPTY
Zone does not contain any records.
@ GNUNET_EC_NAMESTORE_RECORD_TOO_BIG
Record size exceeds maximum limit.
@ GNUNET_EC_SERVICE_COMMUNICATION_FAILED
Communication with service failed.
@ GNUNET_EC_NAMESTORE_STORE_FAILED
Failed to store the given records.
@ GNUNET_EC_NAMESTORE_NO_LABEL_GIVEN
No label given.
@ GNUNET_EC_NAMESTORE_RECORD_DATA_INVALID
Record data invalid.
@ GNUNET_EC_NAMESTORE_NO_RECORDS_GIVEN
No records given.
@ GNUNET_EC_UNKNOWN
Unknown and unspecified error.
@ GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND
Zone not found.
@ GNUNET_EC_NONE
No error (success).
@ GNUNET_EC_IDENTITY_NOT_FOUND
Ego not found.
@ GNUNET_EC_IDENTITY_NAME_CONFLICT
Identifier already in use for another ego.
@ GNUNET_EC_NAMESTORE_RECORD_EXISTS
Record already exists.
@ GNUNET_EC_NAMESTORE_UNKNOWN
Unknown namestore error.
@ GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND
Record not found.
unsigned int GNUNET_ErrorCode_get_http_status_safe(enum GNUNET_ErrorCode ec)
Return HTTP status for a given error code that is guaranteed to work (no corner cases).
const char * GNUNET_ErrorCode_get_hint(enum GNUNET_ErrorCode ec)
Returns a hint for a given error code.
unsigned int GNUNET_ErrorCode_get_http_status(enum GNUNET_ErrorCode ec)
Return HTTP status for a given error code.
A pair containing an error code and its hint.
const char * hint
The hint.
enum GNUNET_ErrorCode ec
The error code.
unsigned int http_code
The HTTP status code.