summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_pay.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/taler-merchant-httpd_pay.c')
-rw-r--r--src/backend/taler-merchant-httpd_pay.c117
1 files changed, 70 insertions, 47 deletions
diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c
index 4644354f..7b524b6a 100644
--- a/src/backend/taler-merchant-httpd_pay.c
+++ b/src/backend/taler-merchant-httpd_pay.c
@@ -73,11 +73,6 @@ deposit_fee_from_coin_aggregate (struct MHD_Connection *connection,
if (GNUNET_OK != res)
return res; /* may return GNUNET_NO */
- /*printf ("mint %s (%d), pends: %d\n",
- mints[mint_index].hostname,
- mint_index,
- mints[mint_index].pending);*/
-
if (1 == mints[mint_index].pending)
return GNUNET_SYSERR;
keys = TALER_MINT_get_keys (mints[mint_index].conn);
@@ -133,11 +128,6 @@ struct PayContext
uint64_t transaction_id;
/**
- * Offset of this coin into the array of all coins outcomes
- */
- unsigned int index;
-
- /**
* How many coins this paymen is made of.
*/
unsigned int coins_cnt;
@@ -151,6 +141,25 @@ struct PayContext
};
+/**
+ * Information needed by a single /deposit callback to refer to its
+ * own coin inside the confirmations array, namely `struct MERCHANT_DepositConfirmation *dc`
+ * above. Note: this information can NOT be shared between all the callbacks.
+ */
+struct DepositCallbackContext
+{
+
+ /**
+ * Offset of this coin into the array of all coins outcomes
+ */
+ unsigned int index;
+
+ /**
+ * Reference to the main PayContext
+ */
+ struct PayContext *pc;
+
+};
/**
* Callback to handle a deposit permission's response.
@@ -169,50 +178,40 @@ deposit_cb (void *cls,
unsigned int http_status,
json_t *proof)
{
- struct PayContext *pc = cls;
- /* NOTE: what if the mint doesn't respond? Does this callback get
- called? */
+ struct DepositCallbackContext *dcc = cls;
int i;
- printf ("deposit cb\n");
+ /*FIXME the index is the same for every individual cb */
if (GNUNET_SYSERR ==
MERCHANT_DB_update_deposit_permission (db_conn,
- pc->transaction_id,
+ dcc->pc->transaction_id,
0))
/* TODO */
printf ("db error\n");
- printf ("/deposit ack'd\n");
- pc->dc[pc->index].ackd = 1;
- pc->dc[pc->index].exit_status = http_status;
- pc->dc[pc->index].proof = proof;
+ dcc->pc->dc[dcc->index].ackd = 1;
+ dcc->pc->dc[dcc->index].exit_status = http_status;
+ dcc->pc->dc[dcc->index].proof = proof;
/* loop through the confirmation array and return accordingly */
- for (i = 0; i < pc->coins_cnt; i++)
+ for (i = 0; i < dcc->pc->coins_cnt; i++)
{
/* just return if there is at least one coin to be still
confirmed */
- if (! pc->dc[i].ackd)
+ if (! dcc->pc->dc[i].ackd)
{
printf ("still vacant coins\n");
return;
}
}
- /* Clean up what we can already */
- GNUNET_free (pc->dc);
- pc->dc = NULL;
-
+
printf ("All /deposit(s) ack'd\n");
- pc->response = NULL; /* FIXME; */
- /*
- i = TMH_RESPONSE_reply_json_pack (pc->connection,
- MHD_HTTP_OK,
- "{s:s}",
- "result", "all conins ack'd (and connection resumed)");
- printf ("mhd res %d\n", i);
- */
-
- pc->response_code = MHD_HTTP_OK;
- MHD_resume_connection (pc->connection);
+
+ dcc->pc->response = MHD_create_response_from_buffer (strlen ("All coins ack'd by the mint\n"),
+ "All coins ack'd by the mint\n",
+ MHD_RESPMEM_MUST_COPY);
+ dcc->pc->response_code = MHD_HTTP_OK;
+ /* Clean up what we can already */
+ MHD_resume_connection (dcc->pc->connection);
TM_trigger_daemon (); /* we resumed, kick MHD */
}
@@ -220,14 +219,25 @@ deposit_cb (void *cls,
static void
pay_context_cleanup (struct TM_HandlerContext *hc)
{
+ int i;
struct PayContext *pc = (struct PayContext *) hc;
+ for (i = 0; i < pc->coins_cnt; i++)
+ GNUNET_free_non_null (pc->dc[i].dcc);
+
TMH_PARSE_post_cleanup_callback (pc->json_parse_context);
+
+ #if 0
if (NULL != pc->response)
{
+ /* undestroyable regardless of the other MHD_destroy_response called
+ in this source, FIXME */
+
MHD_destroy_response (pc->response);
pc->response = NULL;
}
+ #endif
+
GNUNET_free_non_null (pc->dc);
GNUNET_free (pc);
}
@@ -299,7 +309,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
TMH_PARSE_MEMBER_END
};
- if (NULL == connection_cls)
+ if (NULL == *connection_cls)
{
pc = GNUNET_new (struct PayContext);
pc->hc.cc = &pay_context_cleanup;
@@ -311,7 +321,6 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
/* not the first call, recover state */
pc = *connection_cls;
}
-
if (0 != pc->response_code)
{
if (UINT_MAX == pc->response_code)
@@ -320,13 +329,20 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
res = MHD_queue_response (connection,
pc->response_code,
pc->response);
- MHD_destroy_response (pc->response);
- pc->response = NULL;
+ #if 0
+ if (pc->response != NULL)
+ {
+ /* undestroyable regardless of the other MHD_destroy_response called
+ in this source, FIXME */
+ MHD_destroy_response (pc->response);
+ pc->response = NULL;
+ }
+ #endif
return res;
}
res = TMH_PARSE_post_json (connection,
- connection_cls,
+ &pc->json_parse_context,
upload_data,
upload_data_size,
&root);
@@ -453,6 +469,11 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
That last cb will finally resume the connection and send back a response */
MHD_suspend_connection (connection);
+ pc->dc = dc;
+ pc->coins_cnt = coins_cnt;
+ pc->transaction_id = transaction_id;
+
+
json_array_foreach (coins, coins_index, coin_aggregate)
{
@@ -483,10 +504,11 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
if (GNUNET_OK != res)
return res; /* may return GNUNET_NO */
- pc->index = coins_index;
- pc->dc = dc;
- pc->coins_cnt = coins_cnt;
- pc->transaction_id = transaction_id;
+ /* c */
+ struct DepositCallbackContext *percoin_dcc = GNUNET_new (struct DepositCallbackContext);
+ pc->dc[coins_index].dcc = percoin_dcc;
+ percoin_dcc->index = coins_index;
+ percoin_dcc->pc = pc;
dh = TALER_MINT_deposit (mints[mint_index].conn,
&amount,
@@ -502,7 +524,9 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
refund_deadline,
&coin_sig,
&deposit_cb,
- pc); /*may be destroyed by the time the cb gets called..*/
+ percoin_dcc); /*FIXME TODO instantiate an individual cls for each
+ cb: each of them needs an index which points the
+ array of all the confirmations */
if (NULL == dh)
{
MHD_resume_connection (connection);
@@ -514,7 +538,6 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
}
}
- printf ("poller task: %p\n", poller_task);
GNUNET_SCHEDULER_cancel (poller_task);
GNUNET_SCHEDULER_add_now (context_task, mints[mint_index].ctx);
return MHD_YES;