more refactoring for libtalermhd
This commit is contained in:
parent
7c11a822ba
commit
cf6ba0c771
@ -291,7 +291,8 @@ verify_and_execute_deposit (struct MHD_Connection *connection,
|
||||
if (NULL == mks)
|
||||
{
|
||||
TALER_LOG_ERROR ("Lacking keys to operate\n");
|
||||
return TEH_RESPONSE_reply_internal_error (connection,
|
||||
return TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_EXCHANGE_BAD_CONFIGURATION,
|
||||
"no keys");
|
||||
}
|
||||
@ -465,7 +466,8 @@ TEH_DEPOSIT_handler_deposit (struct TEH_RequestHandler *rh,
|
||||
&emsg)))
|
||||
{
|
||||
GNUNET_JSON_parse_free (spec);
|
||||
res = TEH_RESPONSE_reply_external_error (connection,
|
||||
res = TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_BAD_REQUEST,
|
||||
ec,
|
||||
emsg);
|
||||
GNUNET_free (emsg);
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <gnunet/gnunet_util_lib.h>
|
||||
#include <microhttpd.h>
|
||||
#include "taler-exchange-httpd.h"
|
||||
#include "taler_error_codes.h"
|
||||
#include "taler_exchangedb_lib.h"
|
||||
|
||||
|
||||
|
@ -67,7 +67,7 @@ TEH_MHD_handler_static_response (struct TEH_RequestHandler *rh,
|
||||
GNUNET_break (0);
|
||||
return MHD_NO;
|
||||
}
|
||||
TEH_RESPONSE_add_global_headers (response);
|
||||
TALER_MHD_add_global_headers (response);
|
||||
if (NULL != rh->mime_type)
|
||||
(void) MHD_add_response_header (response,
|
||||
MHD_HTTP_HEADER_CONTENT_TYPE,
|
||||
@ -128,7 +128,7 @@ TEH_MHD_handler_send_json_pack_error (struct TEH_RequestHandler *rh,
|
||||
(void) connection_cls;
|
||||
(void) upload_data;
|
||||
(void) upload_data_size;
|
||||
return TEH_RESPONSE_reply_json_pack (connection,
|
||||
return TALER_MHD_reply_json_pack (connection,
|
||||
rh->response_code,
|
||||
"{s:s}",
|
||||
"error",
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <gnunet/gnunet_json_lib.h>
|
||||
#include <jansson.h>
|
||||
#include <microhttpd.h>
|
||||
#include "taler_mhd_lib.h"
|
||||
#include "taler_signatures.h"
|
||||
#include "taler-exchange-httpd_test.h"
|
||||
#include "taler-exchange-httpd_parsing.h"
|
||||
@ -88,7 +89,7 @@ TEH_TEST_handler_test_base32 (struct TEH_RequestHandler *rh,
|
||||
&hc);
|
||||
GNUNET_JSON_parse_free (spec);
|
||||
json_decref (json);
|
||||
return TEH_RESPONSE_reply_json_pack (connection,
|
||||
return TALER_MHD_reply_json_pack (connection,
|
||||
MHD_HTTP_OK,
|
||||
"{s:o}",
|
||||
"output",
|
||||
@ -172,7 +173,7 @@ TEH_TEST_handler_test_encrypt (struct TEH_RequestHandler *rh,
|
||||
in_ptr_size);
|
||||
GNUNET_free (out);
|
||||
GNUNET_JSON_parse_free (spec);
|
||||
return TEH_RESPONSE_reply_json_pack (connection,
|
||||
return TALER_MHD_reply_json_pack (connection,
|
||||
MHD_HTTP_OK,
|
||||
"{s:o}",
|
||||
"output",
|
||||
@ -237,7 +238,7 @@ TEH_TEST_handler_test_hkdf (struct TEH_RequestHandler *rh,
|
||||
NULL, 0));
|
||||
GNUNET_JSON_parse_free (spec);
|
||||
json = GNUNET_JSON_from_data_auto (&hc);
|
||||
return TEH_RESPONSE_reply_json_pack (connection,
|
||||
return TALER_MHD_reply_json_pack (connection,
|
||||
MHD_HTTP_OK,
|
||||
"{s:o}",
|
||||
"output",
|
||||
@ -298,12 +299,13 @@ TEH_TEST_handler_test_ecdhe (struct TEH_RequestHandler *rh,
|
||||
&hc))
|
||||
{
|
||||
GNUNET_JSON_parse_free (spec);
|
||||
return TEH_RESPONSE_reply_internal_error (connection,
|
||||
return TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_TEST_ECDH_ERROR,
|
||||
"Failed to perform ECDH");
|
||||
}
|
||||
GNUNET_JSON_parse_free (spec);
|
||||
return TEH_RESPONSE_reply_json_pack (connection,
|
||||
return TALER_MHD_reply_json_pack (connection,
|
||||
MHD_HTTP_OK,
|
||||
"{s:o}",
|
||||
"ecdh_hash",
|
||||
@ -369,7 +371,8 @@ TEH_TEST_handler_test_eddsa (struct TEH_RequestHandler *rh,
|
||||
&pub))
|
||||
{
|
||||
GNUNET_JSON_parse_free (spec);
|
||||
return TEH_RESPONSE_reply_signature_invalid (connection,
|
||||
return TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_FORBIDDEN,
|
||||
TALER_EC_TEST_EDDSA_INVALID,
|
||||
"eddsa_sig");
|
||||
}
|
||||
@ -382,14 +385,15 @@ TEH_TEST_handler_test_eddsa (struct TEH_RequestHandler *rh,
|
||||
&sig))
|
||||
{
|
||||
GNUNET_free (pk);
|
||||
return TEH_RESPONSE_reply_internal_error (connection,
|
||||
return TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_TEST_EDDSA_ERROR,
|
||||
"Failed to EdDSA-sign");
|
||||
}
|
||||
GNUNET_CRYPTO_eddsa_key_get_public (pk,
|
||||
&pub);
|
||||
GNUNET_free (pk);
|
||||
return TEH_RESPONSE_reply_json_pack (connection,
|
||||
return TALER_MHD_reply_json_pack (connection,
|
||||
MHD_HTTP_OK,
|
||||
"{s:o, s:o}",
|
||||
"eddsa_pub",
|
||||
@ -425,7 +429,8 @@ TEH_TEST_handler_test_rsa_get (struct TEH_RequestHandler *rh,
|
||||
if (NULL == rsa_pk)
|
||||
{
|
||||
GNUNET_break (0);
|
||||
return TEH_RESPONSE_reply_internal_error (connection,
|
||||
return TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_TEST_RSA_GEN_ERROR,
|
||||
"Failed to create RSA key");
|
||||
}
|
||||
@ -433,11 +438,12 @@ TEH_TEST_handler_test_rsa_get (struct TEH_RequestHandler *rh,
|
||||
if (NULL == pub)
|
||||
{
|
||||
GNUNET_break (0);
|
||||
return TEH_RESPONSE_reply_internal_error (connection,
|
||||
return TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_TEST_RSA_PUB_ERROR,
|
||||
"Failed to get public RSA key");
|
||||
}
|
||||
res = TEH_RESPONSE_reply_json_pack (connection,
|
||||
res = TALER_MHD_reply_json_pack (connection,
|
||||
MHD_HTTP_OK,
|
||||
"{s:o}",
|
||||
"rsa_pub",
|
||||
@ -497,7 +503,8 @@ TEH_TEST_handler_test_rsa_sign (struct TEH_RequestHandler *rh,
|
||||
{
|
||||
GNUNET_break (0);
|
||||
GNUNET_JSON_parse_free (spec);
|
||||
return TEH_RESPONSE_reply_internal_error (connection,
|
||||
return TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_TEST_RSA_GEN_ERROR,
|
||||
"Failed to create RSA key");
|
||||
}
|
||||
@ -508,12 +515,13 @@ TEH_TEST_handler_test_rsa_sign (struct TEH_RequestHandler *rh,
|
||||
{
|
||||
GNUNET_break (0);
|
||||
GNUNET_JSON_parse_free (spec);
|
||||
return TEH_RESPONSE_reply_internal_error (connection,
|
||||
return TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_TEST_RSA_SIGN_ERROR,
|
||||
"Failed to RSA-sign");
|
||||
}
|
||||
GNUNET_JSON_parse_free (spec);
|
||||
res = TEH_RESPONSE_reply_json_pack (connection,
|
||||
res = TALER_MHD_reply_json_pack (connection,
|
||||
MHD_HTTP_OK,
|
||||
"{s:o}",
|
||||
"rsa_blind_sig",
|
||||
@ -573,7 +581,7 @@ TEH_TEST_handler_test_transfer (struct TEH_RequestHandler *rh,
|
||||
TALER_link_reveal_transfer_secret (&trans_priv,
|
||||
&coin_pub,
|
||||
&secret);
|
||||
return TEH_RESPONSE_reply_json_pack (connection,
|
||||
return TALER_MHD_reply_json_pack (connection,
|
||||
MHD_HTTP_OK,
|
||||
"{s:o}",
|
||||
"secret",
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <jansson.h>
|
||||
#include <microhttpd.h>
|
||||
#include <pthread.h>
|
||||
#include "taler_mhd_lib.h"
|
||||
#include "taler_signatures.h"
|
||||
#include "taler-exchange-httpd_parsing.h"
|
||||
#include "taler-exchange-httpd_keystate.h"
|
||||
@ -42,7 +43,7 @@ static int
|
||||
reply_transfer_pending (struct MHD_Connection *connection,
|
||||
struct GNUNET_TIME_Absolute planned_exec_time)
|
||||
{
|
||||
return TEH_RESPONSE_reply_json_pack (connection,
|
||||
return TALER_MHD_reply_json_pack (connection,
|
||||
MHD_HTTP_ACCEPTED,
|
||||
"{s:o}",
|
||||
"execution_time",
|
||||
@ -92,11 +93,12 @@ reply_track_transaction (struct MHD_Connection *connection,
|
||||
&pub,
|
||||
&sig))
|
||||
{
|
||||
return TEH_RESPONSE_reply_internal_error (connection,
|
||||
return TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_EXCHANGE_BAD_CONFIGURATION,
|
||||
"no keys");
|
||||
}
|
||||
return TEH_RESPONSE_reply_json_pack (connection,
|
||||
return TALER_MHD_reply_json_pack (connection,
|
||||
MHD_HTTP_OK,
|
||||
"{s:o, s:o, s:o, s:o, s:o}",
|
||||
"wtid", GNUNET_JSON_from_data_auto (
|
||||
@ -249,15 +251,19 @@ track_transaction_transaction (void *cls,
|
||||
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
|
||||
{
|
||||
GNUNET_break (0);
|
||||
*mhd_ret = TEH_RESPONSE_reply_internal_db_error (connection,
|
||||
TALER_EC_TRACK_TRANSACTION_DB_FETCH_FAILED);
|
||||
*mhd_ret = TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_TRACK_TRANSACTION_DB_FETCH_FAILED,
|
||||
"failed to fetch transaction data");
|
||||
}
|
||||
return qs;
|
||||
}
|
||||
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
|
||||
{
|
||||
*mhd_ret = TEH_RESPONSE_reply_transaction_unknown (connection,
|
||||
TALER_EC_TRACK_TRANSACTION_NOT_FOUND);
|
||||
*mhd_ret = TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_NOT_FOUND,
|
||||
TALER_EC_TRACK_TRANSACTION_NOT_FOUND,
|
||||
"transaction unknown");
|
||||
return GNUNET_DB_STATUS_HARD_ERROR;
|
||||
}
|
||||
return qs;
|
||||
@ -295,7 +301,8 @@ check_and_handle_track_transaction_request (struct MHD_Connection *connection,
|
||||
&merchant_pub->eddsa_pub))
|
||||
{
|
||||
GNUNET_break_op (0);
|
||||
return TEH_RESPONSE_reply_signature_invalid (connection,
|
||||
return TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_FORBIDDEN,
|
||||
TALER_EC_TRACK_TRANSACTION_MERCHANT_SIGNATURE_INVALID,
|
||||
"merchant_sig");
|
||||
}
|
||||
@ -314,8 +321,10 @@ check_and_handle_track_transaction_request (struct MHD_Connection *connection,
|
||||
return reply_transfer_pending (connection,
|
||||
ctx.execution_time);
|
||||
if (GNUNET_SYSERR == ctx.pending)
|
||||
return TEH_RESPONSE_reply_internal_db_error (connection,
|
||||
TALER_EC_TRACK_TRANSACTION_DB_FEE_INCONSISTENT);
|
||||
return TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_TRACK_TRANSACTION_DB_FEE_INCONSISTENT,
|
||||
"fees are inconsistent");
|
||||
return reply_track_transaction (connection,
|
||||
&tps->h_contract_terms,
|
||||
&tps->h_wire,
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "taler-exchange-httpd_keystate.h"
|
||||
#include "taler-exchange-httpd_track_transfer.h"
|
||||
#include "taler-exchange-httpd_responses.h"
|
||||
#include "taler_mhd_lib.h"
|
||||
#include "taler_wire_lib.h"
|
||||
|
||||
|
||||
@ -148,12 +149,13 @@ reply_track_transfer_details (struct MHD_Connection *connection,
|
||||
&sig))
|
||||
{
|
||||
json_decref (deposits);
|
||||
return TEH_RESPONSE_reply_internal_error (connection,
|
||||
return TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_EXCHANGE_BAD_CONFIGURATION,
|
||||
"no keys");
|
||||
}
|
||||
|
||||
return TEH_RESPONSE_reply_json_pack (connection,
|
||||
return TALER_MHD_reply_json_pack (connection,
|
||||
MHD_HTTP_OK,
|
||||
"{s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o}",
|
||||
"total", TALER_JSON_from_amount (total),
|
||||
@ -396,21 +398,26 @@ track_transfer_transaction (void *cls,
|
||||
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
|
||||
{
|
||||
GNUNET_break (0);
|
||||
*mhd_ret = TEH_RESPONSE_reply_internal_db_error (connection,
|
||||
TALER_EC_TRACK_TRANSFER_DB_FETCH_FAILED);
|
||||
*mhd_ret = TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_TRACK_TRANSFER_DB_FETCH_FAILED,
|
||||
"failed to fetch transaction data");
|
||||
}
|
||||
return qs;
|
||||
}
|
||||
if (GNUNET_SYSERR == ctx->is_valid)
|
||||
{
|
||||
GNUNET_break (0);
|
||||
*mhd_ret = TEH_RESPONSE_reply_internal_db_error (connection,
|
||||
TALER_EC_TRACK_TRANSFER_DB_INCONSISTENT);
|
||||
*mhd_ret = TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_TRACK_TRANSFER_DB_INCONSISTENT,
|
||||
"exchange database internally inconsistent");
|
||||
return GNUNET_DB_STATUS_HARD_ERROR;
|
||||
}
|
||||
if (GNUNET_NO == ctx->is_valid)
|
||||
{
|
||||
*mhd_ret = TEH_RESPONSE_reply_arg_unknown (connection,
|
||||
*mhd_ret = TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_NOT_FOUND,
|
||||
TALER_EC_TRACK_TRANSFER_WTID_NOT_FOUND,
|
||||
"wtid");
|
||||
return GNUNET_DB_STATUS_HARD_ERROR;
|
||||
@ -430,8 +437,10 @@ track_transfer_transaction (void *cls,
|
||||
(GNUNET_DB_STATUS_SUCCESS_NO_RESULTS) )
|
||||
{
|
||||
GNUNET_break (0);
|
||||
*mhd_ret = TEH_RESPONSE_reply_internal_db_error (connection,
|
||||
TALER_EC_TRACK_TRANSFER_WIRE_FEE_NOT_FOUND);
|
||||
*mhd_ret = TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_TRACK_TRANSFER_WIRE_FEE_NOT_FOUND,
|
||||
"did not find wire fee");
|
||||
}
|
||||
return qs;
|
||||
}
|
||||
@ -441,8 +450,10 @@ track_transfer_transaction (void *cls,
|
||||
&ctx->wire_fee))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
*mhd_ret = TEH_RESPONSE_reply_internal_db_error (connection,
|
||||
TALER_EC_TRACK_TRANSFER_WIRE_FEE_INCONSISTENT);
|
||||
*mhd_ret = TALER_MHD_reply_with_error (connection,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
TALER_EC_TRACK_TRANSFER_WIRE_FEE_INCONSISTENT,
|
||||
"could not subtract wire fee");
|
||||
return GNUNET_DB_STATUS_HARD_ERROR;
|
||||
}
|
||||
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "taler-exchange-httpd_validation.h"
|
||||
#include "taler-exchange-httpd_wire.h"
|
||||
#include "taler_json_lib.h"
|
||||
#include "taler_mhd_lib.h"
|
||||
#include <jansson.h>
|
||||
|
||||
/**
|
||||
@ -140,7 +141,7 @@ TEH_WIRE_handler_wire (struct TEH_RequestHandler *rh,
|
||||
(void) upload_data;
|
||||
(void) upload_data_size;
|
||||
GNUNET_assert (NULL != wire_methods);
|
||||
return TEH_RESPONSE_reply_json (connection,
|
||||
return TALER_MHD_reply_json (connection,
|
||||
wire_methods,
|
||||
MHD_HTTP_OK);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user