diff options
Diffstat (limited to 'src/bank-lib/bank_api_debit.c')
-rw-r--r-- | src/bank-lib/bank_api_debit.c | 81 |
1 files changed, 44 insertions, 37 deletions
diff --git a/src/bank-lib/bank_api_debit.c b/src/bank-lib/bank_api_debit.c index 0e1ec0c5d..8cca0cc50 100644 --- a/src/bank-lib/bank_api_debit.c +++ b/src/bank-lib/bank_api_debit.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of TALER | 2 | This file is part of TALER |
3 | Copyright (C) 2017--2020 Taler Systems SA | 3 | Copyright (C) 2017--2021 Taler Systems SA |
4 | 4 | ||
5 | TALER is free software; you can redistribute it and/or | 5 | TALER is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU General Public License | 6 | modify it under the terms of the GNU General Public License |
@@ -97,9 +97,9 @@ parse_account_history (struct TALER_BANK_DebitHistoryHandle *hh, | |||
97 | GNUNET_JSON_spec_fixed_auto ("wtid", | 97 | GNUNET_JSON_spec_fixed_auto ("wtid", |
98 | &td.wtid), | 98 | &td.wtid), |
99 | GNUNET_JSON_spec_string ("credit_account", | 99 | GNUNET_JSON_spec_string ("credit_account", |
100 | &td.credit_account_url), | 100 | &td.credit_account_uri), |
101 | GNUNET_JSON_spec_string ("debit_account", | 101 | GNUNET_JSON_spec_string ("debit_account", |
102 | &td.debit_account_url), | 102 | &td.debit_account_uri), |
103 | GNUNET_JSON_spec_string ("exchange_base_url", | 103 | GNUNET_JSON_spec_string ("exchange_base_url", |
104 | &td.exchange_base_url), | 104 | &td.exchange_base_url), |
105 | GNUNET_JSON_spec_end () | 105 | GNUNET_JSON_spec_end () |
@@ -214,35 +214,19 @@ handle_debit_history_finished (void *cls, | |||
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
217 | /** | ||
218 | * Request the debit history of the exchange's bank account. | ||
219 | * | ||
220 | * @param ctx curl context for the event loop | ||
221 | * @param auth authentication data to use | ||
222 | * @param start_row from which row on do we want to get results, | ||
223 | * use UINT64_MAX for the latest; exclusive | ||
224 | * @param num_results how many results do we want; | ||
225 | * negative numbers to go into the past, positive numbers | ||
226 | * to go into the future starting at @a start_row; | ||
227 | * must not be zero. | ||
228 | * @param hres_cb the callback to call with the transaction | ||
229 | * history | ||
230 | * @param hres_cb_cls closure for the above callback | ||
231 | * @return NULL if the inputs are invalid (i.e. zero value for | ||
232 | * @e num_results). In this case, the callback is not | ||
233 | * called. | ||
234 | */ | ||
235 | struct TALER_BANK_DebitHistoryHandle * | 217 | struct TALER_BANK_DebitHistoryHandle * |
236 | TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx, | 218 | TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx, |
237 | const struct TALER_BANK_AuthenticationData *auth, | 219 | const struct TALER_BANK_AuthenticationData *auth, |
238 | uint64_t start_row, | 220 | uint64_t start_row, |
239 | int64_t num_results, | 221 | int64_t num_results, |
222 | struct GNUNET_TIME_Relative timeout, | ||
240 | TALER_BANK_DebitHistoryCallback hres_cb, | 223 | TALER_BANK_DebitHistoryCallback hres_cb, |
241 | void *hres_cb_cls) | 224 | void *hres_cb_cls) |
242 | { | 225 | { |
243 | char url[128]; | 226 | char url[128]; |
244 | struct TALER_BANK_DebitHistoryHandle *hh; | 227 | struct TALER_BANK_DebitHistoryHandle *hh; |
245 | CURL *eh; | 228 | CURL *eh; |
229 | unsigned long long tms; | ||
246 | 230 | ||
247 | if (0 == num_results) | 231 | if (0 == num_results) |
248 | { | 232 | { |
@@ -250,20 +234,43 @@ TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx, | |||
250 | return NULL; | 234 | return NULL; |
251 | } | 235 | } |
252 | 236 | ||
237 | tms = (unsigned long long) (timeout.rel_value_us | ||
238 | / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us); | ||
253 | if ( ( (UINT64_MAX == start_row) && | 239 | if ( ( (UINT64_MAX == start_row) && |
254 | (0 > num_results) ) || | 240 | (0 > num_results) ) || |
255 | ( (0 == start_row) && | 241 | ( (0 == start_row) && |
256 | (0 < num_results) ) ) | 242 | (0 < num_results) ) ) |
257 | GNUNET_snprintf (url, | 243 | { |
258 | sizeof (url), | 244 | if ( (0 < num_results) && |
259 | "history/outgoing?delta=%lld", | 245 | (! GNUNET_TIME_relative_is_zero (timeout)) ) |
260 | (long long) num_results); | 246 | GNUNET_snprintf (url, |
247 | sizeof (url), | ||
248 | "history/outgoing?delta=%lld&long_poll_ms=%llu", | ||
249 | (long long) num_results, | ||
250 | tms); | ||
251 | else | ||
252 | GNUNET_snprintf (url, | ||
253 | sizeof (url), | ||
254 | "history/outgoing?delta=%lld", | ||
255 | (long long) num_results); | ||
256 | } | ||
261 | else | 257 | else |
262 | GNUNET_snprintf (url, | 258 | { |
263 | sizeof (url), | 259 | if ( (0 < num_results) && |
264 | "history/outgoing?delta=%lld&start=%llu", | 260 | (! GNUNET_TIME_relative_is_zero (timeout)) ) |
265 | (long long) num_results, | 261 | GNUNET_snprintf (url, |
266 | (unsigned long long) start_row); | 262 | sizeof (url), |
263 | "history/outgoing?delta=%lld&start=%llu&long_poll_ms=%llu", | ||
264 | (long long) num_results, | ||
265 | (unsigned long long) start_row, | ||
266 | tms); | ||
267 | else | ||
268 | GNUNET_snprintf (url, | ||
269 | sizeof (url), | ||
270 | "history/outgoing?delta=%lld&start=%llu", | ||
271 | (long long) num_results, | ||
272 | (unsigned long long) start_row); | ||
273 | } | ||
267 | hh = GNUNET_new (struct TALER_BANK_DebitHistoryHandle); | 274 | hh = GNUNET_new (struct TALER_BANK_DebitHistoryHandle); |
268 | hh->hcb = hres_cb; | 275 | hh->hcb = hres_cb; |
269 | hh->hcb_cls = hres_cb_cls; | 276 | hh->hcb_cls = hres_cb_cls; |
@@ -295,6 +302,13 @@ TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx, | |||
295 | curl_easy_cleanup (eh); | 302 | curl_easy_cleanup (eh); |
296 | return NULL; | 303 | return NULL; |
297 | } | 304 | } |
305 | if (0 != tms) | ||
306 | { | ||
307 | GNUNET_break (CURLE_OK == | ||
308 | curl_easy_setopt (eh, | ||
309 | CURLOPT_TIMEOUT_MS, | ||
310 | (long) tms)); | ||
311 | } | ||
298 | hh->job = GNUNET_CURL_job_add2 (ctx, | 312 | hh->job = GNUNET_CURL_job_add2 (ctx, |
299 | eh, | 313 | eh, |
300 | NULL, | 314 | NULL, |
@@ -304,13 +318,6 @@ TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx, | |||
304 | } | 318 | } |
305 | 319 | ||
306 | 320 | ||
307 | /** | ||
308 | * Cancel a history request. This function cannot be | ||
309 | * used on a request handle if a response is already | ||
310 | * served for it. | ||
311 | * | ||
312 | * @param hh the history request handle | ||
313 | */ | ||
314 | void | 321 | void |
315 | TALER_BANK_debit_history_cancel (struct TALER_BANK_DebitHistoryHandle *hh) | 322 | TALER_BANK_debit_history_cancel (struct TALER_BANK_DebitHistoryHandle *hh) |
316 | { | 323 | { |