diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-10-15 03:14:23 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-10-15 03:14:23 +0200 |
commit | 9f8b9743f382ee627439634369788489248c9a41 (patch) | |
tree | 01299695ad9601a3c3e75bd40249880ef163db22 /src/backend/taler-merchant-httpd_pay.c | |
parent | ff8fdfa0ec4f617993d385bb4258fb0538156c20 (diff) | |
parent | 521aa89e5bca18cab12d8872bfccea5de11f48ce (diff) | |
download | merchant-9f8b9743f382ee627439634369788489248c9a41.tar.gz merchant-9f8b9743f382ee627439634369788489248c9a41.tar.bz2 merchant-9f8b9743f382ee627439634369788489248c9a41.zip |
resolving merge conflict with Marcello, mostly exactly the same changes
Diffstat (limited to 'src/backend/taler-merchant-httpd_pay.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_pay.c | 216 |
1 files changed, 108 insertions, 108 deletions
diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c index 9d1b0b3c..339d9f08 100644 --- a/src/backend/taler-merchant-httpd_pay.c +++ b/src/backend/taler-merchant-httpd_pay.c @@ -797,35 +797,35 @@ check_coin_paid (void *cls, */ static void check_transaction_exists (void *cls, - uint64_t transaction_id, - const struct TALER_MerchantPublicKeyP *merchant_pub, - const char *exchange_uri, - const struct GNUNET_HashCode *h_contract, - const struct GNUNET_HashCode *h_xwire, - struct GNUNET_TIME_Absolute timestamp, - struct GNUNET_TIME_Absolute refund, - const struct TALER_Amount *total_amount) + uint64_t transaction_id, + const struct TALER_MerchantPublicKeyP *merchant_pub, + const char *exchange_uri, + const struct GNUNET_HashCode *h_contract, + const struct GNUNET_HashCode *h_xwire, + struct GNUNET_TIME_Absolute timestamp, + struct GNUNET_TIME_Absolute refund, + const struct TALER_Amount *total_amount) { struct PayContext *pc = cls; if ( (0 == memcmp (h_contract, - &pc->h_contract, - sizeof (struct GNUNET_HashCode))) && + &pc->h_contract, + sizeof (struct GNUNET_HashCode))) && (0 == memcmp (h_xwire, - &pc->mi->h_wire, - sizeof (struct GNUNET_HashCode))) && + &pc->mi->h_wire, + sizeof (struct GNUNET_HashCode))) && (timestamp.abs_value_us == pc->timestamp.abs_value_us) && (refund.abs_value_us == pc->refund_deadline.abs_value_us) && (0 == TALER_amount_cmp (total_amount, - &pc->amount) ) ) + &pc->amount) ) ) { pc->transaction_exits = GNUNET_YES; } else - { - GNUNET_break_op (0); - pc->transaction_exits = GNUNET_SYSERR; - } + { + GNUNET_break_op (0); + pc->transaction_exits = GNUNET_SYSERR; + } } extern struct MerchantInstance * @@ -846,17 +846,17 @@ get_instance (struct json_t *json); */ int MH_handler_pay (struct TMH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size) + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size) { struct PayContext *pc; int res; json_t *root; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "In handler for /pay.\n"); + "In handler for /pay.\n"); if (NULL == *connection_cls) { pc = GNUNET_new (struct PayContext); @@ -878,35 +878,35 @@ MH_handler_pay (struct TMH_RequestHandler *rh, return MHD_NO; /* hard error */ } res = MHD_queue_response (connection, - pc->response_code, - pc->response); + pc->response_code, + pc->response); if (NULL != pc->response) { MHD_destroy_response (pc->response); pc->response = NULL; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Queueing response (%u) for /pay (%s).\n", - (unsigned int) pc->response_code, - res ? "OK" : "FAILED"); + "Queueing response (%u) for /pay (%s).\n", + (unsigned int) pc->response_code, + res ? "OK" : "FAILED"); return res; } if (NULL != pc->chosen_exchange) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Shouldn't be here. Old MHD version?\n"); + "Shouldn't be here. Old MHD version?\n"); return MHD_YES; } res = TMH_PARSE_post_json (connection, - &pc->json_parse_context, - upload_data, - upload_data_size, - &root); + &pc->json_parse_context, + upload_data, + upload_data_size, + &root); if (GNUNET_SYSERR == res) { GNUNET_break (0); return TMH_RESPONSE_reply_external_error (connection, - "failed to parse JSON body"); + "failed to parse JSON body"); } if ((GNUNET_NO == res) || (NULL == root)) return MHD_YES; /* the POST's body has to be further fetched */ @@ -935,95 +935,95 @@ MH_handler_pay (struct TMH_RequestHandler *rh, }; res = TMH_PARSE_json_data (connection, - root, - spec); + root, + spec); if (GNUNET_YES != res) { json_decref (root); GNUNET_break (0); return (GNUNET_NO == res) ? MHD_YES : MHD_NO; } - pc->mi = mi; + pc->mi = get_instance (root); GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "/pay: picked instance %s\n", - pc->mi->id); + "/pay: picked instance %s\n", + pc->mi->id); if (NULL == pc->mi) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Not able to find the specified receiver\n"); + "Not able to find the specified receiver\n"); json_decref (root); return TMH_RESPONSE_reply_external_error (connection, - "Unknown receiver given"); + "Unknown receiver given"); } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "The receiver for this deposit is '%s', whose bank details are '%s'\n", - pc->mi->id, - json_dumps (pc->mi->j_wire, JSON_COMPACT)); + "The receiver for this deposit is '%s', whose bank details are '%s'\n", + pc->mi->id, + json_dumps (pc->mi->j_wire, JSON_COMPACT)); pc->chosen_exchange = GNUNET_strdup (chosen_exchange); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Parsed JSON for /pay.\n"); + "Parsed JSON for /pay.\n"); cp.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_CONTRACT); cp.purpose.size = htonl (sizeof (struct TALER_ContractPS)); cp.transaction_id = GNUNET_htonll (pc->transaction_id); TALER_amount_hton (&cp.total_amount, - &pc->amount); + &pc->amount); TALER_amount_hton (&cp.max_fee, - &pc->max_fee); + &pc->max_fee); cp.h_contract = pc->h_contract; cp.merchant_pub = pc->mi->pubkey; if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_CONTRACT, - &cp.purpose, - &merchant_sig.eddsa_sig, - &pc->mi->pubkey.eddsa_pub)) + GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_CONTRACT, + &cp.purpose, + &merchant_sig.eddsa_sig, + &pc->mi->pubkey.eddsa_pub)) { GNUNET_break (0); GNUNET_JSON_parse_free (spec); json_decref (root); return TMH_RESPONSE_reply_external_error (connection, - "invalid merchant signature supplied"); + "invalid merchant signature supplied"); } /* 'wire_transfer_deadline' is optional, if it is not present, generate it here; it will be timestamp plus the wire_transfer_delay supplied in config file */ if (NULL == json_object_get (root, - "wire_transfer_deadline")) + "wire_transfer_deadline")) { pc->wire_transfer_deadline = GNUNET_TIME_absolute_add (pc->timestamp, - wire_transfer_delay); + wire_transfer_delay); if (pc->wire_transfer_deadline.abs_value_us < pc->refund_deadline.abs_value_us) { - /* Refund value very large, delay wire transfer accordingly */ - pc->wire_transfer_deadline = pc->refund_deadline; + /* Refund value very large, delay wire transfer accordingly */ + pc->wire_transfer_deadline = pc->refund_deadline; } } else { struct GNUNET_JSON_Specification espec[] = { - GNUNET_JSON_spec_absolute_time ("wire_transfer_deadline", - &pc->wire_transfer_deadline), - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_absolute_time ("wire_transfer_deadline", + &pc->wire_transfer_deadline), + GNUNET_JSON_spec_end() }; res = TMH_PARSE_json_data (connection, - root, - espec); + root, + espec); if (GNUNET_YES != res) { - GNUNET_JSON_parse_free (spec); - json_decref (root); - GNUNET_break (0); - return (GNUNET_NO == res) ? MHD_YES : MHD_NO; + GNUNET_JSON_parse_free (spec); + json_decref (root); + GNUNET_break (0); + return (GNUNET_NO == res) ? MHD_YES : MHD_NO; } if (pc->wire_transfer_deadline.abs_value_us < pc->refund_deadline.abs_value_us) { - GNUNET_break (0); - GNUNET_JSON_parse_free (spec); - json_decref (root); - return TMH_RESPONSE_reply_external_error (connection, - "refund deadline after wire transfer deadline"); + GNUNET_break (0); + GNUNET_JSON_parse_free (spec); + json_decref (root); + return TMH_RESPONSE_reply_external_error (connection, + "refund deadline after wire transfer deadline"); } } @@ -1034,46 +1034,46 @@ MH_handler_pay (struct TMH_RequestHandler *rh, GNUNET_JSON_parse_free (spec); json_decref (root); return TMH_RESPONSE_reply_external_error (connection, - "no coins given"); + "no coins given"); } /* note: 1 coin = 1 deposit confirmation expected */ pc->dc = GNUNET_new_array (pc->coins_cnt, - struct DepositConfirmation); + struct DepositConfirmation); /* This loop populates the array 'dc' in 'pc' */ json_array_foreach (coins, coins_index, coin) { struct DepositConfirmation *dc = &pc->dc[coins_index]; struct GNUNET_JSON_Specification spec[] = { - TALER_JSON_spec_denomination_public_key ("denom_pub", &dc->denom), - TALER_JSON_spec_amount ("f" /* FIXME */, &dc->amount_with_fee), - GNUNET_JSON_spec_fixed_auto ("coin_pub", &dc->coin_pub), - TALER_JSON_spec_denomination_signature ("ub_sig", &dc->ub_sig), - GNUNET_JSON_spec_fixed_auto ("coin_sig", &dc->coin_sig), - GNUNET_JSON_spec_end() + TALER_JSON_spec_denomination_public_key ("denom_pub", &dc->denom), + TALER_JSON_spec_amount ("f" /* FIXME */, &dc->amount_with_fee), + GNUNET_JSON_spec_fixed_auto ("coin_pub", &dc->coin_pub), + TALER_JSON_spec_denomination_signature ("ub_sig", &dc->ub_sig), + GNUNET_JSON_spec_fixed_auto ("coin_sig", &dc->coin_sig), + GNUNET_JSON_spec_end() }; res = TMH_PARSE_json_data (connection, - coin, - spec); + coin, + spec); if (GNUNET_YES != res) { - GNUNET_JSON_parse_free (spec); - json_decref (root); - GNUNET_break (0); - return (GNUNET_NO == res) ? MHD_YES : MHD_NO; + GNUNET_JSON_parse_free (spec); + json_decref (root); + GNUNET_break (0); + return (GNUNET_NO == res) ? MHD_YES : MHD_NO; } { - char *s; - - s = TALER_amount_to_string (&dc->amount_with_fee); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Coin #%i has f %s\n", - coins_index, - s); - GNUNET_free (s); - } + char *s; + + s = TALER_amount_to_string (&dc->amount_with_fee); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Coin #%i has f %s\n", + coins_index, + s); + GNUNET_free (s); + } dc->index = coins_index; dc->pc = pc; @@ -1084,16 +1084,16 @@ MH_handler_pay (struct TMH_RequestHandler *rh, /* Check if this payment attempt has already succeeded */ if (GNUNET_SYSERR == - db->find_payments_by_id (db->cls, - pc->transaction_id, - &mi->pubkey, - &check_coin_paid, - pc)) + db->find_payments (db->cls, + pc->transaction_id, + &pc->mi->pubkey, + &check_coin_paid, + pc)) { GNUNET_break (0); json_decref (root); return TMH_RESPONSE_reply_internal_error (connection, - "Merchant database error"); + "Merchant database error"); } if (0 == pc->pending) { @@ -1103,11 +1103,11 @@ MH_handler_pay (struct TMH_RequestHandler *rh, /* Payment succeeded in the past; take short cut and accept immediately */ resp = MHD_create_response_from_buffer (0, - NULL, - MHD_RESPMEM_PERSISTENT); + NULL, + MHD_RESPMEM_PERSISTENT); ret = MHD_queue_response (connection, - MHD_HTTP_OK, - resp); + MHD_HTTP_OK, + resp); MHD_destroy_response (resp); json_decref (root); return ret; @@ -1115,15 +1115,15 @@ MH_handler_pay (struct TMH_RequestHandler *rh, /* Check if transaction is already known, if not store it. */ if (GNUNET_SYSERR == db->find_transaction (db->cls, - pc->transaction_id, - &pc->mi->pubkey, - &check_transaction_exists, + pc->transaction_id, + &pc->mi->pubkey, + &check_transaction_exists, pc)) { GNUNET_break (0); json_decref (root); return TMH_RESPONSE_reply_internal_error (connection, - "Merchant database error"); + "Merchant database error"); } if (GNUNET_SYSERR == pc->transaction_exits) { @@ -1137,7 +1137,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh, if (GNUNET_OK != db->store_transaction (db->cls, pc->transaction_id, - &pc->mi->pubkey, + &pc->mi->pubkey, pc->chosen_exchange, &pc->h_contract, &pc->mi->h_wire, @@ -1148,7 +1148,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh, GNUNET_break (0); json_decref (root); return TMH_RESPONSE_reply_internal_error (connection, - "Merchant database error"); + "Merchant database error"); } } |