[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-merchant] 128/277: more work on tipping implementation
From: |
gnunet |
Subject: |
[taler-merchant] 128/277: more work on tipping implementation |
Date: |
Sun, 05 Jul 2020 20:50:41 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository merchant.
commit e6cd3507114e625f89d8d2383fd7a88b21d22b97
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed May 20 17:34:55 2020 +0200
more work on tipping implementation
---
src/backend/taler-merchant-httpd.c | 8 ++--
.../taler-merchant-httpd_post-tips-ID-pickup.c | 52 ++++++++------------
.../taler-merchant-httpd_post-tips-ID-pickup.h | 48 +++++--------------
... => taler-merchant-httpd_private-get-tips-ID.c} | 56 +++++++---------------
.../taler-merchant-httpd_private-get-tips-ID.h | 41 ++++++++++++++++
...-httpd_private-post-reserves-ID-authorize-tip.c | 8 ++--
...-httpd_private-post-reserves-ID-authorize-tip.h | 8 ++--
7 files changed, 102 insertions(+), 119 deletions(-)
diff --git a/src/backend/taler-merchant-httpd.c
b/src/backend/taler-merchant-httpd.c
index 7f06390..b2577bd 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -40,6 +40,7 @@
#include "taler-merchant-httpd_private-get-orders.h"
// #include "taler-merchant-httpd_private-get-orders-ID.h"
#include "taler-merchant-httpd_private-get-reserves.h"
+#include "taler-merchant-httpd_private-get-tips-ID.h"
#include "taler-merchant-httpd_private-get-transfers.h"
#include "taler-merchant-httpd_private-patch-instances-ID.h"
#include "taler-merchant-httpd_private-patch-products-ID.h"
@@ -858,12 +859,11 @@ url_handler (void *cls,
.method = MHD_HTTP_METHOD_POST,
.handler = &TMH_private_post_reserves_ID_authorize_tip
},
- /* POST /reserves/authorize-tip: */
+ /* POST /tips: */
{
- .url_prefix = "/reserves",
- .url_suffix = "authorize-tip",
+ .url_prefix = "/tips",
.method = MHD_HTTP_METHOD_POST,
- .handler = &TMH_private_post_reserves_authorize_tip
+ .handler = &TMH_private_post_tips
},
/* GET /reserves: */
{
diff --git a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c
b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c
index 42066e3..4425834 100644
--- a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c
+++ b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c
@@ -14,8 +14,8 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file backend/taler-merchant-httpd_tip-pickup.c
- * @brief implementation of /tip-pickup handler
+ * @file backend/taler-merchant-httpd_post-tips-ID-pickup.c
+ * @brief implementation of a POST /tips/ID/pickup handler
* @author Christian Grothoff
*/
#include "platform.h"
@@ -30,28 +30,30 @@
/**
- * Manages a GET /tip-pickup call, checking that the tip is authorized,
- * and if so, returning the withdrawal permissions.
+ * We are shutting down, force resuming all suspended pickup operations.
+ */
+void
+TMH_force_tip_pickup_resume ()
+{
+ // FIXME!
+}
+
+
+/**
+ * Manages a POST /tips/$ID/pickup call, checking that the tip is authorized,
+ * and if so, returning the blind signatures.
*
* @param rh context of the handler
* @param connection the MHD connection to handle
- * @param[in,out] connection_cls the connection's closure (can be updated)
- * @param upload_data upload data
- * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
- * @param mi merchant backend instance, never NULL
+ * @param[in,out] hc context with further information about the request
* @return MHD result code
*/
MHD_RESULT
-MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size,
- struct MerchantInstance *mi)
+TMH_post_tips_ID_pickup (const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc)
{
- const char *tip_id_str;
char *exchange_url;
- json_t *extra;
struct GNUNET_HashCode tip_id;
struct TALER_Amount tip_amount;
struct TALER_Amount tip_amount_left;
@@ -60,22 +62,9 @@ MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh,
MHD_RESULT ret;
enum GNUNET_DB_QueryStatus qs;
- tip_id_str = MHD_lookup_connection_value (connection,
- MHD_GET_ARGUMENT_KIND,
- "tip_id");
-
- if (NULL == tip_id_str)
- {
- /* tip_id is required but missing */
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_PARAMETER_MISSING,
- "tip_id required");
- }
-
+ GNUNET_assert (NULL != hc->infix);
if (GNUNET_OK !=
- GNUNET_CRYPTO_hash_from_string (tip_id_str,
+ GNUNET_CRYPTO_hash_from_string (hc->infix,
&tip_id))
{
/* tip_id has wrong encoding */
@@ -87,6 +76,7 @@ MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh,
}
db->preflight (db->cls);
+ // FIXME: logic here is completely bonkers!
qs = db->lookup_tip_by_id (db->cls,
&tip_id,
&exchange_url,
diff --git a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.h
b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.h
index 6fdba31..f8ac486 100644
--- a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.h
+++ b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.h
@@ -14,12 +14,12 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file backend/taler-merchant-httpd_tip-pickup.h
- * @brief headers for /tip-pickup handler
+ * @file backend/taler-merchant-httpd_post-tips-ID-pickup.h
+ * @brief headers for POST /tips/ID/pickup handler
* @author Christian Grothoff
*/
-#ifndef TALER_MERCHANT_HTTPD_TIP_PICKUP_H
-#define TALER_MERCHANT_HTTPD_TIP_PICKUP_H
+#ifndef TALER_MERCHANT_HTTPD_POST_TIPS_ID_PICKUP_H
+#define TALER_MERCHANT_HTTPD_POST_TIPS_ID_PICKUP_H
#include <microhttpd.h>
#include "taler-merchant-httpd.h"
@@ -28,48 +28,22 @@
* We are shutting down, force resuming all suspended pickup operations.
*/
void
-MH_force_tip_pickup_resume (void);
+TMH_force_tip_pickup_resume (void);
/**
- * Manages a POST /tip-pickup call, checking that the tip is authorized,
- * and if so, returning the withdrawal permissions.
+ * Manages a POST /tips/$ID/pickup call, checking that the tip is authorized,
+ * and if so, returning the blind signatures.
*
* @param rh context of the handler
* @param connection the MHD connection to handle
- * @param[in,out] connection_cls the connection's closure (can be updated)
- * @param upload_data upload data
- * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
-* @param mi merchant backend instance, never NULL
+ * @param[in,out] hc context with further information about the request
* @return MHD result code
*/
MHD_RESULT
-MH_handler_tip_pickup (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size,
- struct MerchantInstance *mi);
-
-
-/**
- * Manages a GET /tip-pickup call.
- *
- * @param rh context of the handler
- * @param connection the MHD connection to handle
- * @param[in,out] connection_cls the connection's closure (can be updated)
- * @param upload_data upload data
- * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
- * @param mi merchant backend instance, never NULL
- * @return MHD result code
- */
-MHD_RESULT
-MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size,
- struct MerchantInstance *mi);
+TMH_post_tips_ID_pickup (const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc);
#endif
diff --git a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c
b/src/backend/taler-merchant-httpd_private-get-tips-ID.c
similarity index 65%
copy from src/backend/taler-merchant-httpd_post-tips-ID-pickup.c
copy to src/backend/taler-merchant-httpd_private-get-tips-ID.c
index 42066e3..f186363 100644
--- a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c
+++ b/src/backend/taler-merchant-httpd_private-get-tips-ID.c
@@ -14,8 +14,8 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file backend/taler-merchant-httpd_tip-pickup.c
- * @brief implementation of /tip-pickup handler
+ * @file backend/taler-merchant-httpd_get-tips-ID.c
+ * @brief implementation of a GET /tips/ID handler
* @author Christian Grothoff
*/
#include "platform.h"
@@ -30,28 +30,19 @@
/**
- * Manages a GET /tip-pickup call, checking that the tip is authorized,
- * and if so, returning the withdrawal permissions.
+ * Manages a GET /tips/$ID call, returning the status of a tip.
*
* @param rh context of the handler
* @param connection the MHD connection to handle
- * @param[in,out] connection_cls the connection's closure (can be updated)
- * @param upload_data upload data
- * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
- * @param mi merchant backend instance, never NULL
+ * @param[in,out] hc context with further information about the request
* @return MHD result code
*/
MHD_RESULT
-MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size,
- struct MerchantInstance *mi)
+TMH_private_get_tips_ID (const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc)
{
- const char *tip_id_str;
char *exchange_url;
- json_t *extra;
struct GNUNET_HashCode tip_id;
struct TALER_Amount tip_amount;
struct TALER_Amount tip_amount_left;
@@ -60,22 +51,9 @@ MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh,
MHD_RESULT ret;
enum GNUNET_DB_QueryStatus qs;
- tip_id_str = MHD_lookup_connection_value (connection,
- MHD_GET_ARGUMENT_KIND,
- "tip_id");
-
- if (NULL == tip_id_str)
- {
- /* tip_id is required but missing */
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_PARAMETER_MISSING,
- "tip_id required");
- }
-
+ GNUNET_assert (NULL != hc->infix);
if (GNUNET_OK !=
- GNUNET_CRYPTO_hash_from_string (tip_id_str,
+ GNUNET_CRYPTO_hash_from_string (hc->infix,
&tip_id))
{
/* tip_id has wrong encoding */
@@ -87,6 +65,7 @@ MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh,
}
db->preflight (db->cls);
+ // FIXME: logic here is completely bonkers!
qs = db->lookup_tip_by_id (db->cls,
&tip_id,
&exchange_url,
@@ -132,15 +111,14 @@ MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh,
ret = TALER_MHD_reply_json_pack (
connection,
MHD_HTTP_OK,
- "{s:s, s:o, s:o, s:o, s:o, s:o}",
- "exchange_url", exchange_url,
- "amount", TALER_JSON_from_amount (&tip_amount),
- "amount_left", TALER_JSON_from_amount (&tip_amount_left),
- "stamp_created", GNUNET_JSON_from_time_abs (timestamp),
- "stamp_expire", GNUNET_JSON_from_time_abs (timestamp_expire),
- "extra", extra);
+ "{s:s, s:o, s:o, s:o, s:o, s:o?}",
+ "reason", reason,
+ "total_authorized", TALER_JSON_from_amount (&tip_amount),
+ "total_picked_up", TALER_JSON_from_amount (&tip_amount_left),
+ "reserve_pub", GNUNET_JSON_from_data_auto (&reserve_pub),
+ "expiration", GNUNET_JSON_from_time_abs (timestamp_expire),
+ "pickups", pickups);
GNUNET_free (exchange_url);
- json_decref (extra);
return ret;
}
diff --git a/src/backend/taler-merchant-httpd_private-get-tips-ID.h
b/src/backend/taler-merchant-httpd_private-get-tips-ID.h
new file mode 100644
index 0000000..bc59469
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_private-get-tips-ID.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ (C) 2017 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file backend/taler-merchant-httpd_get-tips-ID.h
+ * @brief headers for GET /tips/ID handler
+ * @author Christian Grothoff
+ */
+#ifndef TALER_MERCHANT_HTTPD_GET_TIPS_ID_H
+#define TALER_MERCHANT_HTTPD_GET_TIPS_ID_H
+#include <microhttpd.h>
+#include "taler-merchant-httpd.h"
+
+
+/**
+ * Manages a GET /tips/$ID call, returning the status of the tip.
+ *
+ * @param rh context of the handler
+ * @param connection the MHD connection to handle
+ * @param[in,out] hc context with further information about the request
+ * @return MHD result code
+ */
+MHD_RESULT
+TMH_private_get_tips_ID (const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc);
+
+
+#endif
diff --git
a/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c
b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c
index 9193669..0b363cf 100644
--- a/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c
+++ b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c
@@ -199,7 +199,7 @@ TMH_private_post_reserves_ID_authorize_tip (const struct
TMH_RequestHandler *rh,
/**
- * Handle a "/reserves/tip-authorize" request.
+ * Handle a POST "/tips" request.
* Here the client does not specify the reserve public key, so we
* are free to pick "any" available reserve.
*
@@ -209,9 +209,9 @@ TMH_private_post_reserves_ID_authorize_tip (const struct
TMH_RequestHandler *rh,
* @return MHD result code
*/
MHD_RESULT
-TMH_private_post_reserves_authorize_tip (const struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- struct TMH_HandlerContext *hc)
+TMH_private_post_tips (const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc)
{
return authorize_tip (rh,
connection,
diff --git
a/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.h
b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.h
index 2df5529..297a53d 100644
--- a/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.h
+++ b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.h
@@ -39,7 +39,7 @@ TMH_private_post_reserves_ID_authorize_tip (const struct
TMH_RequestHandler *rh,
/**
- * Handle a "/reserves/tip-authorize" request.
+ * Handle a POST "/tips" request.
* Here the client does not specify the reserve public key, so we
* are free to pick "any" available reserve.
*
@@ -49,9 +49,9 @@ TMH_private_post_reserves_ID_authorize_tip (const struct
TMH_RequestHandler *rh,
* @return MHD result code
*/
MHD_RESULT
-TMH_private_post_reserves_authorize_tip (const struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- struct TMH_HandlerContext *hc);
+TMH_private_post_tips (const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc);
#endif
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-merchant] 129/277: fixed coding style in db tests and double callbacks in lookup_instances, (continued)
- [taler-merchant] 129/277: fixed coding style in db tests and double callbacks in lookup_instances, gnunet, 2020/07/05
- [taler-merchant] 131/277: towards POST tips pickup impl, gnunet, 2020/07/05
- [taler-merchant] 120/277: implement insert_reserve, gnunet, 2020/07/05
- [taler-merchant] 125/277: more work on GET /reserves logic, gnunet, 2020/07/05
- [taler-merchant] 99/277: more work on post /transfers and the like, gnunet, 2020/07/05
- [taler-merchant] 93/277: updates, gnunet, 2020/07/05
- [taler-merchant] 100/277: more work on POST /transfer, gnunet, 2020/07/05
- [taler-merchant] 121/277: Merge branch 'master' into protocolV1, gnunet, 2020/07/05
- [taler-merchant] 126/277: more instance and product related tests, gnunet, 2020/07/05
- [taler-merchant] 124/277: expanding DB API, gnunet, 2020/07/05
- [taler-merchant] 128/277: more work on tipping implementation,
gnunet <=
- [taler-merchant] 132/277: Merge branch 'protocolV1' of git+ssh://git.taler.net/merchant into protocolV1, gnunet, 2020/07/05
- [taler-merchant] 136/277: add GET /tips/ID handler, gnunet, 2020/07/05
- [taler-merchant] 138/277: wrote some db tests for orders, gnunet, 2020/07/05
- [taler-merchant] 123/277: added tests for instance creation and lookup, gnunet, 2020/07/05
- [taler-merchant] 127/277: implement reserve deletion, gnunet, 2020/07/05
- [taler-merchant] 135/277: fix ftbfs, gnunet, 2020/07/05
- [taler-merchant] 130/277: added more instance tests and fixed mem leaks/code style in tests, gnunet, 2020/07/05
- [taler-merchant] 133/277: fix ftbfs, gnunet, 2020/07/05
- [taler-merchant] 139/277: wrote db tests for accounts, gnunet, 2020/07/05
- [taler-merchant] 140/277: DB prep work, gnunet, 2020/07/05