From f1c18611d7b6ff9e80a087c9c9042cfdfd821a0a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 13 Dec 2020 12:09:51 +0100 Subject: generate logic to lookup HTTP status code by ec, also safely --- gnu-taler-error-codes/c.footer | 18 +++++++++++++++++- gnu-taler-error-codes/h.footer | 14 +++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'gnu-taler-error-codes') diff --git a/gnu-taler-error-codes/c.footer b/gnu-taler-error-codes/c.footer index 118aa08..163901f 100644 --- 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 index 67d90c8..714e7f4 100644 --- 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 -- cgit v1.2.3