aboutsummaryrefslogtreecommitdiff
path: root/src/exchange
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchange')
-rw-r--r--src/exchange/taler-exchange-httpd.c44
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_attest.c27
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_attest.h8
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_open.c15
4 files changed, 49 insertions, 45 deletions
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
index a45c9d2b..34f93879 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -389,10 +389,6 @@ handle_post_reserves (struct TEH_RequestContext *rc,
.handler = &TEH_handler_reserves_open
},
{
- .op = "attest",
- .handler = &TEH_handler_reserves_attest
- },
- {
.op = "close",
.handler = &TEH_handler_reserves_close
},
@@ -1055,27 +1051,6 @@ handle_post_auditors (struct TEH_RequestContext *rc,
/**
- * Handle a GET "/reserves/$RID/$XXX" request.
- *
- * @param rc request context
- * @param args array of additional options (length: 1, just the reserve_pub)
- * @return MHD result code
- */
-static MHD_RESULT
-handler_reserves_get3 (struct TEH_RequestContext *rc,
- const char *const args[3])
-{
- if (0 == strcmp (args[2],
- "attest"))
- return TEH_handler_reserves_get_attest (rc,
- args);
- GNUNET_break_op (0);
- return r404 (rc->connection,
- "/reserves/$RID/*");
-}
-
-
-/**
* Handle incoming HTTP request.
*
* @param cls closure for MHD daemon (unused)
@@ -1190,15 +1165,21 @@ handle_mhd_request (void *cls,
},
{
.url = "reserves",
+ .method = MHD_HTTP_METHOD_POST,
+ .handler.post = &handle_post_reserves,
+ .nargs = 2
+ },
+ {
+ .url = "reserves-attest",
.method = MHD_HTTP_METHOD_GET,
- .handler.get = &handler_reserves_get3,
- .nargs = 3
+ .handler.get = &TEH_handler_reserves_get_attest,
+ .nargs = 1
},
{
- .url = "reserves",
+ .url = "reserves-attest",
.method = MHD_HTTP_METHOD_POST,
- .handler.post = &handle_post_reserves,
- .nargs = 2
+ .handler.post = &TEH_handler_reserves_attest,
+ .nargs = 1
},
/* coins */
{
@@ -1441,7 +1422,8 @@ handle_mhd_request (void *cls,
continue;
found = true;
/* The URL is a match! What we now do depends on the method. */
- if (0 == strcasecmp (method, MHD_HTTP_METHOD_OPTIONS))
+ if (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_OPTIONS))
{
GNUNET_async_scope_restore (&old_scope);
return TALER_MHD_reply_cors_preflight (connection);
diff --git a/src/exchange/taler-exchange-httpd_reserves_attest.c b/src/exchange/taler-exchange-httpd_reserves_attest.c
index a740bb25..f88f2c30 100644
--- a/src/exchange/taler-exchange-httpd_reserves_attest.c
+++ b/src/exchange/taler-exchange-httpd_reserves_attest.c
@@ -48,7 +48,7 @@ struct ReserveAttestContext
/**
* Public key of the reserve the inquiry is about.
*/
- const struct TALER_ReservePublicKeyP *reserve_pub;
+ struct TALER_ReservePublicKeyP reserve_pub;
/**
* Hash of the payto URI of this reserve.
@@ -122,7 +122,7 @@ reply_reserve_attest_success (struct MHD_Connection *connection,
&TEH_keys_exchange_sign_,
now,
rhc->etime,
- rhc->reserve_pub,
+ &rhc->reserve_pub,
rhc->json_attest,
&exchange_pub,
&exchange_sig);
@@ -273,8 +273,8 @@ reserve_attest_transaction (void *cls,
MHD_RESULT
TEH_handler_reserves_attest (struct TEH_RequestContext *rc,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const json_t *root)
+ const json_t *root,
+ const char *const args[1])
{
struct ReserveAttestContext rsc = {
.etime = GNUNET_TIME_UNIT_FOREVER_TS
@@ -291,7 +291,18 @@ TEH_handler_reserves_attest (struct TEH_RequestContext *rc,
};
struct GNUNET_TIME_Timestamp now;
- rsc.reserve_pub = reserve_pub;
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[0],
+ strlen (args[0]),
+ &rsc.reserve_pub,
+ sizeof (rsc.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]);
+ }
{
enum GNUNET_GenericReturnValue res;
@@ -324,7 +335,7 @@ TEH_handler_reserves_attest (struct TEH_RequestContext *rc,
if (GNUNET_OK !=
TALER_wallet_reserve_attest_request_verify (rsc.timestamp,
rsc.details,
- reserve_pub,
+ &rsc.reserve_pub,
&rsc.reserve_sig))
{
GNUNET_break_op (0);
@@ -338,7 +349,7 @@ TEH_handler_reserves_attest (struct TEH_RequestContext *rc,
char *payto_uri;
payto_uri = TALER_reserve_make_payto (TEH_base_url,
- rsc.reserve_pub);
+ &rsc.reserve_pub);
TALER_payto_hash (payto_uri,
&rsc.h_payto);
GNUNET_free (payto_uri);
@@ -360,7 +371,7 @@ TEH_handler_reserves_attest (struct TEH_RequestContext *rc,
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_NOT_FOUND,
TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN,
- NULL);
+ args[0]);
}
if (TALER_EC_NONE != rsc.ec)
{
diff --git a/src/exchange/taler-exchange-httpd_reserves_attest.h b/src/exchange/taler-exchange-httpd_reserves_attest.h
index d5ec8fd7..66bbdf71 100644
--- a/src/exchange/taler-exchange-httpd_reserves_attest.h
+++ b/src/exchange/taler-exchange-httpd_reserves_attest.h
@@ -26,16 +26,16 @@
/**
- * Handle a POST "/reserves/$RID/attest" request.
+ * Handle a POST "/reserves-attest/$RID" request.
*
* @param rc request context
- * @param reserve_pub public key of the reserve
* @param root uploaded body from the client
+ * @param args args[0] has public key of the reserve
* @return MHD result code
*/
MHD_RESULT
TEH_handler_reserves_attest (struct TEH_RequestContext *rc,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const json_t *root);
+ const json_t *root,
+ const char *const args[1]);
#endif
diff --git a/src/exchange/taler-exchange-httpd_reserves_open.c b/src/exchange/taler-exchange-httpd_reserves_open.c
index 6ad2592f..ced291d7 100644
--- a/src/exchange/taler-exchange-httpd_reserves_open.c
+++ b/src/exchange/taler-exchange-httpd_reserves_open.c
@@ -108,6 +108,7 @@ struct ReserveOpenContext
* for the operation.
*/
bool no_funds;
+
};
@@ -122,6 +123,8 @@ static MHD_RESULT
reply_reserve_open_success (struct MHD_Connection *connection,
const struct ReserveOpenContext *rsc)
{
+ struct GNUNET_TIME_Timestamp now;
+ struct GNUNET_TIME_Timestamp re;
unsigned int status;
status = MHD_HTTP_OK;
@@ -129,11 +132,18 @@ reply_reserve_open_success (struct MHD_Connection *connection,
<,
rsc->desired_expiration))
status = MHD_HTTP_PAYMENT_REQUIRED;
+ now = GNUNET_TIME_timestamp_get ();
+ if (GNUNET_TIME_timestamp_cmp (rsc->reserve_expiration,
+ <,
+ now))
+ re = now;
+ else
+ re = rsc->reserve_expiration;
return TALER_MHD_REPLY_JSON_PACK (
connection,
status,
GNUNET_JSON_pack_timestamp ("reserve_expiration",
- rsc->reserve_expiration),
+ re),
TALER_JSON_pack_amount ("open_cost",
&rsc->open_cost));
}
@@ -234,7 +244,8 @@ reserve_open_transaction (void *cls,
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Do reserve open\n");
+ "Do reserve open with reserve payment of %s\n",
+ TALER_amount2s (&rsc->total));
qs = TEH_plugin->do_reserve_open (TEH_plugin->cls,
/* inputs */
rsc->reserve_pub,