commit 2db37d200729d7d0e665c6c974fa92349400d84a
parent ba72783dfaa0a86792df2c5adce108d5e51fd1b1
Author: Tellenbach Reto <tellr1@bfh.ch>
Date: Mon, 8 Jun 2026 11:06:39 +0200
[wip] State-logic: Scan QR-code, longpoll request
Diffstat:
3 files changed, 49 insertions(+), 13 deletions(-)
diff --git a/src/lib/bank_api_get_withdrawals.c b/src/lib/bank_api_get_withdrawals.c
@@ -216,7 +216,7 @@ TALER_BANK_get_withdrawal ( struct GNUNET_CURL_Context *ctx,
const char *wopid,
TALER_BANK_WithdrawalCallback withdrawals_cb,
void *withdrawals_cb_cls,
- const unsigned long *timeout_ms)
+ const unsigned long timeout_ms)
{
struct TALER_BANK_GetWithdrawalHandle *withdrawal;
char *url;
@@ -229,12 +229,12 @@ TALER_BANK_get_withdrawal ( struct GNUNET_CURL_Context *ctx,
GNUNET_asprintf(&url,
"withdrawals/%s",
wopid);
- if (NULL != timeout_ms)
+ if (0 != timeout_ms)
{
withdrawal->job_url = TALER_url_join(base_url,
url,
"timeout_ms",
- *timeout_ms,
+ timeout_ms,
NULL);
}
else
@@ -277,7 +277,7 @@ TALER_BANK_get_withdrawal ( struct GNUNET_CURL_Context *ctx,
void
-TALER_BANK_get_withdrawals_cancel ( struct TALER_BANK_GetWithdrawalHandle *withdrawal)
+TALER_BANK_get_withdrawal_cancel ( struct TALER_BANK_GetWithdrawalHandle *withdrawal)
{
if(NULL != withdrawal->job)
{
diff --git a/src/lib/bank_api_get_withdrawals.h b/src/lib/bank_api_get_withdrawals.h
@@ -136,7 +136,7 @@ struct TALER_BANK_GetWithdrawalHandle;
* @param withdrawal_cb callback
* @param withdrawal_cb_cls callback context
* @param timeout_ms timeout to long-polling,
- * ignored when NULL, therfor no long-poll
+ * ignored when 0, therfor no long-poll
* @return NULL on failure
*/
struct TALER_BANK_GetWithdrawalHandle *
@@ -145,7 +145,7 @@ TALER_BANK_get_withdrawal ( struct GNUNET_CURL_Context *ctx,
const char *wopid,
TALER_BANK_WithdrawalCallback withdrawals_cb,
void *withdrawals_cb_cls,
- const unsigned long *timeout_ms);
+ const unsigned long timeout_ms);
/**
diff --git a/src/taler-digitizer.c b/src/taler-digitizer.c
@@ -31,6 +31,7 @@
#include "lib/bank_api_get_config.h"
#include "lib/bank_api_get_accounts.h"
#include "lib/bank_api_post_accounts_withdrawals.h"
+#include "lib/bank_api_get_withdrawals.h"
#include "digitizer_display.h"
@@ -43,7 +44,7 @@
#define FRAMEBUFFER_SIZE 256
#define PATH_QR_SHOW "/ext/QRshow"
-#define SCAN_QR_TIMEOUT_SECONDS 30
+#define SCAN_QR_TIMEOUT_SECONDS 100
/**
* Global return value
@@ -161,7 +162,7 @@ static struct TALER_Amount cfg_ba_min_denomination;
/**
- * Handle to the context for interacting with the bank.
+ * Handle to the context for http requests
*/
static struct GNUNET_CURL_Context *curl_ctx;
@@ -363,6 +364,7 @@ static void
on_get_config_done (void *cls,
const struct TALER_BANK_ConfigResponse *vr)
{
+ TALER_LOG_DEBUG ("Callback of GET /config\n");
(void) cls;
get_config_handle = NULL;
@@ -481,10 +483,34 @@ on_post_accounts_withdrawal_done(void *cls,
/**
+ * callback of accounts withdrawal request
+ * used in the QR Create state
+ */
+static void
+on_get_withdrawal_selected_done(void *cls,
+ const struct TALER_BANK_WithdrawalResponse *vr)
+{
+ TALER_LOG_DEBUG ("Callback of withdrawal/$WITHDRAWAL_ID\n");
+
+ (void) cls;
+ if(0 != strcasecmp("active", vr->details.ok.acc.status))
+ {
+ TALER_LOG_WARNING("QR-code was not scanned in time\n");
+ state = DIGITIZER_STATE_CANCEL_WITHDRAWAL;
+ GNUNET_SCHEDULER_add_now(state_controller_task,NULL);
+ }
+
+ state = DIGITIZER_STATE_SCAN_QR;
+ GNUNET_SCHEDULER_add_now(state_controller_task,NULL);
+ return;
+}
+
+/**
* Timeout when QR is shown
* SCAN_QR_TIMEOUT_SECONDS without been scanned
* used in the ScanQR state
*/
+/*
static void
ScanQR_timeout(void *cls)
{
@@ -496,6 +522,7 @@ ScanQR_timeout(void *cls)
GNUNET_SCHEDULER_add_now(state_controller_task,NULL);
return;
}
+*/
/**
* @brief Cleanup when no task is scheduled anymore
@@ -539,7 +566,7 @@ shutdown_task (void *cls)
*/
static void Init_state_task(void *cls)
{
- TALER_LOG_DEBUG ("start INIT state task\n");
+ TALER_LOG_DEBUG ("INIT state\n");
const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
@@ -944,8 +971,8 @@ static void TerminalError_state_task(void *cls)
*/
static void Idle_state_task(void *cls)
{
+ TALER_LOG_DEBUG("Idle state\n");
(void)cls;
-
get_accounts_handle = TALER_BANK_get_accounts (curl_ctx,
cfg_bank_base_url,
cfg_bank_account_username,
@@ -961,6 +988,7 @@ static void Idle_state_task(void *cls)
*/
static void CreateQR_state_task(void *cls)
{
+ TALER_LOG_DEBUG("CreateQR state\n");
(void)cls;
struct TALER_BANK_AccountCreateWithdrawalRequest *acwr;
acwr = GNUNET_new(struct TALER_BANK_AccountCreateWithdrawalRequest);
@@ -993,9 +1021,10 @@ static void CreateQR_state_task(void *cls)
*/
static void ScanQR_state_task(void *cls)
{
+ TALER_LOG_DEBUG ("ScanQR state\n");
(void)cls;
- struct GNUNET_TIME_Relative delay;
- delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,SCAN_QR_TIMEOUT_SECONDS);
+ //struct GNUNET_TIME_Relative delay;
+ //delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,SCAN_QR_TIMEOUT_SECONDS);
if(GNUNET_OK != run_qr_show(SCAN_QR_TIMEOUT_SECONDS))
{
TALER_LOG_ERROR("run_qr_show failed\n");
@@ -1004,8 +1033,15 @@ static void ScanQR_state_task(void *cls)
GNUNET_SCHEDULER_add_now(state_controller_task,NULL);
}
+ TALER_BANK_get_withdrawal(curl_ctx,
+ cfg_bank_base_url,
+ state_ctx->wi.withdrawal_id,
+ on_get_withdrawal_selected_done,
+ NULL,
+ SCAN_QR_TIMEOUT_SECONDS);
- GNUNET_SCHEDULER_add_delayed(delay,ScanQR_timeout,NULL);
+ state = DIGITIZER_STATE_CANCEL_WITHDRAWAL;
+ GNUNET_SCHEDULER_add_now(state_controller_task,NULL);
return;
}