[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: simplify backend via libtalermh
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: simplify backend via libtalermhd |
Date: |
Sun, 24 Nov 2019 18:00:45 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new 9eab2e9 simplify backend via libtalermhd
9eab2e9 is described below
commit 9eab2e9046c5474791bc419554d902ff6fe39f14
Author: Christian Grothoff <address@hidden>
AuthorDate: Sun Nov 24 18:00:42 2019 +0100
simplify backend via libtalermhd
---
src/backend/Makefile.am | 2 -
src/backend/anastasis-httpd.c | 2 -
src/backend/anastasis-httpd_parsing.c | 272 ---------------------
src/backend/anastasis-httpd_parsing.h | 93 --------
src/backend/anastasis-httpd_policy.c | 34 +--
src/backend/anastasis-httpd_responses.c | 408 --------------------------------
src/backend/anastasis-httpd_responses.h | 244 -------------------
src/backend/anastasis-httpd_truth.c | 3 +-
8 files changed, 21 insertions(+), 1037 deletions(-)
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index f5487ff..4198a5a 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -13,8 +13,6 @@ bin_PROGRAMS = \
anastasis_httpd_SOURCES = \
anastasis-httpd.c anastasis-httpd.h \
- anastasis-httpd_parsing.c anastasis-httpd_parsing.h \
- anastasis-httpd_responses.c anastasis-httpd_responses.h \
anastasis-httpd_mhd.c anastasis-httpd_mhd.h \
anastasis-httpd_policy.c anastasis-httpd_policy.h \
anastasis-httpd_truth.c anastasis-httpd_truth.h
diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index 92bd093..eca8373 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -22,9 +22,7 @@
#include <microhttpd.h>
#include <gnunet/gnunet_util_lib.h>
#include <taler/taler_mhd_lib.h>
-#include "anastasis-httpd_responses.h"
#include "anastasis-httpd.h"
-#include "anastasis-httpd_parsing.h"
#include "anastasis-httpd_mhd.h"
#include "anastasis_database_lib.h"
#include "anastasis-httpd_policy.h"
diff --git a/src/backend/anastasis-httpd_parsing.c
b/src/backend/anastasis-httpd_parsing.c
deleted file mode 100644
index b2295d3..0000000
--- a/src/backend/anastasis-httpd_parsing.c
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014, 2015, 2016 GNUnet e.V.
-
- 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 Foundation; either version 3,
- or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public
- License along with TALER; see the file COPYING. If not,
- see <http://www.gnu.org/licenses/>
-*/
-
-/**
- * @file anastasis-httpd_parsing.c
- * @brief functions to parse incoming requests
- * (MHD arguments and JSON snippets)
- * @author Florian Dold
- * @author Benedikt Mueller
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <gnunet/gnunet_util_lib.h>
-#include <taler/taler_json_lib.h>
-#include "anastasis-httpd_parsing.h"
-#include "anastasis-httpd_responses.h"
-
-/* FIXME: de-duplicate code with taler-exchange-httpd_parsing.c
- and taler-exchange-httpd_response.c */
-
-/**
- * Initial size for POST request buffer.
- */
-#define REQUEST_BUFFER_INITIAL (2 * 1024)
-
-/**
- * Maximum POST request size.
- */
-#define REQUEST_BUFFER_MAX (1024 * 1024)
-
-
-/**
- * Buffer for POST requests.
- */
-struct Buffer
-{
- /**
- * Allocated memory
- */
- char *data;
-
- /**
- * Number of valid bytes in buffer.
- */
- size_t fill;
-
- /**
- * Number of allocated bytes in buffer.
- */
- size_t alloc;
-};
-
-
-
-
-/**
- * Free the data in a buffer. Does *not* free
- * the buffer object itself.
- *
- * @param buf buffer to de-initialize
- */
-static void
-buffer_deinit (struct Buffer *buf)
-{
- GNUNET_free_non_null (buf->data);
- buf->data = NULL;
-}
-
-
-
-/**
- * Function called whenever we are done with a request
- * to clean up our state.
- *
- * @param con_cls value as it was left by
- * #TMH_PARSE_post_json(), to be cleaned up
- */
-void
-TMH_PARSE_post_cleanup_callback (void *con_cls)
-{
- struct Buffer *r = con_cls;
-
- if (NULL != r)
- {
- buffer_deinit (r);
- GNUNET_free (r);
- }
-}
-
-
-/**
- * Process a POST request containing a JSON object. This function
- * realizes an MHD POST processor that will (incrementally) process
- * JSON data uploaded to the HTTP server. It will store the
- * required state in the @a con_cls, which must be cleaned up
- * using #TMH_PARSE_post_cleanup_callback().
- *
- * @param connection the MHD connection
- * @param con_cls the closure (points to a `struct Buffer *`)
- * @param upload_data the POST data
- * @param upload_data_size number of bytes in @a upload_data
- * @param json the JSON object for a completed request
- * @return
- * #GNUNET_YES if json object was parsed or at least
- * may be parsed in the future (call again);
- * `*json` will be NULL if we need to be called again,
- * and non-NULL if we are done.
- * #GNUNET_NO if request is incomplete or invalid
- * (error message was generated)
- * #GNUNET_SYSERR on internal error
- * (we could not even queue an error message,
- * close HTTP session with MHD_NO)
- */
-int
-TMH_PARSE_post_json (struct MHD_Connection *connection,
- void **con_cls,
- const char *upload_data,
- size_t *upload_data_size,
- json_t **json)
-{
- enum GNUNET_JSON_PostResult pr;
-
- pr = GNUNET_JSON_post_parser (REQUEST_BUFFER_MAX,
- connection,
- con_cls,
- upload_data,
- upload_data_size,
- json);
- switch (pr)
- {
-
- case GNUNET_JSON_PR_OUT_OF_MEMORY:
- return (MHD_NO == TMH_RESPONSE_reply_internal_error
- (connection,
- TALER_EC_PARSER_OUT_OF_MEMORY,
- "out of memory")) ? GNUNET_SYSERR : GNUNET_NO;
-
- case GNUNET_JSON_PR_CONTINUE:
- return GNUNET_YES;
-
- case GNUNET_JSON_PR_REQUEST_TOO_LARGE:
- return (MHD_NO == TMH_RESPONSE_reply_request_too_large
- (connection)) ? GNUNET_SYSERR : GNUNET_NO;
-
- case GNUNET_JSON_PR_JSON_INVALID:
- return (MHD_YES ==
- TMH_RESPONSE_reply_invalid_json (connection))
- ? GNUNET_NO : GNUNET_SYSERR;
- case GNUNET_JSON_PR_SUCCESS:
- GNUNET_break (NULL != *json);
- return GNUNET_YES;
- }
- /* this should never happen */
- GNUNET_break (0);
- return GNUNET_SYSERR;
-}
-
-
-/**
- * Parse JSON object into components based on the given field
- * specification.
- *
- * @param connection the connection to send an error response to
- * @param root the JSON node to start the navigation at.
- * @param spec field specification for the parser
- * @return
- * #GNUNET_YES if navigation was successful (caller is responsible
- * for freeing allocated variable-size data using
- * #GNUNET_JSON_parse_free() when done)
- * #GNUNET_NO if json is malformed, error response was generated
- * #GNUNET_SYSERR on internal error
- */
-int
-TMH_PARSE_json_data (struct MHD_Connection *connection,
- const json_t *root,
- struct GNUNET_JSON_Specification *spec)
-{
- int ret;
- const char *error_json_name;
- unsigned int error_line;
-
- ret = GNUNET_JSON_parse (root,
- spec,
- &error_json_name,
- &error_line);
- if (GNUNET_SYSERR == ret)
- {
- if (NULL == error_json_name)
- error_json_name = "<no field>";
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Parsing failed due to field '%s'\n",
- error_json_name);
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:s, s:I}",
- "error", "parse error",
- "field", error_json_name,
- "line", (json_int_t) error_line))
- ? GNUNET_NO : GNUNET_SYSERR;
- return ret;
- }
- return GNUNET_YES;
-}
-
-
-
-/**
- * Extract base32crockford encoded data from request.
- *
- * Queues an error response to the connection if the parameter is
- * missing or invalid.
- *
- * @param connection the MHD connection
- * @param param_name the name of the parameter with the key
- * @param[out] out_data pointer to store the result
- * @param out_size expected size of data
- * @return
- * #GNUNET_YES if the the argument is present
- * #GNUNET_NO if the argument is absent or malformed
- * #GNUNET_SYSERR on internal error (error response could not be sent)
- */
-int
-TMH_PARSE_mhd_request_arg_data (struct MHD_Connection *connection,
- const char *param_name,
- void *out_data,
- size_t out_size)
-{
- const char *str;
-
- str = MHD_lookup_connection_value (connection,
- MHD_GET_ARGUMENT_KIND,
- param_name);
- if (NULL == str)
- {
- return (MHD_NO ==
- TMH_RESPONSE_reply_arg_missing (connection,
- TALER_EC_PARAMETER_MISSING,
- param_name))
- ? GNUNET_SYSERR : GNUNET_NO;
- }
- if (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (str,
- strlen (str),
- out_data,
- out_size))
- return (MHD_NO ==
- TMH_RESPONSE_reply_arg_invalid (connection,
- TALER_EC_PARAMETER_MALFORMED,
- param_name))
- ? GNUNET_SYSERR : GNUNET_NO;
- return GNUNET_OK;
-}
-
-
-/* end of taler-merchant-httpd_parsing.c */
diff --git a/src/backend/anastasis-httpd_parsing.h
b/src/backend/anastasis-httpd_parsing.h
deleted file mode 100644
index 3e5816a..0000000
--- a/src/backend/anastasis-httpd_parsing.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014, 2015, 2016 GNUnet e.V.
-
- 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
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
details.
-
- You should have received a copy of the GNU Affero General Public License
along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file anastasis-httpd_parsing.h
- * @brief functions to parse incoming requests
- * @author Florian Dold
- * @author Benedikt Mueller
- * @author Christian Grothoff
- */
-#ifndef ANASTASIS_HTTPD_PARSING_H
-#define ANASTASIS_HTTPD_PARSING_H
-
-#include <microhttpd.h>
-#include <taler/taler_util.h>
-#include <taler/taler_json_lib.h>
-
-/**
- * Process a POST request containing a JSON object. This
- * function realizes an MHD POST processor that will
- * (incrementally) process JSON data uploaded to the HTTP
- * server. It will store the required state in the
- * "connection_cls", which must be cleaned up using
- * #TMH_PARSE_post_cleanup_callback().
- *
- * @param connection the MHD connection
- * @param con_cls the closure (points to a `struct Buffer *`)
- * @param upload_data the POST data
- * @param upload_data_size number of bytes in @a upload_data
- * @param json the JSON object for a completed request
- * @return
- * #GNUNET_YES if json object was parsed or at least
- * may be parsed in the future (call again);
- * `*json` will be NULL if we need to be called again,
- * and non-NULL if we are done.
- * #GNUNET_NO is request incomplete or invalid
- * (error message was generated)
- * #GNUNET_SYSERR on internal error
- * (we could not even queue an error message,
- * close HTTP session with MHD_NO)
- */
-int
-TMH_PARSE_post_json (struct MHD_Connection *connection,
- void **con_cls,
- const char *upload_data,
- size_t *upload_data_size,
- json_t **json);
-
-
-/**
- * Function called whenever we are done with a request
- * to clean up our state.
- *
- * @param con_cls value as it was left by
- * #TMH_PARSE_post_json(), to be cleaned up
- */
-void
-TMH_PARSE_post_cleanup_callback (void *con_cls);
-
-
-/**
- * Parse JSON object into components based on the given field
- * specification.
- *
- * @param connection the connection to send an error response to
- * @param root the JSON node to start the navigation at.
- * @param spec field specification for the parser
- * @return
- * #GNUNET_YES if navigation was successful (caller is responsible
- * for freeing allocated variable-size data using
- * #GNUNET_JSON_parse_free() when done)
- * #GNUNET_NO if json is malformed, error response was generated
- * #GNUNET_SYSERR on internal error
- */
-int
-TMH_PARSE_json_data (struct MHD_Connection *connection,
- const json_t *root,
- struct GNUNET_JSON_Specification *spec);
-
-
-#endif /* TALER_MERCHANT_HTTPD_PARSING_H */
diff --git a/src/backend/anastasis-httpd_policy.c
b/src/backend/anastasis-httpd_policy.c
index 6ed7cc3..2d3c8cc 100644
--- a/src/backend/anastasis-httpd_policy.c
+++ b/src/backend/anastasis-httpd_policy.c
@@ -24,7 +24,7 @@
#include "anastasis-httpd.h"
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_rest_lib.h>
-#include "anastasis-httpd_responses.h"
+
/**
* @param connection the MHD connection to handle
@@ -57,9 +57,10 @@ AH_handler_policy_GET (struct MHD_Connection *connection,
strlen (account),
&accountPubP.pub))
{
- return TMH_RESPONSE_reply_bad_request (connection,
- 42 /*FIXME */,
- "account public key malformed");
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ 42 /*FIXME */,
+ "account public key malformed");
}
}
version_s = MHD_lookup_connection_value (connection,
@@ -74,9 +75,10 @@ AH_handler_policy_GET (struct MHD_Connection *connection,
"%u",
&version))
{
- return TMH_RESPONSE_reply_arg_invalid (connection,
- 43 /*FIXME */,
- "version");
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ 43 /*FIXME */,
+ "version");
}
qs = db->get_recovery_document (db->cls,
&accountPubP,
@@ -97,9 +99,10 @@ AH_handler_policy_GET (struct MHD_Connection *connection,
{
// FIXME: handle DB error cases!
case ANASTASIS_DB_STATUS_SUCCESS_NO_RESULTS:
- return TMH_RESPONSE_reply_not_found (connection,
- 42 /*FIXME*/,
- "recovery data not available");
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ 42 /*FIXME*/,
+ "recovery data not available");
case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
GNUNET_assert (NULL != res_recovery_data);
break;
@@ -118,7 +121,7 @@ AH_handler_policy_GET (struct MHD_Connection *connection,
response = MHD_create_response_from_buffer (sizeof (res_recovery_data),
res_recovery_data,
MHD_RESPMEM_MUST_FREE);
- TMH_RESPONSE_add_global_headers (response);
+ TALER_MHD_add_global_headers (response);
GNUNET_break (MHD_YES ==
MHD_add_response_header (response,
MHD_HTTP_HEADER_CONTENT_TYPE,
@@ -171,9 +174,10 @@ AH_handler_policy_POST (struct MHD_Connection *connection,
strlen (account),
&accountPubP.pub))
{
- return TMH_RESPONSE_reply_bad_request (connection,
- 42 /*FIXME */,
- "account public key malformed");
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ 42 /*FIXME */,
+ "account public key malformed");
}
paymentIdentifier_str = MHD_lookup_connection_value (connection,
@@ -200,7 +204,7 @@ AH_handler_policy_POST (struct MHD_Connection *connection,
// FIXME: find correct create response
response = GNUNET_REST_create_response ("Irgendwas");
- TMH_RESPONSE_add_global_headers (response);
+ TALER_MHD_add_global_headers (response);
GNUNET_break (MHD_YES ==
MHD_add_response_header (response,
"Anastasis-Version",
diff --git a/src/backend/anastasis-httpd_responses.c
b/src/backend/anastasis-httpd_responses.c
deleted file mode 100644
index 2b5a8a0..0000000
--- a/src/backend/anastasis-httpd_responses.c
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2017 GNUnet e.V.
-
- 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
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
details.
-
- You should have received a copy of the GNU Affero General Public License
along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file anastasis-httpd_responses.c
- * @brief API for generating the various replies of the exchange; these
- * functions are called TMH_RESPONSE_reply_ and they generate
- * and queue MHD response objects for a given connection.
- * @author Florian Dold
- * @author Benedikt Mueller
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "anastasis-httpd.h"
-#include "anastasis-httpd_responses.h"
-#include <taler/taler_util.h>
-#include <taler/taler_json_lib.h>
-#include <gnunet/gnunet_util_lib.h>
-
-
-/**
- * Make JSON response object.
- *
- * @param json the json object
- * @return MHD response object
- */
-struct MHD_Response *
-TMH_RESPONSE_make_json (const json_t *json)
-{
- struct MHD_Response *resp;
- char *json_str;
-
- json_str = json_dumps (json,
- JSON_INDENT (2));
- if (NULL == json_str)
- {
- GNUNET_break (0);
- return NULL;
- }
- resp = MHD_create_response_from_buffer (strlen (json_str),
- json_str,
- MHD_RESPMEM_MUST_FREE);
- if (NULL == resp)
- {
- free (json_str);
- GNUNET_break (0);
- return NULL;
- }
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (resp,
- MHD_HTTP_HEADER_CONTENT_TYPE,
- "application/json"));
- return resp;
-}
-
-
-/**
- * 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
- */
-int
-TMH_RESPONSE_reply_json (struct MHD_Connection *connection,
- const json_t *json,
- unsigned int response_code)
-{
- struct MHD_Response *resp;
- int ret;
-
- resp = TMH_RESPONSE_make_json (json);
- if (NULL == resp)
- return MHD_NO;
- ret = MHD_queue_response (connection,
- response_code,
- resp);
- MHD_destroy_response (resp);
- return ret;
-}
-
-
-/**
- * Make JSON response object.
- *
- * @param fmt format string for pack
- * @param ... varargs
- * @return MHD response object
- */
-struct MHD_Response *
-TMH_RESPONSE_make_json_pack (const char *fmt,
- ...)
-{
- json_t *json;
- va_list argp;
- struct MHD_Response *ret;
- json_error_t jerror;
-
- va_start (argp, fmt);
- json = json_vpack_ex (&jerror,
- 0,
- fmt,
- argp);
- va_end (argp);
- if (NULL == json)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to pack JSON with format `%s': %s\n",
- fmt,
- jerror.text);
- GNUNET_break (0);
- return MHD_NO;
- }
- ret = TMH_RESPONSE_make_json (json);
- json_decref (json);
- return ret;
-}
-
-
-/**
- * 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
- */
-int
-TMH_RESPONSE_reply_json_pack (struct MHD_Connection *connection,
- unsigned int response_code,
- const char *fmt,
- ...)
-{
- json_t *json;
- va_list argp;
- int ret;
- json_error_t jerror;
-
- va_start (argp, fmt);
- json = json_vpack_ex (&jerror,
- 0,
- fmt,
- argp);
- va_end (argp);
- if (NULL == json)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to pack JSON with format `%s': %s\n",
- fmt,
- jerror.text);
- GNUNET_break (0);
- return MHD_NO;
- }
- ret = TMH_RESPONSE_reply_json (connection,
- json,
- response_code);
- json_decref (json);
- return ret;
-}
-
-
-/**
- * Create a response indicating an internal error.
- *
- * @param ec error code to return
- * @param hint hint about the internal error's nature
- * @return a MHD response object
- */
-struct MHD_Response *
-TMH_RESPONSE_make_error (enum TALER_ErrorCode ec,
- const char *hint)
-{
- return TMH_RESPONSE_make_json_pack ("{s:I, s:s}",
- "code", (json_int_t) ec,
- "hint", hint);
-}
-
-
-/**
- * Send a response indicating an internal error.
- *
- * @param connection the MHD connection to use
- * @param ec error code to return
- * @param hint hint about the internal error's nature
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_internal_error (struct MHD_Connection *connection,
- enum TALER_ErrorCode ec,
- const char *hint)
-{
- return TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- "{s:I, s:s}",
- "code", (json_int_t) ec,
- "hint", hint);
-}
-
-
-/**
- * Send a response indicating that the request was too big.
- *
- * @param connection the MHD connection to use
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_request_too_large (struct MHD_Connection *connection)
-{
- struct MHD_Response *resp;
- int ret;
-
- resp = MHD_create_response_from_buffer (0,
- NULL,
- MHD_RESPMEM_PERSISTENT);
- if (NULL == resp)
- return MHD_NO;
- ret = MHD_queue_response (connection,
- MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
- resp);
- MHD_destroy_response (resp);
- return ret;
-}
-
-
-/**
- * Send a response indicating that we did not find the @a object
- * needed for the reply.
- *
- * @param connection the MHD connection to use
- * @param response_code response code to use
- * @param ec error code to return
- * @param msg human-readable diagnostic
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_rc (struct MHD_Connection *connection,
- unsigned int response_code,
- enum TALER_ErrorCode ec,
- const char *msg)
-{
- return TMH_RESPONSE_reply_json_pack (connection,
- response_code,
- "{s:I, s:s}",
- "code", (json_int_t) ec,
- "error", msg);
-}
-
-
-/**
- * Send a response indicating that the JSON was malformed.
- *
- * @param connection the MHD connection to use
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_invalid_json (struct MHD_Connection *connection)
-{
- return TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:I, s:s}",
- "code",
- (json_int_t) TALER_EC_JSON_INVALID,
- "error", "invalid json");
-}
-
-
-/**
- * Send a response indicating that we did not find the @a object
- * needed for the reply.
- *
- * @param connection the MHD connection to use
- * @param ec error code to return
- * @param object name of the object we did not find
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_not_found (struct MHD_Connection *connection,
- enum TALER_ErrorCode ec,
- const char *object)
-{
- return TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_NOT_FOUND,
- "{s:I, s:s}",
- "code", (json_int_t) ec,
- "error", object);
-}
-
-
-/**
- * Send a response indicating that the request was malformed.
- *
- * @param connection the MHD connection to use
- * @param ec error code to return
- * @param issue description of what was wrong with the request
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_bad_request (struct MHD_Connection *connection,
- enum TALER_ErrorCode ec,
- const char *issue)
-{
- return TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:I, s:s}",
- "code", (json_int_t) ec,
- "error", issue);
-}
-
-
-/**
- * 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
-TMH_RESPONSE_add_global_headers (struct MHD_Response *response)
-{
- if (TMH_anastasis_connection_close)
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (response,
- MHD_HTTP_HEADER_CONNECTION,
- "close"));
-}
-
-
-/**
- * Send a response indicating an external error.
- *
- * @param connection the MHD connection to use
- * @param ec error code to return
- * @param hint hint about the error's nature
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_external_error (struct MHD_Connection *connection,
- enum TALER_ErrorCode ec,
- const char *hint)
-{
- return TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:I, s:s}",
- "code", (json_int_t) ec,
- "hint", hint);
-}
-
-
-/**
- * Send a response indicating a missing argument.
- *
- * @param connection the MHD connection to use
- * @param ec error code to return
- * @param param_name the parameter that is missing
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_arg_missing (struct MHD_Connection *connection,
- enum TALER_ErrorCode ec,
- const char *param_name)
-{
- return TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:I, s:s}",
- "error", "missing parameter",
- "code", (json_int_t) ec,
- "parameter", param_name);
-}
-
-
-/**
- * Send a response indicating an invalid argument.
- *
- * @param connection the MHD connection to use
- * @param ec error code to return
- * @param param_name the parameter that is invalid
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_arg_invalid (struct MHD_Connection *connection,
- enum TALER_ErrorCode ec,
- const char *param_name)
-{
- return TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:I, s:s}",
- "error", "invalid parameter",
- "code", (json_int_t) ec,
- "parameter", param_name);
-}
-
-
-/* end of taler-exchange-httpd_responses.c */
diff --git a/src/backend/anastasis-httpd_responses.h
b/src/backend/anastasis-httpd_responses.h
deleted file mode 100644
index 6f17e74..0000000
--- a/src/backend/anastasis-httpd_responses.h
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2017 GNUnet e.V.
-
- 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
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
details.
-
- You should have received a copy of the GNU Affero General Public License
along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file anastasis-httpd_responses.h
- * @brief API for generating the various replies of the exchange; these
- * functions are called TMH_RESPONSE_reply_ and they generate
- * and queue MHD response objects for a given connection.
- * @author Florian Dold
- * @author Benedikt Mueller
- * @author Christian Grothoff
- */
-#ifndef ANASTASIS_HTTPD_RESPONSES_H
-#define ANASTASIS_HTTPD_RESPONSES_H
-#include "anastasis-httpd.h"
-#include <taler/taler_util.h>
-#include <taler/taler_json_lib.h>
-#include <gnunet/gnunet_util_lib.h>
-
-
-
-/**
- * Make JSON response object.
- *
- * @param json the json object
- * @return MHD response object
- */
-struct MHD_Response *
-TMH_RESPONSE_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
- */
-int
-TMH_RESPONSE_reply_json (struct MHD_Connection *connection,
- const json_t *json,
- unsigned int response_code);
-
-
-/**
- * Make JSON response object.
- *
- * @param fmt format string for pack
- * @param ... varargs
- * @return MHD response object
- */
-struct MHD_Response *
-TMH_RESPONSE_make_json_pack (const char *fmt,
- ...);
-
-
-
-
-/**
- * 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
- */
-int
-TMH_RESPONSE_reply_json_pack (struct MHD_Connection *connection,
- unsigned int response_code,
- const char *fmt,
- ...);
-
-
-/**
- * Create a response indicating an internal error.
- *
- * @param ec error code to return
- * @param hint hint about the internal error's nature
- * @return a MHD response object
- */
-struct MHD_Response *
-TMH_RESPONSE_make_error (enum TALER_ErrorCode ec,
- const char *hint);
-
-
-/**
- * Send a response indicating an internal error.
- *
- * @param connection the MHD connection to use
- * @param ec error code to return
- * @param hint hint about the internal error's nature
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_internal_error (struct MHD_Connection *connection,
- enum TALER_ErrorCode ec,
- const char *hint);
-
-
-
-
-/**
- * Send a response indicating that the request was too big.
- *
- * @param connection the MHD connection to use
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_request_too_large (struct MHD_Connection *connection);
-
-
-
-/**
- * Send a response indicating that we did not find the @a object
- * needed for the reply.
- *
- * @param connection the MHD connection to use
- * @param response_code response code to use
- * @param ec error code to return
- * @param msg human-readable diagnostic
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_rc (struct MHD_Connection *connection,
- unsigned int response_code,
- enum TALER_ErrorCode ec,
- const char *msg);
-
-
-
-/**
- * Send a response indicating that the JSON was malformed.
- *
- * @param connection the MHD connection to use
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_invalid_json (struct MHD_Connection *connection);
-
-
-
-/**
- * Send a response indicating that we did not find the @a object
- * needed for the reply.
- *
- * @param connection the MHD connection to use
- * @param ec error code to return
- * @param object name of the object we did not find
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_not_found (struct MHD_Connection *connection,
- enum TALER_ErrorCode ec,
- const char *object);
-
-
-
-/**
- * Send a response indicating that the request was malformed.
- *
- * @param connection the MHD connection to use
- * @param ec error code to return
- * @param issue description of what was wrong with the request
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_bad_request (struct MHD_Connection *connection,
- enum TALER_ErrorCode ec,
- const char *issue);
-
-
-
-
-/**
- * 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
-TMH_RESPONSE_add_global_headers (struct MHD_Response *response);
-
-
-
-/**
- * Send a response indicating an external error.
- *
- * @param connection the MHD connection to use
- * @param ec error code to return
- * @param hint hint about the error's nature
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_external_error (struct MHD_Connection *connection,
- enum TALER_ErrorCode ec,
- const char *hint);
-
-
-
-
-/**
- * Send a response indicating a missing argument.
- *
- * @param connection the MHD connection to use
- * @param ec error code to return
- * @param param_name the parameter that is missing
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_arg_missing (struct MHD_Connection *connection,
- enum TALER_ErrorCode ec,
- const char *param_name);
-
-
-/**
- * Send a response indicating an invalid argument.
- *
- * @param connection the MHD connection to use
- * @param ec error code to return
- * @param param_name the parameter that is invalid
- * @return a MHD result code
- */
-int
-TMH_RESPONSE_reply_arg_invalid (struct MHD_Connection *connection,
- enum TALER_ErrorCode ec,
- const char *param_name);
-
-#endif
diff --git a/src/backend/anastasis-httpd_truth.c
b/src/backend/anastasis-httpd_truth.c
index 7e05c1a..77d515b 100644
--- a/src/backend/anastasis-httpd_truth.c
+++ b/src/backend/anastasis-httpd_truth.c
@@ -24,7 +24,7 @@
#include "anastasis-httpd.h"
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_rest_lib.h>
-#include "anastasis-httpd_responses.h"
+
/**
* @param connection the MHD connection to handle
@@ -41,6 +41,7 @@ AH_handler_truth_GET (struct MHD_Connection *connection,
return MHD_NO;
}
+
/**
* @param connection the MHD connection to handle
* @param con_cls the connection's closure
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: simplify backend via libtalermhd,
gnunet <=