From 253d220ea54d45557f33dd3a7affef0e79593218 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 30 Jun 2015 22:09:15 +0200 Subject: towards implementing #3851: /admin/add/incoming --- src/mint/Makefile.am | 1 + src/mint/taler-mint-httpd.c | 10 ++++++++++ src/mint/taler-mint-httpd_db.c | 24 ++++++++++++++++++++++++ src/mint/taler-mint-httpd_db.h | 19 +++++++++++++++++++ src/mint/taler-mint-httpd_parsing.h | 2 ++ src/mint/taler-mint-httpd_responses.c | 19 +++++++++++++++++++ src/mint/taler-mint-httpd_responses.h | 12 ++++++++++++ 7 files changed, 87 insertions(+) diff --git a/src/mint/Makefile.am b/src/mint/Makefile.am index 2cda4fac1..112dbbf18 100644 --- a/src/mint/Makefile.am +++ b/src/mint/Makefile.am @@ -11,6 +11,7 @@ taler_mint_httpd_SOURCES = \ taler-mint-httpd_parsing.c taler-mint-httpd_parsing.h \ taler-mint-httpd_responses.c taler-mint-httpd_responses.h \ taler-mint-httpd_mhd.c taler-mint-httpd_mhd.h \ + taler-mint-httpd_admin.c taler-mint-httpd_admin.h \ taler-mint-httpd_deposit.c taler-mint-httpd_deposit.h \ taler-mint-httpd_withdraw.c taler-mint-httpd_withdraw.h \ taler-mint-httpd_refresh.c taler-mint-httpd_refresh.h diff --git a/src/mint/taler-mint-httpd.c b/src/mint/taler-mint-httpd.c index 66d7e01e2..a0f1eca4b 100644 --- a/src/mint/taler-mint-httpd.c +++ b/src/mint/taler-mint-httpd.c @@ -28,6 +28,7 @@ #include #include "taler-mint-httpd_parsing.h" #include "taler-mint-httpd_mhd.h" +#include "taler-mint-httpd_admin.h" #include "taler-mint-httpd_deposit.h" #include "taler-mint-httpd_withdraw.h" #include "taler-mint-httpd_refresh.h" @@ -199,6 +200,15 @@ handle_mhd_request (void *cls, "Only GET is allowed", 0, &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, + /* FIXME: maybe conditionally compile these? */ + { "/admin/add/incoming", MHD_HTTP_METHOD_POST, "application/json", + NULL, 0, + &TMH_ADMIN_handler_admin_add_incoming, MHD_HTTP_OK }, + { "/admin/add/incoming", NULL, "text/plain", + "Only POST is allowed", 0, + &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, + + #if HAVE_DEVELOPER { "/test", MHD_HTTP_METHOD_POST, "application/json", NULL, 0, diff --git a/src/mint/taler-mint-httpd_db.c b/src/mint/taler-mint-httpd_db.c index 78a8d6f40..512ed9a48 100644 --- a/src/mint/taler-mint-httpd_db.c +++ b/src/mint/taler-mint-httpd_db.c @@ -1374,4 +1374,28 @@ TMH_DB_execute_refresh_link (struct MHD_Connection *connection, } +/** + * Add an incoming transaction to the database. Checks if the + * transaction is fresh (not a duplicate) and if so adds it to + * the database. + * + * @param connection the MHD connection to handle + * @param reserve_pub public key of the reserve + * @param amount amount to add to the reserve + * @param execution_time when did we receive the wire transfer + * @param wire details about the wire transfer + * @return MHD result code + */ +int +TMH_DB_execute_admin_add_incoming (struct MHD_Connection *connection, + const struct TALER_ReservePublicKeyP *reserve_pub, + const struct TALER_Amount *amount, + struct GNUNET_TIME_Absolute execution_time, + json_t *wire) +{ + GNUNET_break (0); // FIXME: #3851! + return MHD_NO; +} + + /* end of taler-mint-httpd_db.c */ diff --git a/src/mint/taler-mint-httpd_db.h b/src/mint/taler-mint-httpd_db.h index 56a4dd9cb..8a171153a 100644 --- a/src/mint/taler-mint-httpd_db.h +++ b/src/mint/taler-mint-httpd_db.h @@ -167,5 +167,24 @@ TMH_DB_execute_refresh_link (struct MHD_Connection *connection, const struct TALER_CoinSpendPublicKeyP *coin_pub); + +/** + * Add an incoming transaction to the database. + * + * @param connection the MHD connection to handle + * @param reserve_pub public key of the reserve + * @param amount amount to add to the reserve + * @param execution_time when did we receive the wire transfer + * @param wire details about the wire transfer + * @return MHD result code + */ +int +TMH_DB_execute_admin_add_incoming (struct MHD_Connection *connection, + const struct TALER_ReservePublicKeyP *reserve_pub, + const struct TALER_Amount *amount, + struct GNUNET_TIME_Absolute execution_time, + json_t *wire); + + #endif /* TALER_MINT_HTTPD_DB_H */ diff --git a/src/mint/taler-mint-httpd_parsing.h b/src/mint/taler-mint-httpd_parsing.h index 4714ab6a0..2439f39f9 100644 --- a/src/mint/taler-mint-httpd_parsing.h +++ b/src/mint/taler-mint-httpd_parsing.h @@ -134,6 +134,7 @@ enum TMH_PARSE_JsonNavigationCommand * Param: struct GNUNET_TIME_Absolute * */ TMH_PARSE_JNC_RET_TIME_ABSOLUTE + }; @@ -299,6 +300,7 @@ TMH_PARSE_release_data (struct TMH_PARSE_FieldSpecification *spec); */ #define TMH_PARSE_MEMBER_TIME_ABS(field,atime) { field, atime, sizeof(*atime), 0, TMH_PARSE_JNC_RET_TIME_ABSOLUTE, 0 } + /** * Generate line in parser specification indicating the end of the spec. */ diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c index ccc144e29..013cc19b8 100644 --- a/src/mint/taler-mint-httpd_responses.c +++ b/src/mint/taler-mint-httpd_responses.c @@ -171,6 +171,25 @@ TMH_RESPONSE_reply_arg_missing (struct MHD_Connection *connection, } +/** + * Send a response indicating permission denied. + * + * @param connection the MHD connection to use + * @param hint hint about why access was denied + * @return a MHD result code + */ +int +TMH_RESPONSE_reply_permission_denied (struct MHD_Connection *connection, + const char *hint) +{ + return TMH_RESPONSE_reply_json_pack (connection, + MHD_HTTP_FORBIDDEN, + "{s:s, s:s}", + "error", "permission denied", + "hint", hint); +} + + /** * Send a response indicating an internal error. * diff --git a/src/mint/taler-mint-httpd_responses.h b/src/mint/taler-mint-httpd_responses.h index 2ae06209d..1f8e1e44c 100644 --- a/src/mint/taler-mint-httpd_responses.h +++ b/src/mint/taler-mint-httpd_responses.h @@ -114,6 +114,18 @@ TMH_RESPONSE_reply_arg_missing (struct MHD_Connection *connection, const char *param_name); +/** + * Send a response indicating permission denied. + * + * @param connection the MHD connection to use + * @param hint hint about why access was denied + * @return a MHD result code + */ +int +TMH_RESPONSE_reply_permission_denied (struct MHD_Connection *connection, + const char *hint); + + /** * Send a response indicating an internal error. * -- cgit v1.2.3