GNUnet 0.22.2
gnunet_error_codes.c File Reference
#include "gnunet_error_codes.h"
#include <stddef.h>
#include <microhttpd.h>
#include <gettext.h>
Include dependency graph for gnunet_error_codes.c:

Go to the source code of this file.

Data Structures

struct  ErrorCodeAndHint
 A pair containing an error code and its hint. More...
 

Macros

#define MHD_HTTP_UNINITIALIZED   0
 MHD does not define our value for 0 (client-side generated code). More...
 

Functions

const char * GNUNET_ErrorCode_get_hint (enum GNUNET_ErrorCode ec)
 Returns a hint for a given error code. More...
 
unsigned int GNUNET_ErrorCode_get_http_status (enum GNUNET_ErrorCode ec)
 Return HTTP status for a given error code. More...
 
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). More...
 

Variables

static const struct ErrorCodeAndHint code_hint_pairs []
 The list of all error codes with their hints. More...
 
static const unsigned int code_hint_pairs_length = 22
 The length of code_hint_pairs. More...
 

Macro Definition Documentation

◆ MHD_HTTP_UNINITIALIZED

#define MHD_HTTP_UNINITIALIZED   0

MHD does not define our value for 0 (client-side generated code).

Definition at line 28 of file gnunet_error_codes.c.

Function Documentation

◆ GNUNET_ErrorCode_get_hint()

const char * GNUNET_ErrorCode_get_hint ( enum GNUNET_ErrorCode  ec)

Returns a hint for a given error code.

Parameters
ecthe error code.
Returns
the hint if it could be found, otherwise "<no hint found>"

Definition at line 201 of file gnunet_error_codes.c.

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}
static const unsigned int code_hint_pairs_length
The length of code_hint_pairs.
static const struct ErrorCodeAndHint code_hint_pairs[]
The list of all error codes with their hints.
const char * hint
The hint.

References code_hint_pairs, code_hint_pairs_length, ErrorCodeAndHint::ec, and ErrorCodeAndHint::hint.

Referenced by add_continuation(), attr_store_cont(), create_did_ego_create_cb(), create_finished(), cred_store_cont(), del_attr_finished(), del_continuation(), delete_finished(), DID_create_did_store_cb(), do_error(), handle_generic_response(), handle_zone_to_name_response(), marked_deleted(), move_attr_finished(), origin_create_cb(), remove_did_document_namestore_cb(), remove_ticket_cont(), replace_cont(), send_result_code(), and store_completed_cb().

Here is the caller graph for this function:

◆ GNUNET_ErrorCode_get_http_status()

unsigned int GNUNET_ErrorCode_get_http_status ( enum GNUNET_ErrorCode  ec)

Return HTTP status for a given error code.

Parameters
ecthe error code.
Returns
the HTTP status code for the given ec, UINT_MAX if not found

Definition at line 227 of file gnunet_error_codes.c.

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}
unsigned int http_code
The HTTP status code.

References code_hint_pairs, code_hint_pairs_length, ErrorCodeAndHint::ec, and ErrorCodeAndHint::http_code.

Referenced by do_error(), and GNUNET_ErrorCode_get_http_status_safe().

Here is the caller graph for this function:

◆ GNUNET_ErrorCode_get_http_status_safe()

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).

Parameters
ecthe error code.
Returns
the HTTP status code for the given ec, 500 if the ec is not found or is a client-side code

Definition at line 253 of file gnunet_error_codes.c.

254{
255 unsigned int hc;
256
258 if ( (0 == hc) ||
259 (UINT_MAX == hc) )
260 return MHD_HTTP_INTERNAL_SERVER_ERROR;
261 return hc;
262}
unsigned int GNUNET_ErrorCode_get_http_status(enum GNUNET_ErrorCode ec)
Return HTTP status for a given error code.

References ErrorCodeAndHint::ec, and GNUNET_ErrorCode_get_http_status().

Here is the call graph for this function:

Variable Documentation

◆ code_hint_pairs

const struct ErrorCodeAndHint code_hint_pairs[]
static

The list of all error codes with their hints.

Definition at line 55 of file gnunet_error_codes.c.

Referenced by GNUNET_ErrorCode_get_hint(), and GNUNET_ErrorCode_get_http_status().

◆ code_hint_pairs_length

const unsigned int code_hint_pairs_length = 22
static

The length of code_hint_pairs.

Definition at line 196 of file gnunet_error_codes.c.

Referenced by GNUNET_ErrorCode_get_hint(), and GNUNET_ErrorCode_get_http_status().