aboutsummaryrefslogtreecommitdiff
path: root/src/authorization/anastasis-helper-authorization-iban.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/authorization/anastasis-helper-authorization-iban.c')
-rw-r--r--src/authorization/anastasis-helper-authorization-iban.c60
1 files changed, 34 insertions, 26 deletions
diff --git a/src/authorization/anastasis-helper-authorization-iban.c b/src/authorization/anastasis-helper-authorization-iban.c
index 946b008..066b4cb 100644
--- a/src/authorization/anastasis-helper-authorization-iban.c
+++ b/src/authorization/anastasis-helper-authorization-iban.c
@@ -25,13 +25,14 @@
25 * - needs to add DB triggers to notify main service of inbound activity 25 * - needs to add DB triggers to notify main service of inbound activity
26 */ 26 */
27#include "platform.h" 27#include "platform.h"
28#include "anastasis_eufin_lib.h"
29#include "anastasis_database_lib.h"
30#include "anastasis_util_lib.h"
31#include <taler/taler_json_lib.h>
28#include <gnunet/gnunet_util_lib.h> 32#include <gnunet/gnunet_util_lib.h>
29#include <jansson.h> 33#include <jansson.h>
30#include <pthread.h> 34#include <pthread.h>
31#include <microhttpd.h> 35#include <microhttpd.h>
32#include <taler/taler_json_lib.h>
33#include <XXX_bank_service.h>
34#include "anastasis_db_lib.h"
35 36
36/** 37/**
37 * How long to wait for an HTTP reply if there 38 * How long to wait for an HTTP reply if there
@@ -40,19 +41,24 @@
40#define LONGPOLL_TIMEOUT GNUNET_TIME_UNIT_HOURS 41#define LONGPOLL_TIMEOUT GNUNET_TIME_UNIT_HOURS
41 42
42/** 43/**
44 * How long to wait between HTTP requests?
45 */
46#define RETRY_TIMEOUT GNUNET_TIME_UNIT_MINUTES
47
48/**
43 * Authentication data needed to access the account. 49 * Authentication data needed to access the account.
44 */ 50 */
45static struct BANK_AccountInfo *auth; 51static struct ANASTASIS_EUFIN_AuthenticationData auth;
46 52
47/** 53/**
48 * Bank account payto://-URI this process is monitoring. 54 * Bank account payto://-URI this process is monitoring.
49 */ 55 */
50static struct credit_account_uri; 56static char *credit_account_uri;
51 57
52/** 58/**
53 * Active request for history. 59 * Active request for history.
54 */ 60 */
55static struct BANK_CreditHistoryHandle *hh; 61static struct ANASTASIS_EUFIN_CreditHistoryHandle *hh;
56 62
57/** 63/**
58 * Handle to the context for interacting with the bank. 64 * Handle to the context for interacting with the bank.
@@ -92,6 +98,12 @@ static struct GNUNET_TIME_Relative idle_sleep_interval;
92static int global_ret; 98static int global_ret;
93 99
94/** 100/**
101 * Run in test-mode, do not background, only import currently
102 * pending transactions.
103 */
104static int test_mode;
105
106/**
95 * Current task waiting for execution, if any. 107 * Current task waiting for execution, if any.
96 */ 108 */
97static struct GNUNET_SCHEDULER_Task *task; 109static struct GNUNET_SCHEDULER_Task *task;
@@ -108,7 +120,7 @@ shutdown_task (void *cls)
108 (void) cls; 120 (void) cls;
109 if (NULL != hh) 121 if (NULL != hh)
110 { 122 {
111 BANK_credit_history_cancel (hh); 123 ANASTASIS_EUFIN_credit_history_cancel (hh);
112 hh = NULL; 124 hh = NULL;
113 } 125 }
114 if (NULL != ctx) 126 if (NULL != ctx)
@@ -157,11 +169,10 @@ history_cb (void *cls,
157 unsigned int http_status, 169 unsigned int http_status,
158 enum TALER_ErrorCode ec, 170 enum TALER_ErrorCode ec,
159 uint64_t serial_id, 171 uint64_t serial_id,
160 const struct BANK_CreditDetails *details) 172 const struct ANASTASIS_EUFIN_CreditDetails *details)
161{ 173{
162 enum GNUNET_DB_QueryStatus qs; 174 enum GNUNET_DB_QueryStatus qs;
163 175
164 (void) json;
165 if (NULL == details) 176 if (NULL == details)
166 { 177 {
167 hh = NULL; 178 hh = NULL;
@@ -175,9 +186,9 @@ history_cb (void *cls,
175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
176 "End of list.\n"); 187 "End of list.\n");
177 GNUNET_assert (NULL == task); 188 GNUNET_assert (NULL == task);
178 task = GNUNET_SCHEDULER_add_at (delayed_until, 189 task = GNUNET_SCHEDULER_add_delayed (idle_sleep_interval,
179 &find_transfers, 190 &find_transfers,
180 NULL); 191 NULL);
181 return GNUNET_OK; /* will be ignored anyway */ 192 return GNUNET_OK; /* will be ignored anyway */
182 } 193 }
183 if (serial_id <= latest_row_off) 194 if (serial_id <= latest_row_off)
@@ -200,7 +211,7 @@ history_cb (void *cls,
200 &details->amount, 211 &details->amount,
201 details->debit_account_uri, 212 details->debit_account_uri,
202 details->credit_account_uri, 213 details->credit_account_uri,
203 details->execution_time); 214 details->execution_date);
204 switch (qs) 215 switch (qs)
205 { 216 {
206 case GNUNET_DB_STATUS_HARD_ERROR: 217 case GNUNET_DB_STATUS_HARD_ERROR:
@@ -234,20 +245,18 @@ history_cb (void *cls,
234static void 245static void
235find_transfers (void *cls) 246find_transfers (void *cls)
236{ 247{
237 enum GNUNET_DB_QueryStatus qs;
238
239 (void) cls; 248 (void) cls;
240 task = NULL; 249 task = NULL;
241 GNUNET_assert (NULL == hh); 250 GNUNET_assert (NULL == hh);
242 hh = BANK_credit_history (ctx, 251 hh = ANASTASIS_EUFIN_credit_history (ctx,
243 &auth, 252 &auth,
244 latest_row_off, 253 latest_row_off,
245 1024, 254 1024,
246 test_mode 255 test_mode
247 ? GNUNET_TIME_UNIT_ZERO 256 ? GNUNET_TIME_UNIT_ZERO
248 : LONGPOLL_TIMEOUT, 257 : LONGPOLL_TIMEOUT,
249 &history_cb, 258 &history_cb,
250 NULL); 259 NULL);
251 if (NULL == hh) 260 if (NULL == hh)
252 { 261 {
253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 262 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -310,8 +319,7 @@ run (void *cls,
310 GNUNET_break (0); 319 GNUNET_break (0);
311 return; 320 return;
312 } 321 }
313 latest_row_off = FIXME; // need new DB function! 322 idle_sleep_interval = RETRY_TIMEOUT;
314
315 task = GNUNET_SCHEDULER_add_now (&find_transfers, 323 task = GNUNET_SCHEDULER_add_now (&find_transfers,
316 NULL); 324 NULL);
317} 325}