summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-10-25 19:17:20 +0100
committerChristian Grothoff <christian@grothoff.org>2020-10-25 19:17:20 +0100
commit5600b3868430a6d4baae628dc18f7e4ff75b12fe (patch)
treea721fd88f76666ef6643af5b1f9e69fcaae8a1bf
parent1a1760c6fe08d3cf132b2bf7a45f9c9fe53a6ef2 (diff)
downloadmerchant-5600b3868430a6d4baae628dc18f7e4ff75b12fe.tar.gz
merchant-5600b3868430a6d4baae628dc18f7e4ff75b12fe.tar.bz2
merchant-5600b3868430a6d4baae628dc18f7e4ff75b12fe.zip
work on #6525
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-claim.c27
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-pay.c47
2 files changed, 19 insertions, 55 deletions
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
index 60aadf4b..0c5da004 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
@@ -163,30 +163,15 @@ TMH_post_orders_ID_claim (const struct TMH_RequestHandler *rh,
const char *nonce;
enum GNUNET_DB_QueryStatus qs;
json_t *contract_terms;
- struct TALER_ClaimTokenP claim_token;
+ struct TALER_ClaimTokenP claim_token = { 0 };
{
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_string ("nonce",
&nonce),
- GNUNET_JSON_spec_end ()
- };
- enum GNUNET_GenericReturnValue res;
-
- res = TALER_MHD_parse_json_data (connection,
- hc->request_body,
- spec);
- if (GNUNET_OK != res)
- return (GNUNET_NO == res)
- ? MHD_YES
- : MHD_NO;
- }
- if (NULL != json_object_get (hc->request_body,
- "token"))
- {
- struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_fixed_auto ("token",
- &claim_token),
+ &claim_token)),
GNUNET_JSON_spec_end ()
};
enum GNUNET_GenericReturnValue res;
@@ -199,12 +184,6 @@ TMH_post_orders_ID_claim (const struct TMH_RequestHandler *rh,
? MHD_YES
: MHD_NO;
}
- else
- {
- memset (&claim_token,
- 0,
- sizeof (claim_token));
- }
contract_terms = NULL;
for (unsigned int i = 0; i<MAX_RETRIES; i++)
{
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
index f33aa9da..1f611e9d 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
@@ -1280,6 +1280,7 @@ check_payment_sufficient (struct PayContext *pc)
return true;
}
+
static void
begin_transaction (struct PayContext *pc)
{
@@ -1519,10 +1520,14 @@ parse_pay (struct MHD_Connection *connection,
{
/* First, parse request */
{
+ const char *session_id = NULL;
json_t *coins;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_json ("coins",
&coins),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("session_id",
+ &session_id)),
GNUNET_JSON_spec_end ()
};
@@ -1539,6 +1544,17 @@ parse_pay (struct MHD_Connection *connection,
}
}
+ /* copy session ID (if set) */
+ if (NULL != session_id)
+ {
+ pc->session_id = GNUNET_strdup (session_id);
+ }
+ else
+ {
+ /* use empty string as default if client didn't specify it */
+ pc->session_id = GNUNET_strdup ("");
+ }
+
if ( (! json_is_array (coins)) ||
(0 == (pc->coins_cnt = json_array_size (coins))) )
{
@@ -1596,37 +1612,6 @@ parse_pay (struct MHD_Connection *connection,
GNUNET_JSON_parse_free (spec);
}
- /* copy session ID (if set) */
- {
- const char *session_id;
- json_t *sid;
-
- sid = json_object_get (hc->request_body,
- "session_id");
- if (NULL != sid)
- {
- if (! json_is_string (sid))
- {
- GNUNET_break_op (0);
- return (MHD_YES ==
- TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_PARAMETER_MALFORMED,
- "session_id"))
- ? GNUNET_NO
- : GNUNET_SYSERR;
- }
- session_id = json_string_value (sid);
- GNUNET_assert (NULL != session_id);
- pc->session_id = GNUNET_strdup (session_id);
- }
- else
- {
- /* use empty string as default if client didn't specify it */
- pc->session_id = GNUNET_strdup ("");
- }
- }
-
/* copy order ID */
{
const char *order_id = hc->infix;