aboutsummaryrefslogtreecommitdiff
path: root/gnu-taler-error-codes/c.footer
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-12-13 12:07:10 +0100
committerChristian Grothoff <christian@grothoff.org>2020-12-13 12:07:10 +0100
commit7626b96d37ca125d8b9bf34db7b0305f11d02361 (patch)
tree6bbdca97fdd4d34fed40922915d0833f24da594b /gnu-taler-error-codes/c.footer
parent1e1a13c64febaf890617e59cc0f41cb9c17a025b (diff)
downloadgana-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.footer32
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 */
10const char * 4const char *
11TALER_ErrorCode_get_hint (enum TALER_ErrorCode ec) 5TALER_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
30const unsigned int
31TALER_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}