gana

GNUnet Assigned Numbers Authority
Log | Files | Refs | README | LICENSE

commit f1c18611d7b6ff9e80a087c9c9042cfdfd821a0a
parent 7626b96d37ca125d8b9bf34db7b0305f11d02361
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 13 Dec 2020 12:09:51 +0100

generate logic to lookup HTTP status code by ec, also safely

Diffstat:
Mgnu-taler-error-codes/c.footer | 18+++++++++++++++++-
Mgnu-taler-error-codes/h.footer | 14+++++++++++++-
2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/gnu-taler-error-codes/c.footer b/gnu-taler-error-codes/c.footer @@ -27,7 +27,7 @@ TALER_ErrorCode_get_hint (enum TALER_ErrorCode ec) } -const unsigned int +unsigned int TALER_ErrorCode_get_http_status (enum TALER_ErrorCode ec) { unsigned int lower = 0; @@ -51,3 +51,19 @@ TALER_ErrorCode_get_http_status (enum TALER_ErrorCode ec) } return UINT_MAX; } + + +unsigned int +TALER_ErrorCode_get_http_status_safe (enum TALER_ErrorCode ec) +{ + unsigned int hc; + + hc = TALER_ErrorCode_get_http_status (ec); + if ( (0 == hc) || + (UINT_MAX == hc) ) + { + GNUNET_break (0); + return MHD_HTTP_INTERNAL_SERVER_ERROR; + } + return hc; +} diff --git a/gnu-taler-error-codes/h.footer b/gnu-taler-error-codes/h.footer @@ -19,10 +19,22 @@ TALER_ErrorCode_get_hint (enum TALER_ErrorCode ec); * @param ec the error code. * @return the HTTP status code for the given @a ec, UINT_MAX if not found */ -const unsigned int +unsigned int TALER_ErrorCode_get_http_status (enum TALER_ErrorCode ec); +/** + * Return HTTP status for a given error code that is guaranteed + * to work (no corner cases). + * + * @param ec the error code. + * @return the HTTP status code for the given @a ec, 500 if + * the @a ec is not found or is a client-side code + */ +unsigned int +TALER_ErrorCode_get_http_status_safe (enum TALER_ErrorCode ec); + + #if 0 /* keep Emacsens' auto-indent happy */ { #endif