diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Makefile.am | 4 | ||||
-rw-r--r-- | src/lib/exchange_api_common.c | 26 | ||||
-rw-r--r-- | src/lib/exchange_api_handle.c | 21 | ||||
-rw-r--r-- | src/lib/exchange_api_reserves_get.c | 100 | ||||
-rw-r--r-- | src/lib/exchange_api_reserves_history.c | 192 | ||||
-rw-r--r-- | src/lib/exchange_api_reserves_status.c | 183 | ||||
-rw-r--r-- | src/lib/exchange_api_withdraw2.c | 4 |
7 files changed, 233 insertions, 297 deletions
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 7d49f53cd..730c833d7 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -18,7 +18,7 @@ lib_LTLIBRARIES = \ libtalerexchange.la libtalerexchange_la_LDFLAGS = \ - -version-info 4:0:0 \ + -version-info 5:0:0 \ -no-undefined libtalerexchange_la_SOURCES = \ exchange_api_auditor_add_denomination.c \ @@ -51,6 +51,8 @@ libtalerexchange_la_SOURCES = \ exchange_api_refreshes_reveal.c \ exchange_api_refund.c \ exchange_api_reserves_get.c \ + exchange_api_reserves_history.c \ + exchange_api_reserves_status.c \ exchange_api_transfers_get.c \ exchange_api_withdraw.c \ exchange_api_withdraw2.c \ diff --git a/src/lib/exchange_api_common.c b/src/lib/exchange_api_common.c index 160f62dc6..c9bff71f1 100644 --- a/src/lib/exchange_api_common.c +++ b/src/lib/exchange_api_common.c @@ -34,7 +34,7 @@ TALER_EXCHANGE_parse_reserve_history ( const char *currency, struct TALER_Amount *balance, unsigned int history_length, - struct TALER_EXCHANGE_ReserveHistory *rhistory) + struct TALER_EXCHANGE_ReserveHistoryEntry *rhistory) { struct GNUNET_HashCode uuid[history_length]; unsigned int uuid_off; @@ -50,7 +50,7 @@ TALER_EXCHANGE_parse_reserve_history ( uuid_off = 0; for (unsigned int off = 0; off<history_length; off++) { - struct TALER_EXCHANGE_ReserveHistory *rh = &rhistory[off]; + struct TALER_EXCHANGE_ReserveHistoryEntry *rh = &rhistory[off]; json_t *transaction; struct TALER_Amount amount; const char *type; @@ -368,14 +368,20 @@ TALER_EXCHANGE_parse_reserve_history ( } /* check balance = total_in - total_out < withdraw-amount */ - if (0 > - TALER_amount_subtract (balance, - &total_in, - &total_out)) + if (NULL != balance) { - /* total_in < total_out, why did the exchange ever allow this!? */ - GNUNET_break_op (0); - return GNUNET_SYSERR; + /* if balance is NULL, we may have a partial history + in which case the subtraction may fail, so we do + not even check that invariant in this case. */ + if (0 > + TALER_amount_subtract (balance, + &total_in, + &total_out)) + { + /* total_in < total_out, why did the exchange ever allow this!? */ + GNUNET_break_op (0); + return GNUNET_SYSERR; + } } return GNUNET_OK; } @@ -383,7 +389,7 @@ TALER_EXCHANGE_parse_reserve_history ( void TALER_EXCHANGE_free_reserve_history ( - struct TALER_EXCHANGE_ReserveHistory *rhistory, + struct TALER_EXCHANGE_ReserveHistoryEntry *rhistory, unsigned int len) { for (unsigned int i = 0; i<len; i++) diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index f7e877913..e0fcd2b93 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -2181,6 +2181,27 @@ TALER_EXCHANGE_get_denomination_key ( } +const struct TALER_EXCHANGE_GlobalFee * +TALER_EXCHANGE_get_global_fee ( + const struct TALER_EXCHANGE_Keys *keys, + struct GNUNET_TIME_Timestamp ts) +{ + for (unsigned int i = 0; i<keys->num_global_fees; i++) + { + const struct TALER_EXCHANGE_GlobalFee *gf = &keys->global_fees[i]; + + if (GNUNET_TIME_timestamp_cmp (ts, + >=, + gf->start_date) && + GNUNET_TIME_timestamp_cmp (ts, + <, + gf->end_date)) + return gf; + } + return NULL; +} + + struct TALER_EXCHANGE_DenomPublicKey * TALER_EXCHANGE_copy_denomination_key ( const struct TALER_EXCHANGE_DenomPublicKey *key) diff --git a/src/lib/exchange_api_reserves_get.c b/src/lib/exchange_api_reserves_get.c index a25350e5b..4c2886e0b 100644 --- a/src/lib/exchange_api_reserves_get.c +++ b/src/lib/exchange_api_reserves_get.c @@ -83,19 +83,15 @@ static enum GNUNET_GenericReturnValue handle_reserves_get_ok (struct TALER_EXCHANGE_ReservesGetHandle *rgh, const json_t *j) { - json_t *history; - unsigned int len; - struct TALER_Amount balance; - struct TALER_Amount balance_from_history; + struct TALER_EXCHANGE_ReserveSummary rs = { + .hr.reply = j, + .hr.http_status = MHD_HTTP_OK + }; struct GNUNET_JSON_Specification spec[] = { TALER_JSON_spec_amount_any ("balance", - &balance), + &rs.details.ok.balance), GNUNET_JSON_spec_end () }; - struct TALER_EXCHANGE_HttpResponse hr = { - .reply = j, - .http_status = MHD_HTTP_OK - }; if (GNUNET_OK != GNUNET_JSON_parse (j, @@ -106,55 +102,9 @@ handle_reserves_get_ok (struct TALER_EXCHANGE_ReservesGetHandle *rgh, GNUNET_break_op (0); return GNUNET_SYSERR; } - history = json_object_get (j, - "history"); - if (NULL == history) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - len = json_array_size (history); - { - struct TALER_EXCHANGE_ReserveHistory *rhistory; - - rhistory = GNUNET_new_array (len, - struct TALER_EXCHANGE_ReserveHistory); - if (GNUNET_OK != - TALER_EXCHANGE_parse_reserve_history (rgh->exchange, - history, - &rgh->reserve_pub, - balance.currency, - &balance_from_history, - len, - rhistory)) - { - GNUNET_break_op (0); - TALER_EXCHANGE_free_reserve_history (rhistory, - len); - return GNUNET_SYSERR; - } - if (0 != - TALER_amount_cmp (&balance_from_history, - &balance)) - { - /* exchange cannot add up balances!? */ - GNUNET_break_op (0); - TALER_EXCHANGE_free_reserve_history (rhistory, - len); - return GNUNET_SYSERR; - } - if (NULL != rgh->cb) - { - rgh->cb (rgh->cb_cls, - &hr, - &balance, - len, - rhistory); - rgh->cb = NULL; - } - TALER_EXCHANGE_free_reserve_history (rhistory, - len); - } + rgh->cb (rgh->cb_cls, + &rs); + rgh->cb = NULL; return GNUNET_OK; } @@ -174,61 +124,59 @@ handle_reserves_get_finished (void *cls, { struct TALER_EXCHANGE_ReservesGetHandle *rgh = cls; const json_t *j = response; - struct TALER_EXCHANGE_HttpResponse hr = { - .reply = j, - .http_status = (unsigned int) response_code + struct TALER_EXCHANGE_ReserveSummary rs = { + .hr.reply = j, + .hr.http_status = (unsigned int) response_code }; rgh->job = NULL; switch (response_code) { case 0: - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + rs.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; case MHD_HTTP_OK: if (GNUNET_OK != handle_reserves_get_ok (rgh, j)) { - hr.http_status = 0; - hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + rs.hr.http_status = 0; + rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; } break; case MHD_HTTP_BAD_REQUEST: /* This should never happen, either us or the exchange is buggy (or API version conflict); just pass JSON reply to the application */ - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_NOT_FOUND: /* Nothing really to verify, this should never happen, we should pass the JSON reply to the application */ - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: /* Server had an internal issue; we should retry, but this API leaves this to the application */ - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); break; default: /* unexpected response code */ GNUNET_break_op (0); - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for reserves get\n", (unsigned int) response_code, - (int) hr.ec); + (int) rs.hr.ec); break; } if (NULL != rgh->cb) { rgh->cb (rgh->cb_cls, - &hr, - NULL, - 0, NULL); + &rs); rgh->cb = NULL; } TALER_EXCHANGE_reserves_get_cancel (rgh); diff --git a/src/lib/exchange_api_reserves_history.c b/src/lib/exchange_api_reserves_history.c index f7191b2ad..c0f6c42d2 100644 --- a/src/lib/exchange_api_reserves_history.c +++ b/src/lib/exchange_api_reserves_history.c @@ -81,35 +81,32 @@ struct TALER_EXCHANGE_ReservesHistoryHandle * We received an #MHD_HTTP_OK history code. Handle the JSON * response. * - * @param rgh handle of the request + * @param rsh handle of the request * @param j JSON response * @return #GNUNET_OK on success */ static enum GNUNET_GenericReturnValue -handle_reserves_history_ok (struct TALER_EXCHANGE_ReservesHistoryHandle *rgh, +handle_reserves_history_ok (struct TALER_EXCHANGE_ReservesHistoryHandle *rsh, const json_t *j) { json_t *history; unsigned int len; - bool kyc_ok; - bool kyc_required; - struct TALER_Amount balance; - struct TALER_Amount balance_from_history; + struct TALER_Amount history_balance; + struct TALER_EXCHANGE_ReserveHistory rs = { + .hr.reply = j, + .hr.http_status = MHD_HTTP_OK + }; struct GNUNET_JSON_Specification spec[] = { TALER_JSON_spec_amount_any ("balance", - &balance), + &rs.details.ok.balance), GNUNET_JSON_spec_bool ("kyc_passed", - &kyc_ok), + &rs.details.ok.kyc_ok), GNUNET_JSON_spec_bool ("kyc_required", - &kyc_required), + &rs.details.ok.kyc_required), GNUNET_JSON_spec_json ("history", &history), GNUNET_JSON_spec_end () }; - struct TALER_EXCHANGE_HttpResponse hr = { - .reply = j, - .http_history = MHD_HTTP_OK - }; if (GNUNET_OK != GNUNET_JSON_parse (j, @@ -122,16 +119,19 @@ handle_reserves_history_ok (struct TALER_EXCHANGE_ReservesHistoryHandle *rgh, } len = json_array_size (history); { - struct TALER_EXCHANGE_ReserveHistory *rhistory; + struct TALER_EXCHANGE_ReserveHistoryEntry *rhistory; rhistory = GNUNET_new_array (len, - struct TALER_EXCHANGE_ReserveHistory); + struct TALER_EXCHANGE_ReserveHistoryEntry); + // FIXME: even this history could be partial + // (if the reserve is too old!); update API + // and return incoming & outgoing totals separately? if (GNUNET_OK != - TALER_EXCHANGE_parse_reserve_history (rgh->exchange, + TALER_EXCHANGE_parse_reserve_history (rsh->exchange, history, - &rgh->reserve_pub, - balance.currency, - &balance_from_history, + &rsh->reserve_pub, + rs.details.ok.balance.currency, + &history_balance, len, rhistory)) { @@ -141,25 +141,13 @@ handle_reserves_history_ok (struct TALER_EXCHANGE_ReservesHistoryHandle *rgh, GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } - if (0 != - TALER_amount_cmp (&balance_from_history, - &balance)) + if (NULL != rsh->cb) { - /* exchange cannot add up balances!? */ - GNUNET_break_op (0); - TALER_EXCHANGE_free_reserve_history (rhistory, - len); - GNUNET_JSON_parse_free (spec); - return GNUNET_SYSERR; - } - if (NULL != rgh->cb) - { - rgh->cb (rgh->cb_cls, - &hr, - &balance, - len, - rhistory); - rgh->cb = NULL; + rs.details.ok.history = rhistory; + rs.details.ok.history_len = len; + rsh->cb (rsh->cb_cls, + &rs); + rsh->cb = NULL; } TALER_EXCHANGE_free_reserve_history (rhistory, len); @@ -182,75 +170,72 @@ handle_reserves_history_finished (void *cls, long response_code, const void *response) { - struct TALER_EXCHANGE_ReservesHistoryHandle *rgh = cls; + struct TALER_EXCHANGE_ReservesHistoryHandle *rsh = cls; const json_t *j = response; - struct TALER_EXCHANGE_HttpResponse hr = { - .reply = j, - .http_history = (unsigned int) response_code + struct TALER_EXCHANGE_ReserveHistory rs = { + .hr.reply = j, + .hr.http_status = (unsigned int) response_code }; - rgh->job = NULL; + rsh->job = NULL; switch (response_code) { case 0: - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + rs.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; case MHD_HTTP_OK: if (GNUNET_OK != - handle_reserves_history_ok (rgh, + handle_reserves_history_ok (rsh, j)) { - hr.http_history = 0; - hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + rs.hr.http_status = 0; + rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; } break; case MHD_HTTP_BAD_REQUEST: /* This should never happen, either us or the exchange is buggy (or API version conflict); just pass JSON reply to the application */ GNUNET_break (0); - hr.ec = TALER_JSON_history_error_code (j); - hr.hint = TALER_JSON_history_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_FORBIDDEN: /* This should never happen, either us or the exchange is buggy (or API version conflict); just pass JSON reply to the application */ GNUNET_break (0); - hr.ec = TALER_JSON_history_error_code (j); - hr.hint = TALER_JSON_history_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_NOT_FOUND: /* Nothing really to verify, this should never happen, we should pass the JSON reply to the application */ - hr.ec = TALER_JSON_history_error_code (j); - hr.hint = TALER_JSON_history_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: /* Server had an internal issue; we should retry, but this API leaves this to the application */ - hr.ec = TALER_JSON_history_error_code (j); - hr.hint = TALER_JSON_history_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); break; default: /* unexpected response code */ GNUNET_break_op (0); - hr.ec = TALER_JSON_history_error_code (j); - hr.hint = TALER_JSON_history_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for reserves history\n", (unsigned int) response_code, - (int) hr.ec); + (int) rs.hr.ec); break; } - if (NULL != rgh->cb) + if (NULL != rsh->cb) { - rgh->cb (rgh->cb_cls, - &hr, - NULL, - 0, - NULL); - rgh->cb = NULL; + rsh->cb (rsh->cb_cls, + &rs); + rsh->cb = NULL; } - TALER_EXCHANGE_reserves_history_cancel (rgh); + TALER_EXCHANGE_reserves_history_cancel (rsh); } @@ -261,12 +246,11 @@ TALER_EXCHANGE_reserves_history ( TALER_EXCHANGE_ReservesHistoryCallback cb, void *cb_cls) { - struct TALER_EXCHANGE_ReservesHistoryHandle *rgh; + struct TALER_EXCHANGE_ReservesHistoryHandle *rsh; struct GNUNET_CURL_Context *ctx; CURL *eh; char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32]; - const struct TALER_Amount *history_fee; - const struct TALER_EXCHANGE_Keys *keys; + struct TALER_ReserveSignatureP reserve_sig; struct GNUNET_TIME_Timestamp ts = GNUNET_TIME_timestamp_get (); @@ -276,22 +260,19 @@ TALER_EXCHANGE_reserves_history ( GNUNET_break (0); return NULL; } - keys = TALER_EXCHANGE_get_keys (exchange); - // FIXME: extract history_fee from keys! - history_fee = FIXME; - rgh = GNUNET_new (struct TALER_EXCHANGE_ReservesHistoryHandle); - rgh->exchange = exchange; - rgh->cb = cb; - rgh->cb_cls = cb_cls; + rsh = GNUNET_new (struct TALER_EXCHANGE_ReservesHistoryHandle); + rsh->exchange = exchange; + rsh->cb = cb; + rsh->cb_cls = cb_cls; GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv, - &rgh->reserve_pub.eddsa_pub); + &rsh->reserve_pub.eddsa_pub); { char pub_str[sizeof (struct TALER_ReservePublicKeyP) * 2]; char *end; end = GNUNET_STRINGS_data_to_string ( - &rgh->reserve_pub, - sizeof (rgh->reserve_pub), + &rsh->reserve_pub, + sizeof (rsh->reserve_pub), pub_str, sizeof (pub_str)); *end = '\0'; @@ -300,68 +281,67 @@ TALER_EXCHANGE_reserves_history ( "/reserves/%s/history", pub_str); } - rgh->url = TEAH_path_to_url (exchange, + rsh->url = TEAH_path_to_url (exchange, arg_str); - if (NULL == rgh->url) + if (NULL == rsh->url) { - GNUNET_free (rgh); + GNUNET_free (rsh); return NULL; } - eh = TALER_EXCHANGE_curl_easy_history_ (rgh->url); + eh = TALER_EXCHANGE_curl_easy_get_ (rsh->url); if (NULL == eh) { GNUNET_break (0); - GNUNET_free (rgh->url); - GNUNET_free (rgh); + GNUNET_free (rsh->url); + GNUNET_free (rsh); return NULL; } TALER_wallet_reserve_history_sign (ts, - history_fee, + NULL, /* FIXME: fee! */ reserve_priv, &reserve_sig); { json_t *history_obj = GNUNET_JSON_PACK ( GNUNET_JSON_pack_timestamp ("request_timestamp", - &ts), + ts), GNUNET_JSON_pack_data_auto ("reserve_sig", &reserve_sig)); if (GNUNET_OK != - TALER_curl_easy_post (&rgh->post_ctx, + TALER_curl_easy_post (&rsh->post_ctx, eh, history_obj)) - ) - { - GNUNET_break (0); - curl_easy_cleanup (eh); - json_decref (history_obj); - GNUNET_free (rgh->url); - GNUNET_free (rgh); - return NULL; - } + { + GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (history_obj); + GNUNET_free (rsh->url); + GNUNET_free (rsh); + return NULL; + } + json_decref (history_obj); } ctx = TEAH_handle_to_context (exchange); - rgh->job = GNUNET_CURL_job_add (ctx, + rsh->job = GNUNET_CURL_job_add (ctx, eh, &handle_reserves_history_finished, - rgh); - return rgh; + rsh); + return rsh; } void TALER_EXCHANGE_reserves_history_cancel ( - struct TALER_EXCHANGE_ReservesHistoryHandle *rgh) + struct TALER_EXCHANGE_ReservesHistoryHandle *rsh) { - if (NULL != rgh->job) + if (NULL != rsh->job) { - GNUNET_CURL_job_cancel (rgh->job); - rgh->job = NULL; + GNUNET_CURL_job_cancel (rsh->job); + rsh->job = NULL; } - TALER_curl_easy_post_finished (&rgh->post_ctx); - GNUNET_free (rgh->url); - GNUNET_free (rgh); + TALER_curl_easy_post_finished (&rsh->post_ctx); + GNUNET_free (rsh->url); + GNUNET_free (rsh); } diff --git a/src/lib/exchange_api_reserves_status.c b/src/lib/exchange_api_reserves_status.c index 2758a3a28..a99a080bc 100644 --- a/src/lib/exchange_api_reserves_status.c +++ b/src/lib/exchange_api_reserves_status.c @@ -81,35 +81,31 @@ struct TALER_EXCHANGE_ReservesStatusHandle * We received an #MHD_HTTP_OK status code. Handle the JSON * response. * - * @param rgh handle of the request + * @param rsh handle of the request * @param j JSON response * @return #GNUNET_OK on success */ static enum GNUNET_GenericReturnValue -handle_reserves_status_ok (struct TALER_EXCHANGE_ReservesStatusHandle *rgh, +handle_reserves_status_ok (struct TALER_EXCHANGE_ReservesStatusHandle *rsh, const json_t *j) { json_t *history; unsigned int len; - bool kyc_ok; - bool kyc_required; - struct TALER_Amount balance; - struct TALER_Amount balance_from_history; + struct TALER_EXCHANGE_ReserveStatus rs = { + .hr.reply = j, + .hr.http_status = MHD_HTTP_OK + }; struct GNUNET_JSON_Specification spec[] = { TALER_JSON_spec_amount_any ("balance", - &balance), + &rs.details.ok.balance), GNUNET_JSON_spec_bool ("kyc_passed", - &kyc_ok), + &rs.details.ok.kyc_ok), GNUNET_JSON_spec_bool ("kyc_required", - &kyc_required), + &rs.details.ok.kyc_required), GNUNET_JSON_spec_json ("history", &history), GNUNET_JSON_spec_end () }; - struct TALER_EXCHANGE_HttpResponse hr = { - .reply = j, - .http_status = MHD_HTTP_OK - }; if (GNUNET_OK != GNUNET_JSON_parse (j, @@ -122,16 +118,16 @@ handle_reserves_status_ok (struct TALER_EXCHANGE_ReservesStatusHandle *rgh, } len = json_array_size (history); { - struct TALER_EXCHANGE_ReserveHistory *rhistory; + struct TALER_EXCHANGE_ReserveHistoryEntry *rhistory; rhistory = GNUNET_new_array (len, - struct TALER_EXCHANGE_ReserveHistory); + struct TALER_EXCHANGE_ReserveHistoryEntry); if (GNUNET_OK != - TALER_EXCHANGE_parse_reserve_history (rgh->exchange, + TALER_EXCHANGE_parse_reserve_history (rsh->exchange, history, - &rgh->reserve_pub, - balance.currency, - &balance_from_history, + &rsh->reserve_pub, + rs.details.ok.balance.currency, + NULL, len, rhistory)) { @@ -141,27 +137,13 @@ handle_reserves_status_ok (struct TALER_EXCHANGE_ReservesStatusHandle *rgh, GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } - // FIXME: status history is allowed to be - // partial, so this is NOT ok... - if (0 != - TALER_amount_cmp (&balance_from_history, - &balance)) + if (NULL != rsh->cb) { - /* exchange cannot add up balances!? */ - GNUNET_break_op (0); - TALER_EXCHANGE_free_reserve_history (rhistory, - len); - GNUNET_JSON_parse_free (spec); - return GNUNET_SYSERR; - } - if (NULL != rgh->cb) - { - rgh->cb (rgh->cb_cls, - &hr, - &balance, - len, - rhistory); - rgh->cb = NULL; + rs.details.ok.history = rhistory; + rs.details.ok.history_len = len; + rsh->cb (rsh->cb_cls, + &rs); + rsh->cb = NULL; } TALER_EXCHANGE_free_reserve_history (rhistory, len); @@ -184,75 +166,72 @@ handle_reserves_status_finished (void *cls, long response_code, const void *response) { - struct TALER_EXCHANGE_ReservesStatusHandle *rgh = cls; + struct TALER_EXCHANGE_ReservesStatusHandle *rsh = cls; const json_t *j = response; - struct TALER_EXCHANGE_HttpResponse hr = { - .reply = j, - .http_status = (unsigned int) response_code + struct TALER_EXCHANGE_ReserveStatus rs = { + .hr.reply = j, + .hr.http_status = (unsigned int) response_code }; - rgh->job = NULL; + rsh->job = NULL; switch (response_code) { case 0: - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + rs.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; case MHD_HTTP_OK: if (GNUNET_OK != - handle_reserves_status_ok (rgh, + handle_reserves_status_ok (rsh, j)) { - hr.http_status = 0; - hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + rs.hr.http_status = 0; + rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; } break; case MHD_HTTP_BAD_REQUEST: /* This should never happen, either us or the exchange is buggy (or API version conflict); just pass JSON reply to the application */ GNUNET_break (0); - hr.ec = TALER_JSON_status_error_code (j); - hr.hint = TALER_JSON_status_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_FORBIDDEN: /* This should never happen, either us or the exchange is buggy (or API version conflict); just pass JSON reply to the application */ GNUNET_break (0); - hr.ec = TALER_JSON_status_error_code (j); - hr.hint = TALER_JSON_status_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_NOT_FOUND: /* Nothing really to verify, this should never happen, we should pass the JSON reply to the application */ - hr.ec = TALER_JSON_status_error_code (j); - hr.hint = TALER_JSON_status_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: /* Server had an internal issue; we should retry, but this API leaves this to the application */ - hr.ec = TALER_JSON_status_error_code (j); - hr.hint = TALER_JSON_status_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); break; default: /* unexpected response code */ GNUNET_break_op (0); - hr.ec = TALER_JSON_status_error_code (j); - hr.hint = TALER_JSON_status_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for reserves status\n", (unsigned int) response_code, - (int) hr.ec); + (int) rs.hr.ec); break; } - if (NULL != rgh->cb) + if (NULL != rsh->cb) { - rgh->cb (rgh->cb_cls, - &hr, - NULL, - 0, - NULL); - rgh->cb = NULL; + rsh->cb (rsh->cb_cls, + &rs); + rsh->cb = NULL; } - TALER_EXCHANGE_reserves_status_cancel (rgh); + TALER_EXCHANGE_reserves_status_cancel (rsh); } @@ -263,10 +242,11 @@ TALER_EXCHANGE_reserves_status ( TALER_EXCHANGE_ReservesStatusCallback cb, void *cb_cls) { - struct TALER_EXCHANGE_ReservesStatusHandle *rgh; + struct TALER_EXCHANGE_ReservesStatusHandle *rsh; struct GNUNET_CURL_Context *ctx; CURL *eh; char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32]; + struct TALER_ReserveSignatureP reserve_sig; struct GNUNET_TIME_Timestamp ts = GNUNET_TIME_timestamp_get (); @@ -276,19 +256,19 @@ TALER_EXCHANGE_reserves_status ( GNUNET_break (0); return NULL; } - rgh = GNUNET_new (struct TALER_EXCHANGE_ReservesStatusHandle); - rgh->exchange = exchange; - rgh->cb = cb; - rgh->cb_cls = cb_cls; + rsh = GNUNET_new (struct TALER_EXCHANGE_ReservesStatusHandle); + rsh->exchange = exchange; + rsh->cb = cb; + rsh->cb_cls = cb_cls; GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv, - &rgh->reserve_pub.eddsa_pub); + &rsh->reserve_pub.eddsa_pub); { char pub_str[sizeof (struct TALER_ReservePublicKeyP) * 2]; char *end; end = GNUNET_STRINGS_data_to_string ( - &rgh->reserve_pub, - sizeof (rgh->reserve_pub), + &rsh->reserve_pub, + sizeof (rsh->reserve_pub), pub_str, sizeof (pub_str)); *end = '\0'; @@ -297,19 +277,19 @@ TALER_EXCHANGE_reserves_status ( "/reserves/%s/status", pub_str); } - rgh->url = TEAH_path_to_url (exchange, + rsh->url = TEAH_path_to_url (exchange, arg_str); - if (NULL == rgh->url) + if (NULL == rsh->url) { - GNUNET_free (rgh); + GNUNET_free (rsh); return NULL; } - eh = TALER_EXCHANGE_curl_easy_status_ (rgh->url); + eh = TALER_EXCHANGE_curl_easy_get_ (rsh->url); if (NULL == eh) { GNUNET_break (0); - GNUNET_free (rgh->url); - GNUNET_free (rgh); + GNUNET_free (rsh->url); + GNUNET_free (rsh); return NULL; } TALER_wallet_reserve_status_sign (ts, @@ -318,46 +298,45 @@ TALER_EXCHANGE_reserves_status ( { json_t *status_obj = GNUNET_JSON_PACK ( GNUNET_JSON_pack_timestamp ("request_timestamp", - &ts), + ts), GNUNET_JSON_pack_data_auto ("reserve_sig", &reserve_sig)); if (GNUNET_OK != - TALER_curl_easy_post (&rgh->post_ctx, + TALER_curl_easy_post (&rsh->post_ctx, eh, status_obj)) - ) - { - GNUNET_break (0); - curl_easy_cleanup (eh); - json_decref (status_obj); - GNUNET_free (rgh->url); - GNUNET_free (rgh); - return NULL; - } + { + GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (status_obj); + GNUNET_free (rsh->url); + GNUNET_free (rsh); + return NULL; + } + json_decref (status_obj); } ctx = TEAH_handle_to_context (exchange); - rgh->job = GNUNET_CURL_job_add (ctx, + rsh->job = GNUNET_CURL_job_add (ctx, eh, &handle_reserves_status_finished, - rgh); - return rgh; + rsh); + return rsh; } void TALER_EXCHANGE_reserves_status_cancel ( - struct TALER_EXCHANGE_ReservesStatusHandle *rgh) + struct TALER_EXCHANGE_ReservesStatusHandle *rsh) { - if (NULL != rgh->job) + if (NULL != rsh->job) { - GNUNET_CURL_job_cancel (rgh->job); - rgh->job = NULL; + GNUNET_CURL_job_cancel (rsh->job); + rsh->job = NULL; } - TALER_curl_easy_post_finished (&rgh->post_ctx); - GNUNET_free (rgh->url); - GNUNET_free (rgh); + TALER_curl_easy_post_finished (&rsh->post_ctx); + GNUNET_free (rsh->url); + GNUNET_free (rsh); } diff --git a/src/lib/exchange_api_withdraw2.c b/src/lib/exchange_api_withdraw2.c index ade6fe8a7..bc138db0f 100644 --- a/src/lib/exchange_api_withdraw2.c +++ b/src/lib/exchange_api_withdraw2.c @@ -177,14 +177,14 @@ reserve_withdraw_payment_required ( total incoming and outgoing amounts */ len = json_array_size (history); { - struct TALER_EXCHANGE_ReserveHistory *rhistory; + struct TALER_EXCHANGE_ReserveHistoryEntry *rhistory; /* Use heap allocation as "len" may be very big and thus this may not fit on the stack. Use "GNUNET_malloc_large" as a malicious exchange may theoretically try to crash us by giving a history that does not fit into our memory. */ rhistory = GNUNET_malloc_large ( - sizeof (struct TALER_EXCHANGE_ReserveHistory) + sizeof (struct TALER_EXCHANGE_ReserveHistoryEntry) * len); if (NULL == rhistory) { |