diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-12-13 12:07:10 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-12-13 12:07:10 +0100 |
commit | 7626b96d37ca125d8b9bf34db7b0305f11d02361 (patch) | |
tree | 6bbdca97fdd4d34fed40922915d0833f24da594b /gnu-taler-error-codes/c.footer | |
parent | 1e1a13c64febaf890617e59cc0f41cb9c17a025b (diff) | |
download | gana-7626b96d37ca125d8b9bf34db7b0305f11d02361.tar.gz gana-7626b96d37ca125d8b9bf34db7b0305f11d02361.zip |
generate logic to lookup HTTP status code by ec
Diffstat (limited to 'gnu-taler-error-codes/c.footer')
-rw-r--r-- | gnu-taler-error-codes/c.footer | 32 |
1 files changed, 26 insertions, 6 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 | } | ||