diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2021-07-28 09:13:21 +0200 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2021-07-28 09:13:21 +0200 |
commit | 6516f1899f4202d802901d08ce26d02db63af83f (patch) | |
tree | 561efa3beadc892dd330e1886b902f405564f24b /src/mhd | |
parent | 225543b8001148b8540b92966196ac2d5e9c826e (diff) |
start to use new GNUNET_JSON_PACK functionality
Diffstat (limited to 'src/mhd')
-rw-r--r-- | src/mhd/mhd_responses.c | 143 |
1 files changed, 13 insertions, 130 deletions
diff --git a/src/mhd/mhd_responses.c b/src/mhd/mhd_responses.c index 90a8d19f4..b666720e6 100644 --- a/src/mhd/mhd_responses.c +++ b/src/mhd/mhd_responses.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2020 Taler Systems SA + Copyright (C) 2014-2021 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -32,12 +32,6 @@ static enum TALER_MHD_GlobalOptions TM_go; -/** - * Set global options for response generation - * within libtalermhd. - * - * @param go global options to use - */ void TALER_MHD_setup (enum TALER_MHD_GlobalOptions go) { @@ -45,13 +39,6 @@ TALER_MHD_setup (enum TALER_MHD_GlobalOptions go) } -/** - * Add headers we want to return in every response. - * Useful for testing, like if we want to always close - * connections. - * - * @param response response to modify - */ void TALER_MHD_add_global_headers (struct MHD_Response *response) { @@ -69,17 +56,6 @@ TALER_MHD_add_global_headers (struct MHD_Response *response) } -/** - * Is HTTP body deflate compression supported by the client? - * - * @param connection connection to check - * @return #MHD_YES if 'deflate' compression is allowed - * - * Note that right now we're ignoring q-values, which is technically - * not correct, and also do not support "*" anywhere but in a line by - * itself. This should eventually be fixed, see also - * https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html - */ MHD_RESULT TALER_MHD_can_compress (struct MHD_Connection *connection) { @@ -111,13 +87,6 @@ TALER_MHD_can_compress (struct MHD_Connection *connection) } -/** - * Try to compress a response body. Updates @a buf and @a buf_size. - * - * @param[in,out] buf pointer to body to compress - * @param[in,out] buf_size pointer to initial size of @a buf - * @return #MHD_YES if @a buf was compressed - */ MHD_RESULT TALER_MHD_body_compress (void **buf, size_t *buf_size) @@ -148,12 +117,6 @@ TALER_MHD_body_compress (void **buf, } -/** - * Make JSON response object. - * - * @param json the json object - * @return MHD response object - */ struct MHD_Response * TALER_MHD_make_json (const json_t *json) { @@ -185,14 +148,6 @@ TALER_MHD_make_json (const json_t *json) } -/** - * Send JSON object as response. - * - * @param connection the MHD connection - * @param json the json object - * @param response_code the http response code - * @return MHD result code - */ MHD_RESULT TALER_MHD_reply_json (struct MHD_Connection *connection, const json_t *json, @@ -264,13 +219,6 @@ TALER_MHD_reply_json (struct MHD_Connection *connection, } -/** - * Send back a "204 No Content" response with headers - * for the CORS pre-flight request. - * - * @param connection the MHD connection - * @return MHD result code - */ MHD_RESULT TALER_MHD_reply_cors_preflight (struct MHD_Connection *connection) { @@ -307,16 +255,6 @@ TALER_MHD_reply_cors_preflight (struct MHD_Connection *connection) } -/** - * Function to call to handle the request by building a JSON - * reply from a format string and varargs. - * - * @param connection the MHD connection to handle - * @param response_code HTTP response code to use - * @param fmt format string for pack - * @param ... varargs - * @return MHD result code - */ MHD_RESULT TALER_MHD_reply_json_pack (struct MHD_Connection *connection, unsigned int response_code, @@ -360,13 +298,6 @@ TALER_MHD_reply_json_pack (struct MHD_Connection *connection, } -/** - * Make JSON response object. - * - * @param fmt format string for pack - * @param ... varargs - * @return MHD response object - */ struct MHD_Response * TALER_MHD_make_json_pack (const char *fmt, ...) @@ -405,57 +336,34 @@ TALER_MHD_make_json_pack (const char *fmt, } -/** - * Create a response indicating an internal error. - * - * @param ec error code to return - * @param detail additional optional detail about the error, can be NULL - * @return a MHD response object - */ struct MHD_Response * TALER_MHD_make_error (enum TALER_ErrorCode ec, const char *detail) { - return TALER_MHD_make_json_pack ("{s:I, s:s, s:s?}", - "code", (json_int_t) ec, - "hint", TALER_ErrorCode_get_hint (ec), - "detail", detail); + return TALER_MHD_make_JSON_PACK ( + GNUNET_JSON_pack_uint64 ("code", ec), + GNUNET_JSON_pack_string ("hint", TALER_ErrorCode_get_hint (ec)), + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_string ("detail", detail))); } -/** - * Send a response indicating an error. - * - * @param connection the MHD connection to use - * @param ec error code uniquely identifying the error - * @param http_status HTTP status code to use - * @param detail additional optional detail about the error, can be NULL - * @return a MHD result code - */ MHD_RESULT TALER_MHD_reply_with_error (struct MHD_Connection *connection, unsigned int http_status, enum TALER_ErrorCode ec, const char *detail) { - return TALER_MHD_reply_json_pack (connection, - http_status, - "{s:I, s:s, s:s?}", - "code", (json_int_t) ec, - "hint", TALER_ErrorCode_get_hint (ec), - "detail", detail); + return TALER_MHD_reply_JSON_PACK ( + connection, + http_status, + GNUNET_JSON_pack_uint64 ("code", ec), + GNUNET_JSON_pack_string ("hint", TALER_ErrorCode_get_hint (ec)), + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_string ("detail", detail))); } -/** - * Send a response indicating an error. The HTTP status code is - * to be derived from the @a ec. - * - * @param connection the MHD connection to use - * @param ec error code uniquely identifying the error - * @param detail additional optional detail about the error - * @return a MHD result code - */ MHD_RESULT TALER_MHD_reply_with_ec (struct MHD_Connection *connection, enum TALER_ErrorCode ec, @@ -478,12 +386,6 @@ TALER_MHD_reply_with_ec (struct MHD_Connection *connection, } -/** - * Send a response indicating that the request was too big. - * - * @param connection the MHD connection to use - * @return a MHD result code - */ MHD_RESULT TALER_MHD_reply_request_too_large (struct MHD_Connection *connection) { @@ -508,14 +410,6 @@ TALER_MHD_reply_request_too_large (struct MHD_Connection *connection) } -/** - * Function to call to handle the request by sending - * back a redirect to the AGPL source code. - * - * @param connection the MHD connection to handle - * @param url where to redirect for the sources - * @return MHD result code - */ MHD_RESULT TALER_MHD_reply_agpl (struct MHD_Connection *connection, const char *url) @@ -559,17 +453,6 @@ TALER_MHD_reply_agpl (struct MHD_Connection *connection, } -/** - * Function to call to handle the request by sending - * back static data. - * - * @param connection the MHD connection to handle - * @param http_status status code to return - * @param mime_type content-type to use - * @param body response payload - * @param body_size number of bytes in @a body - * @return MHD result code - */ MHD_RESULT TALER_MHD_reply_static (struct MHD_Connection *connection, unsigned int http_status, |