diff options
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c | 149 |
1 files changed, 100 insertions, 49 deletions
diff --git a/src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c b/src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c index 9292b3ff..80f40815 100644 --- a/src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c +++ b/src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c @@ -310,27 +310,6 @@ resume_kyc_with_response (struct KycContext *kc, /** - * Resume KYC processing with an error. - * - * @param kc operation to resume - * @param http_status http status code to return - * @param ec taler error code to return - * @param msg human readable error message - */ -static void -resume_kyc_with_error (struct KycContext *kc, - unsigned int http_status, - enum TALER_ErrorCode ec, - const char *msg) -{ - resume_kyc_with_response (kc, - http_status, - TALER_MHD_make_error (ec, - msg)); -} - - -/** * Handle a timeout for the processing of the kyc request. * * @param cls our `struct KycContext` @@ -339,21 +318,48 @@ static void handle_kyc_timeout (void *cls) { struct KycContext *kc = cls; + struct ExchangeKycRequest *ekr; kc->timeout_task = NULL; + while (NULL != (ekr = kc->exchange_pending_head)) + { + GNUNET_CONTAINER_DLL_remove (kc->exchange_pending_head, + kc->exchange_pending_tail, + ekr); + if (NULL != ekr->kyc) + { + TALER_EXCHANGE_kyc_check_cancel (ekr->kyc); + ekr->kyc = NULL; + } + GNUNET_assert ( + 0 == + json_array_append_new ( + kc->timeout_kycs, + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("exchange_url", + ekr->exchange_url), + GNUNET_JSON_pack_uint64 ("exchange_code", + TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT), + GNUNET_JSON_pack_uint64 ("exchange_http_status", + 0)))); + GNUNET_free (ekr->exchange_url); + GNUNET_free (ekr->payto_uri); + GNUNET_free (ekr); + } GNUNET_assert (GNUNET_YES == kc->suspended); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Resuming KYC with error after timeout\n"); - // FIXME: we _still_ need to produce a valid - // JSON reply, not just an error according to the spec! - resume_kyc_with_error (kc, - MHD_HTTP_GATEWAY_TIMEOUT, - TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT, - NULL); + "Resuming KYC with gateway timeout\n"); + resume_kyc_with_response ( + kc, + MHD_HTTP_GATEWAY_TIMEOUT, + TALER_MHD_MAKE_JSON_PACK ( + GNUNET_JSON_pack_array_incref ("pending_kycs", + kc->pending_kycs), + GNUNET_JSON_pack_array_incref ("timeout_kycs", + kc->timeout_kycs))); } -#if FIXME /** * Function called with the result of a KYC check. * @@ -369,14 +375,47 @@ exchange_check_cb (void *cls, ekr->kyc = NULL; // build up reply in 'kc' - if (error_reply) + switch (ks->http_status) { - // logging ... + case MHD_HTTP_OK: + // STORE in DB: ks->details.kyc_ok.{timestamp,exchange_pub,exchange_sig} + // FIXME... + break; + case MHD_HTTP_ACCEPTED: + GNUNET_assert ( + 0 == + json_array_append_new ( + kc->pending_kycs, + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("kyc_url", + ks->details.kyc_url), + GNUNET_JSON_pack_string ("exchange_url", + ekr->exchange_url), + GNUNET_JSON_pack_string ("payto_uri", + ekr->payto_uri)))); + break; + case MHD_HTTP_NO_CONTENT: + // STORE in DB: no KYC at this exchange! + // FIXME... + break; + default: + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Exchange responded with HTTP status %u (%d) to /kyc-check request!\n", + ks->http_status, + ks->ec); kc->response_code = MHD_HTTP_BAD_GATEWAY; - } - else - { - // ... + GNUNET_assert ( + 0 == + json_array_append_new ( + kc->timeout_kycs, + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("exchange_url", + ekr->exchange_url), + GNUNET_JSON_pack_uint64 ("exchange_code", + ks->ec), + GNUNET_JSON_pack_uint64 ("exchange_http_status", + ks->http_status)))); + break; } GNUNET_CONTAINER_DLL_remove (kc->exchange_pending_head, @@ -394,22 +433,27 @@ exchange_check_cb (void *cls, { /* special case: all KYC operations did succeed after we asked at the exchanges => 204 */ - response = empty; + struct MHD_Response *response; + + response = MHD_create_response_from_buffer (0, + "", + MHD_RESPMEM_PERSISTENT); resume_kyc_with_response (kc, MHD_HTTP_NO_CONTENT, response); return; } - response = make_response (kc); - resume_kyc_with_response (kc, - kc->response_code, - response); + resume_kyc_with_response ( + kc, + kc->response_code, /* MHD_HTTP_OK or MHD_HTTP_BAD_GATEWAY */ + TALER_MHD_MAKE_JSON_PACK ( + GNUNET_JSON_pack_array_incref ("pending_kycs", + kc->pending_kycs), + GNUNET_JSON_pack_array_incref ("timeout_kycs", + kc->timeout_kycs))); } -#endif - - /** * Function called from ``account_kyc_get_status`` * with KYC status information for this merchant. @@ -452,12 +496,19 @@ kyc_status_cb (void *cls, ekr->kc = kc; #if FIXME exchange <= from (exchange_url); - ekr->kyc = TALER_EXCHANGE_kyc_check (exchange, - exchange_kyc_serial, - h_wire, - pc->timeout, - &exchange_check_cb, - ekr); + { + struct GNUNET_HashCode h_payto; + + GNUNET_CRYPTO_hash (payto_uri, + strlen (payto_uri), + &h_payto); + ekr->kyc = TALER_EXCHANGE_kyc_check (exchange, + exchange_kyc_serial, + &h_payto, + pc->timeout, + &exchange_check_cb, + ekr); + } #endif } |