diff options
-rw-r--r-- | gnu-taler-error-codes/c.footer | 32 | ||||
-rw-r--r-- | gnu-taler-error-codes/c.header | 9 | ||||
-rw-r--r-- | gnu-taler-error-codes/c.template | 3 | ||||
-rw-r--r-- | gnu-taler-error-codes/h.footer | 10 |
4 files changed, 47 insertions, 7 deletions
diff --git a/gnu-taler-error-codes/c.footer b/gnu-taler-error-codes/c.footer index d6897b6..118aa08 100644 --- a/gnu-taler-error-codes/c.footer +++ b/gnu-taler-error-codes/c.footer | |||
@@ -1,12 +1,6 @@ | |||
1 | 1 | ||
2 | 2 | ||
3 | 3 | ||
4 | /** | ||
5 | * Returns a hint for a given error code. | ||
6 | * | ||
7 | * @param ec the error code. | ||
8 | * @return the hint if it could be found, otherwise "<no hint found>". | ||
9 | */ | ||
10 | const char * | 4 | const char * |
11 | TALER_ErrorCode_get_hint (enum TALER_ErrorCode ec) | 5 | TALER_ErrorCode_get_hint (enum TALER_ErrorCode ec) |
12 | { | 6 | { |
@@ -31,3 +25,29 @@ TALER_ErrorCode_get_hint (enum TALER_ErrorCode ec) | |||
31 | } | 25 | } |
32 | return "<no hint found>"; | 26 | return "<no hint found>"; |
33 | } | 27 | } |
28 | |||
29 | |||
30 | const unsigned int | ||
31 | TALER_ErrorCode_get_http_status (enum TALER_ErrorCode ec) | ||
32 | { | ||
33 | unsigned int lower = 0; | ||
34 | unsigned int upper = code_hint_pairs_length - 1; | ||
35 | unsigned int mid = upper / 2; | ||
36 | while (lower <= upper) | ||
37 | { | ||
38 | mid = (upper + lower) / 2; | ||
39 | if (code_hint_pairs[mid].ec < ec) | ||
40 | { | ||
41 | lower = mid + 1; | ||
42 | } | ||
43 | else if (code_hint_pairs[mid].ec > ec) | ||
44 | { | ||
45 | upper = mid - 1; | ||
46 | } | ||
47 | else | ||
48 | { | ||
49 | return code_hint_pairs[mid].http_status; | ||
50 | } | ||
51 | } | ||
52 | return UINT_MAX; | ||
53 | } | ||
diff --git a/gnu-taler-error-codes/c.header b/gnu-taler-error-codes/c.header index 7b446aa..fb37b22 100644 --- a/gnu-taler-error-codes/c.header +++ b/gnu-taler-error-codes/c.header | |||
@@ -23,6 +23,10 @@ | |||
23 | #include "taler_error_codes.h" | 23 | #include "taler_error_codes.h" |
24 | #include <stddef.h> | 24 | #include <stddef.h> |
25 | 25 | ||
26 | /** | ||
27 | * MHD does not define our value for 0 (client-side generated code). | ||
28 | */ | ||
29 | #define MHD_HTTP_UNINITIALIZED 0 | ||
26 | 30 | ||
27 | /** | 31 | /** |
28 | * A pair containing an error code and its hint. | 32 | * A pair containing an error code and its hint. |
@@ -38,6 +42,11 @@ struct ErrorCodeAndHint | |||
38 | * The hint. | 42 | * The hint. |
39 | */ | 43 | */ |
40 | const char *hint; | 44 | const char *hint; |
45 | |||
46 | /** | ||
47 | * The HTTP status code. | ||
48 | */ | ||
49 | unsigned int http_status; | ||
41 | }; | 50 | }; |
42 | 51 | ||
43 | 52 | ||
diff --git a/gnu-taler-error-codes/c.template b/gnu-taler-error-codes/c.template index 02c39ed..a32b3e6 100644 --- a/gnu-taler-error-codes/c.template +++ b/gnu-taler-error-codes/c.template | |||
@@ -1,5 +1,6 @@ | |||
1 | 1 | ||
2 | { | 2 | { |
3 | .ec = TALER_EC_{{Name}}, | 3 | .ec = TALER_EC_{{Name}}, |
4 | .hint = "{{Description}}" | 4 | .hint = "{{Description}}", |
5 | .http_code = MHD_HTTP_{{HttpStatus_Identifier}} | ||
5 | }, | 6 | }, |
diff --git a/gnu-taler-error-codes/h.footer b/gnu-taler-error-codes/h.footer index 6c32dbd..67d90c8 100644 --- a/gnu-taler-error-codes/h.footer +++ b/gnu-taler-error-codes/h.footer | |||
@@ -13,6 +13,16 @@ const char * | |||
13 | TALER_ErrorCode_get_hint (enum TALER_ErrorCode ec); | 13 | TALER_ErrorCode_get_hint (enum TALER_ErrorCode ec); |
14 | 14 | ||
15 | 15 | ||
16 | /** | ||
17 | * Return HTTP status for a given error code. | ||
18 | * | ||
19 | * @param ec the error code. | ||
20 | * @return the HTTP status code for the given @a ec, UINT_MAX if not found | ||
21 | */ | ||
22 | const unsigned int | ||
23 | TALER_ErrorCode_get_http_status (enum TALER_ErrorCode ec); | ||
24 | |||
25 | |||
16 | #if 0 /* keep Emacsens' auto-indent happy */ | 26 | #if 0 /* keep Emacsens' auto-indent happy */ |
17 | { | 27 | { |
18 | #endif | 28 | #endif |