summaryrefslogtreecommitdiff
path: root/src/exchange
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-09-18 22:11:28 +0200
committerChristian Grothoff <christian@grothoff.org>2023-09-18 22:11:28 +0200
commitdfe576f9379954ab8164da7521bef930d3af3948 (patch)
treeb7fffe7cfc8767df6b672ccfd08614b550352f1c /src/exchange
parent12cff1b4439ab5dcc26fcf79e19518ae1bdce069 (diff)
downloadexchange-dfe576f9379954ab8164da7521bef930d3af3948.tar.gz
exchange-dfe576f9379954ab8164da7521bef930d3af3948.tar.bz2
exchange-dfe576f9379954ab8164da7521bef930d3af3948.zip
more work on new history logic
Diffstat (limited to 'src/exchange')
-rw-r--r--src/exchange/taler-exchange-httpd.c110
-rw-r--r--src/exchange/taler-exchange-httpd_coins_get.h2
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_get.c20
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_get.h9
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_history.c52
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_history.h12
-rw-r--r--src/exchange/taler-exchange-httpd_responses.h2
7 files changed, 135 insertions, 72 deletions
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
index d059e7430..7129f6d13 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -402,14 +402,17 @@ handle_get_coins (struct TEH_RequestContext *rc,
TALER_EC_EXCHANGE_GENERIC_COINS_INVALID_COIN_PUB,
args[0]);
}
-
- if (NULL == args[1])
- return TEH_handler_coins_get (rc,
- &coin_pub);
- if (0 == strcmp (args[1],
- "link"))
- return TEH_handler_link (rc,
- &coin_pub);
+ if (NULL != args[1])
+ {
+ if (0 == strcmp (args[1],
+ "history"))
+ return TEH_handler_coins_get (rc,
+ &coin_pub);
+ if (0 == strcmp (args[1],
+ "link"))
+ return TEH_handler_link (rc,
+ &coin_pub);
+ }
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_NOT_FOUND,
TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
@@ -731,11 +734,6 @@ handle_post_reserves (struct TEH_RequestContext *rc,
.op = "withdraw",
.handler = &TEH_handler_withdraw
},
- // FIXME: change to GET!
- {
- .op = "history",
- .handler = &TEH_handler_reserves_history
- },
{
.op = "purse",
.handler = &TEH_handler_reserves_purse
@@ -778,6 +776,87 @@ handle_post_reserves (struct TEH_RequestContext *rc,
/**
+ * Signature of functions that handle GET operations on reserves.
+ *
+ * @param rc request context
+ * @param reserve_pub the public key of the reserve
+ * @return MHD result code
+ */
+typedef MHD_RESULT
+(*ReserveGetOpHandler)(struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub);
+
+
+/**
+ * Handle a "GET /reserves/$RESERVE_PUB[/$OP]" request. Parses the "reserve_pub"
+ * EdDSA key of the reserve and demultiplexes based on $OP.
+ *
+ * @param rc request context
+ * @param args NULL-terminated array of additional options, zero, one or two
+ * @return MHD result code
+ */
+static MHD_RESULT
+handle_get_reserves (struct TEH_RequestContext *rc,
+ const char *const args[])
+{
+ struct TALER_ReservePublicKeyP reserve_pub;
+ static const struct
+ {
+ /**
+ * Name of the operation (args[1]), optional
+ */
+ const char *op;
+
+ /**
+ * Function to call to perform the operation.
+ */
+ ReserveGetOpHandler handler;
+
+ } h[] = {
+ {
+ .op = NULL,
+ .handler = &TEH_handler_reserves_get
+ },
+ {
+ .op = "history",
+ .handler = &TEH_handler_reserves_history
+ },
+ {
+ .op = NULL,
+ .handler = NULL
+ },
+ };
+
+ if ( (NULL == args[0]) ||
+ (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[0],
+ strlen (args[0]),
+ &reserve_pub,
+ sizeof (reserve_pub))) )
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_RESERVE_PUB_MALFORMED,
+ args[0]);
+ }
+ for (unsigned int i = 0; NULL != h[i].handler; i++)
+ {
+ if ( ( (NULL == args[1]) &&
+ (NULL == h[i].op) ) ||
+ ( (NULL != args[1]) &&
+ (NULL != h[i].op) &&
+ (0 == strcmp (h[i].op,
+ args[1])) ) )
+ return h[i].handler (rc,
+ &reserve_pub);
+ }
+ return r404 (rc->connection,
+ args[1]);
+}
+
+
+/**
* Signature of functions that handle operations on purses.
*
* @param connection HTTP request handle
@@ -1546,8 +1625,9 @@ handle_mhd_request (void *cls,
{
.url = "reserves",
.method = MHD_HTTP_METHOD_GET,
- .handler.get = &TEH_handler_reserves_get,
- .nargs = 1
+ .handler.get = &handle_get_reserves,
+ .nargs = 2,
+ .nargs_is_upper_bound = true
},
{
.url = "reserves",
diff --git a/src/exchange/taler-exchange-httpd_coins_get.h b/src/exchange/taler-exchange-httpd_coins_get.h
index 712269c3b..90405b55d 100644
--- a/src/exchange/taler-exchange-httpd_coins_get.h
+++ b/src/exchange/taler-exchange-httpd_coins_get.h
@@ -37,7 +37,7 @@ TEH_reserves_get_cleanup (void);
/**
- * Handle a GET "/coins/$COIN_PUB" request. Parses the
+ * Handle a GET "/coins/$COIN_PUB/history" request. Parses the
* given "coins_pub" in @a args (which should contain the
* EdDSA public key of a reserve) and then respond with the
* transaction history of the coin.
diff --git a/src/exchange/taler-exchange-httpd_reserves_get.c b/src/exchange/taler-exchange-httpd_reserves_get.c
index a46886ef4..0775a4c65 100644
--- a/src/exchange/taler-exchange-httpd_reserves_get.c
+++ b/src/exchange/taler-exchange-httpd_reserves_get.c
@@ -170,8 +170,9 @@ db_event_cb (void *cls,
MHD_RESULT
-TEH_handler_reserves_get (struct TEH_RequestContext *rc,
- const char *const args[1])
+TEH_handler_reserves_get (
+ struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub)
{
struct ReservePoller *rp = rc->rh_ctx;
@@ -185,18 +186,7 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc,
GNUNET_CONTAINER_DLL_insert (rp_head,
rp_tail,
rp);
- if (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (args[0],
- strlen (args[0]),
- &rp->reserve_pub,
- sizeof (rp->reserve_pub)))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_RESERVE_PUB_MALFORMED,
- args[0]);
- }
+ rp->reserve_pub = *reserve_pub;
TALER_MHD_parse_request_timeout (rc->connection,
&rp->timeout);
}
@@ -254,7 +244,7 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc,
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_NOT_FOUND,
TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN,
- args[0]);
+ NULL);
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Long-polling on reserve for %s\n",
diff --git a/src/exchange/taler-exchange-httpd_reserves_get.h b/src/exchange/taler-exchange-httpd_reserves_get.h
index 30c6559f6..6c453d0cd 100644
--- a/src/exchange/taler-exchange-httpd_reserves_get.h
+++ b/src/exchange/taler-exchange-httpd_reserves_get.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
+ Copyright (C) 2014-2023 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
@@ -43,11 +43,12 @@ TEH_reserves_get_cleanup (void);
* status of the reserve.
*
* @param rc request context
- * @param args array of additional options (length: 1, just the reserve_pub)
+ * @param reserve_pub public key of the reserve
* @return MHD result code
*/
MHD_RESULT
-TEH_handler_reserves_get (struct TEH_RequestContext *rc,
- const char *const args[1]);
+TEH_handler_reserves_get (
+ struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub);
#endif
diff --git a/src/exchange/taler-exchange-httpd_reserves_history.c b/src/exchange/taler-exchange-httpd_reserves_history.c
index 1bf73cb25..0c692c8fd 100644
--- a/src/exchange/taler-exchange-httpd_reserves_history.c
+++ b/src/exchange/taler-exchange-httpd_reserves_history.c
@@ -23,7 +23,6 @@
#include "platform.h"
#include <gnunet/gnunet_util_lib.h>
#include <jansson.h>
-#include "taler_mhd_lib.h"
#include "taler_json_lib.h"
#include "taler_dbevents.h"
#include "taler-exchange-httpd_keys.h"
@@ -54,6 +53,11 @@ struct ReserveHistoryContext
struct TALER_EXCHANGEDB_ReserveHistory *rh;
/**
+ * Requested startin offset for the reserve history.
+ */
+ uint64_t start_off;
+
+ /**
* Current reserve balance.
*/
struct TALER_Amount balance;
@@ -415,7 +419,7 @@ reserve_history_transaction (void *cls,
qs = TEH_plugin->get_reserve_history (TEH_plugin->cls,
rsc->reserve_pub,
- 0,
+ rsc->start_off,
&rsc->balance,
&rsc->rh);
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
@@ -432,40 +436,28 @@ reserve_history_transaction (void *cls,
MHD_RESULT
-TEH_handler_reserves_history (struct TEH_RequestContext *rc,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const json_t *root)
+TEH_handler_reserves_history (
+ struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub)
{
- struct ReserveHistoryContext rsc;
+ struct ReserveHistoryContext rsc = {
+ .reserve_pub = reserve_pub
+ };
MHD_RESULT mhd_ret;
- uint64_t start_off = 0;
struct TALER_ReserveSignatureP reserve_sig;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("reserve_sig",
- &reserve_sig),
- GNUNET_JSON_spec_end ()
- };
-
+ bool required = true;
+
+ TALER_MHD_parse_request_header_auto (rc->connection,
+ TALER_RESERVE_HISTORY_SIGNATURE_HEADER,
+ &reserve_sig,
+ required);
+ TALER_MHD_parse_request_number (rc->connection,
+ "start",
+ &rsc.start_off);
rsc.reserve_pub = reserve_pub;
- {
- enum GNUNET_GenericReturnValue res;
- res = TALER_MHD_parse_json_data (rc->connection,
- root,
- spec);
- if (GNUNET_SYSERR == res)
- {
- GNUNET_break (0);
- return MHD_NO; /* hard failure */
- }
- if (GNUNET_NO == res)
- {
- GNUNET_break_op (0);
- return MHD_YES; /* failure */
- }
- }
if (GNUNET_OK !=
- TALER_wallet_reserve_history_verify (start_off,
+ TALER_wallet_reserve_history_verify (rsc.start_off,
reserve_pub,
&reserve_sig))
{
diff --git a/src/exchange/taler-exchange-httpd_reserves_history.h b/src/exchange/taler-exchange-httpd_reserves_history.h
index 9a2a93782..e1bd7ae1b 100644
--- a/src/exchange/taler-exchange-httpd_reserves_history.h
+++ b/src/exchange/taler-exchange-httpd_reserves_history.h
@@ -15,7 +15,7 @@
*/
/**
* @file taler-exchange-httpd_reserves_history.h
- * @brief Handle /reserves/$RESERVE_PUB HISTORY requests
+ * @brief Handle /reserves/$RESERVE_PUB/history requests
* @author Florian Dold
* @author Benedikt Mueller
* @author Christian Grothoff
@@ -24,20 +24,20 @@
#define TALER_EXCHANGE_HTTPD_RESERVES_HISTORY_H
#include <microhttpd.h>
+#include "taler_mhd_lib.h"
#include "taler-exchange-httpd.h"
/**
- * Handle a POST "/reserves/$RID/history" request.
+ * Handle a GET "/reserves/$RID/history" request.
*
* @param rc request context
* @param reserve_pub public key of the reserve
- * @param root uploaded body from the client
* @return MHD result code
*/
MHD_RESULT
-TEH_handler_reserves_history (struct TEH_RequestContext *rc,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const json_t *root);
+TEH_handler_reserves_history (
+ struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub);
#endif
diff --git a/src/exchange/taler-exchange-httpd_responses.h b/src/exchange/taler-exchange-httpd_responses.h
index 3e55f0b07..877e8878f 100644
--- a/src/exchange/taler-exchange-httpd_responses.h
+++ b/src/exchange/taler-exchange-httpd_responses.h
@@ -24,13 +24,13 @@
*/
#ifndef TALER_EXCHANGE_HTTPD_RESPONSES_H
#define TALER_EXCHANGE_HTTPD_RESPONSES_H
+
#include <gnunet/gnunet_util_lib.h>
#include <jansson.h>
#include <microhttpd.h>
#include "taler_error_codes.h"
#include "taler-exchange-httpd.h"
#include "taler-exchange-httpd_db.h"
-#include <gnunet/gnunet_mhd_compat.h>
/**