[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-mdb] branch master updated: fix
From: |
gnunet |
Subject: |
[taler-taler-mdb] branch master updated: fix |
Date: |
Thu, 02 Jan 2020 20:01:45 +0100 |
This is an automated email from the git hooks/post-receive script.
marco-boss pushed a commit to branch master
in repository taler-mdb.
The following commit(s) were added to refs/heads/master by this push:
new dca6cd0 fix
dca6cd0 is described below
commit dca6cd094d195666aaed42b558d56f15f4f8c9af
Author: Boss Marco <address@hidden>
AuthorDate: Thu Jan 2 20:01:36 2020 +0100
fix
---
src/main.c | 300 ++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 156 insertions(+), 144 deletions(-)
diff --git a/src/main.c b/src/main.c
index 9eadbf4..fb15fc7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -70,7 +70,8 @@ along with
#define _(s) (s)
/* FIXME Adjusted Time out because low internet connection at 36C3 */
-#define BACKEND_POLL_TIMEOUT GNUNET_TIME_relative_multiply (
GNUNET_TIME_UNIT_MINUTES, 5)
+#define BACKEND_POLL_TIMEOUT GNUNET_TIME_relative_multiply ( \
+ GNUNET_TIME_UNIT_MINUTES, 5)
#define NFC_FAILURE_RETRY_FREQ GNUNET_TIME_UNIT_SECONDS
@@ -218,9 +219,12 @@ along with
/* Display Request for Sold Out product */
#define READER_DISPLAY_REQUEST "02"
#define READER_DISPLAY_REQUEST_TIME "32"
-#define READER_DISPLAY_SOLD_OUT
"202020202020202050726f6475637420736f6c64206f75742020202020202020"
-#define READER_DISPLAY_INTERNAL_ERROR
"202020496e7465726e616c204572726f72202d2054727920416761696e202020i"
-#define READER_DISPLAY_BACKEND_NOT_REACHABLE
"20202020204261636b656e64206e6f7420726561636861626c65202020202020"
+#define READER_DISPLAY_SOLD_OUT \
+ "202020202020202050726f6475637420736f6c64206f75742020202020202020"
+#define READER_DISPLAY_INTERNAL_ERROR \
+ "202020496e7465726e616c204572726f72202d2054727920416761696e202020i"
+#define READER_DISPLAY_BACKEND_NOT_REACHABLE \
+ "20202020204261636b656e64206e6f7420726561636861626c65202020202020"
/* Unused reader commands */
#define READER_SESSION_CANCEL_REQUEST "04"
@@ -231,12 +235,12 @@ along with
*/
struct MdbBlock
{
- /**
+ /**
* Data containing a mdb command or the data of an mdb command
*/
uint8_t *bin;
-
- /**
+
+ /**
* Size of the data referenced by *bin
*/
size_t bin_size;
@@ -248,18 +252,18 @@ struct MdbBlock
*/
struct MdbCommand
{
- /**
- * Name of the command for the logging
+ /**
+ * Name of the command for the logging
*/
- const char *name;
+ const char *name;
/**
* Data block containing the information about the mdb command
*/
struct MdbBlock cmd;
-
- /**
- * Data block containing the information about the mdb command data
+
+ /**
+ * Data block containing the information about the mdb command data
*/
struct MdbBlock data;
};
@@ -379,38 +383,38 @@ struct PaymentActivity
*/
struct MdbHandle
{
-
- /**
+
+ /**
* Buffer to save the received data from UART
*/
uint8_t rxBuffer[MAX_SIZE_RX_BUFFER];
- /**
+ /**
* Buffer to save the data to send via UART
*/
uint8_t txBuffer[MAX_SIZE_TX_BUFFER];
- /**
- * Reference to scheduler task to read from UART
+ /**
+ * Reference to scheduler task to read from UART
*/
struct GNUNET_SCHEDULER_Task *rtask;
-
- /**
- * Reference to scheduler task to write to UART
+
+ /**
+ * Reference to scheduler task to write to UART
*/
struct GNUNET_SCHEDULER_Task *wtask;
- /**
- * Reference to the mdb cmd which will be sent next
+ /**
+ * Reference to the mdb cmd which will be sent next
*/
const struct MdbCommand *cmd;
-
- /**
- * Reference to the mdb cmd which was sent last
+
+ /**
+ * Reference to the mdb cmd which was sent last
*/
const struct MdbCommand *last_cmd;
- /**
+ /**
* Current read offset in @e rxBuffer.
*/
size_t rx_off;
@@ -426,23 +430,23 @@ struct MdbHandle
*/
size_t tx_len;
- /**
+ /**
* Time out to wait for an acknoweledge received via the mdb bus
*/
struct GNUNET_TIME_Absolute ack_timeout;
- /**
+ /**
* Backup of the config data to restore the configuration of the UART before
closing it
*/
struct termios uart_opts_backup;
- /**
- * Indicates if a vend session is running or not
+ /**
+ * Indicates if a vend session is running or not
*/
int session_running;
- /**
- * File descriptor to the UART device file
+ /**
+ * File descriptor to the UART device file
*/
int uartfd;
@@ -490,8 +494,8 @@ struct Display
*/
struct CancelButton
{
- /**
- * File descriptor to read the state of the cancel button gpio pin
+ /**
+ * File descriptor to read the state of the cancel button gpio pin
*/
int cancelbuttonfd;
};
@@ -644,7 +648,7 @@ static struct MdbCommand revalueApproved;
static struct MdbCommand revalueAmount;
/**
- * Send NACK
+ * Send NACK
*/
static struct MdbCommand readerNACK;
@@ -885,11 +889,11 @@ cleanup_payment (struct PaymentActivity *pa)
nfc_abort_command (pa->pnd);
nfc_close (pa->pnd);
}
- if (NULL != cancelbutton_task)
- {
- GNUNET_SCHEDULER_cancel (cancelbutton_task);
- cancelbutton_task = NULL;
- }
+ if (NULL != cancelbutton_task)
+ {
+ GNUNET_SCHEDULER_cancel (cancelbutton_task);
+ cancelbutton_task = NULL;
+ }
if (NULL != pa->po)
TALER_MERCHANT_proposal_cancel (pa->po);
if (NULL != pa->cpo)
@@ -990,7 +994,7 @@ shutdown_task (void *cls)
cleanup_payment (payment_activity);
payment_activity = NULL;
}
- if (NULL != cancelbutton_task)
+ if (NULL != cancelbutton_task)
{
GNUNET_SCHEDULER_cancel (cancelbutton_task);
cancelbutton_task = NULL;
@@ -1755,26 +1759,32 @@ cancel_button_pressed (void *cls)
read (cancelButton.cancelbuttonfd, &value, 1);
lseek (cancelButton.cancelbuttonfd, 0, SEEK_SET);
- if ( '1' == value )
+ if (NULL != payment_activity)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Cancel button pressed, canceling current order\n");
- if (GNUNET_NO == payment_activity->paid)
+ if ('1' == value)
{
- mdb.cmd = &denyVend;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Cancel button pressed, canceling current order\n");
+ if (GNUNET_NO == payment_activity->paid)
+ {
+ /* The current payment was not paid already, deny it */
+ mdb.cmd = &denyVend;
+ }
+ else
+ {
+ /* The order was paid and if we know this, then it is also yielded,
+ * just end the current session */
+ mdb.cmd = &endSession;
+ mdb.session_running = GNUNET_NO;
+ }
+ run_mdb_event_loop ();
+ cleanup_payment (payment_activity);
+ payment_activity = NULL;
}
else
{
- mdb.cmd = &endSession;
- mdb.session_running = GNUNET_NO;
+ start_read_cancel_button ();
}
- run_mdb_event_loop ();
- cleanup_payment (payment_activity);
- payment_activity = NULL;
- }
- else
- {
- start_read_cancel_button ();
}
}
@@ -1826,10 +1836,11 @@ start_read_cancel_button ()
struct GNUNET_DISK_FileHandle fh = { cancelButton.cancelbuttonfd };
GNUNET_assert (NULL == cancelbutton_task);
- cancelbutton_task = GNUNET_SCHEDULER_add_read_file
(GNUNET_TIME_UNIT_FOREVER_REL,
- &fh,
- &cancel_button_pressed,
- NULL);
+ cancelbutton_task = GNUNET_SCHEDULER_add_read_file (
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &fh,
+ &cancel_button_pressed,
+ NULL);
}
/**
@@ -1952,12 +1963,12 @@ handle_ack ()
mdb.session_running = GNUNET_NO;
mdb.cmd = &endSession;
}
- if (&readerDisplaySoldOut == mdb.last_cmd)
- mdb.cmd = &denyVend;
- if (&readerDisplayInternalError == mdb.last_cmd)
- mdb.cmd = &denyVend;
- if (&readerDisplayBackendNotReachable == mdb.last_cmd)
- mdb.cmd = &denyVend;
+ if (&readerDisplaySoldOut == mdb.last_cmd)
+ mdb.cmd = &denyVend;
+ if (&readerDisplayInternalError == mdb.last_cmd)
+ mdb.cmd = &denyVend;
+ if (&readerDisplayBackendNotReachable == mdb.last_cmd)
+ mdb.cmd = &denyVend;
mdb.last_cmd = NULL;
/* Cause the write-task to be re-scheduled now */
if (NULL != mdb.wtask)
@@ -1979,8 +1990,8 @@ handle_command (const char *hex,
size_t hex_len)
{
unsigned int cmd;
- unsigned int tmp = 0;
- uint32_t chkSum;
+ unsigned int tmp = 0;
+ uint32_t chkSum;
/* if the received command is 0 or not a multiple of 2 we cannot parse it */
if (0 == hex_len)
@@ -1995,7 +2006,7 @@ handle_command (const char *hex,
return;
}
/* convert the received 2 bytes from ASCII to hex */
- if (1 != sscanf (hex,
+ if (1 != sscanf (hex,
"%2X",
&cmd))
{
@@ -2006,8 +2017,8 @@ handle_command (const char *hex,
GNUNET_break_op (0);
return;
}
-
- /* parse the first byte (cmd) and the second byte (subcmd) */
+
+ /* parse the first byte (cmd) and the second byte (subcmd) */
switch (cmd)
{
case VMC_VEND:
@@ -2035,34 +2046,34 @@ handle_command (const char *hex,
{
case VMC_VEND_REQUEST:
{
-
- /* Calculate the checksum and check it */
- chkSum = cmd;
-
- for( size_t offset = 1; offset < ((hex_len /
2)); offset++ ){
- chkSum += tmp;
- if (1 != sscanf (hex + (2 *
offset),
- "%2X",
- &tmp))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Received non-HEX input `%.*s'\n",
- (int) hex_len,
- hex);
- GNUNET_break_op (0);
- return;
- }
- }
- if ( ((uint8_t) (chkSum & 0xFF)) != tmp
)
- {
- mdb.cmd =
&readerDisplayInternalError;
- GNUNET_log
(GNUNET_ERROR_TYPE_WARNING,
- "Received command with wrong
checksum `%.*s'\n",
- (int) hex_len,
- hex);
- break;
-
- }
+
+ /* Calculate the checksum and check it */
+ chkSum = cmd;
+
+ for ( size_t offset = 1; offset < ((hex_len / 2)); offset++ ) {
+ chkSum += tmp;
+ if (1 != sscanf (hex + (2 * offset),
+ "%2X",
+ &tmp))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Received non-HEX input `%.*s'\n",
+ (int) hex_len,
+ hex);
+ GNUNET_break_op (0);
+ return;
+ }
+ }
+ if ( ((uint8_t) (chkSum & 0xFF)) != tmp )
+ {
+ mdb.cmd = &readerDisplayInternalError;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Received command with wrong checksum `%.*s'\n",
+ (int) hex_len,
+ hex);
+ break;
+
+ }
unsigned int product;
GNUNET_break (GNUNET_YES == mdb.session_running);
@@ -2186,7 +2197,7 @@ handle_command (const char *hex,
break;
}
case VMC_CONF:
- {
+ {
unsigned int subcmd;
if (4 > hex_len)
@@ -2209,11 +2220,11 @@ handle_command (const char *hex,
{
case VMC_READER_CONF:
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Received request for configuration via MDB\n");
- mdb.cmd = &readerConfigData;
- break;
-
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received request for configuration via MDB\n");
+ mdb.cmd = &readerConfigData;
+ break;
+
}
case VMC_SETUP_MAX_MIN_PRICES:
{
@@ -2234,12 +2245,12 @@ handle_command (const char *hex,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received POLL from MDB (ignored)\n");
break;
- case VMC_CMD_RESET:
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received RESET from MDB (ignored)\n");
- break;
- }
+ case VMC_CMD_RESET:
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received RESET from MDB (ignored)\n");
+ break;
+ }
case VMC_READER:
{
unsigned int subcmd;
@@ -2269,17 +2280,17 @@ handle_command (const char *hex,
payment_activity = NULL;
}
for (unsigned int i = 0; i < products_length; i++)
- {
- if ( (sold_out_enabled) &&
- (0 != strcmp (products[i].description,
- "empty")) &&
- (GNUNET_YES ==
products[i].sold_out) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Resetting sold out state of product %s\n",
- products[i].description);
- products[i].sold_out = GNUNET_NO;
- }
+ {
+ if ( (sold_out_enabled) &&
+ (0 != strcmp (products[i].description,
+ "empty")) &&
+ (GNUNET_YES == products[i].sold_out) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Resetting sold out state of product %s\n",
+ products[i].description);
+ products[i].sold_out = GNUNET_NO;
+ }
}
break;
case VMC_READER_ENABLE:
@@ -2500,15 +2511,15 @@ read_products (void *cls,
}
if (sold_out_enabled)
{
- if(0 == strcmp (tmpProduct.description,
- "empty"))
+ if (0 == strcmp (tmpProduct.description,
+ "empty"))
{
tmpProduct.sold_out = GNUNET_YES;
}
else
- {
- tmpProduct.sold_out = GNUNET_NO;
- }
+ {
+ tmpProduct.sold_out = GNUNET_NO;
+ }
}
if (GNUNET_OK !=
TALER_config_get_denom (cls,
@@ -3047,24 +3058,25 @@ main (int argc,
READER_REVALUE_LIMIT,
READER_REVALUE_LIMIT_AMOUNT);
- readerNACK = setup_mdb_cmd ("Reader NACK",
- READER_NACK,
- NULL);
+ readerNACK = setup_mdb_cmd ("Reader NACK",
+ READER_NACK,
+ NULL);
- readerDisplaySoldOut = setup_mdb_cmd ("Display Sold Out",
-
READER_DISPLAY_REQUEST,
-
READER_DISPLAY_REQUEST_TIME
-
READER_DISPLAY_SOLD_OUT);
-
- readerDisplayInternalError = setup_mdb_cmd ("Display Communication
Error",
-
READER_DISPLAY_REQUEST,
-
READER_DISPLAY_REQUEST_TIME
-
READER_DISPLAY_INTERNAL_ERROR);
-
- readerDisplayBackendNotReachable = setup_mdb_cmd ("Display Backend not
reachable",
-
READER_DISPLAY_REQUEST,
-
READER_DISPLAY_REQUEST_TIME
-
READER_DISPLAY_BACKEND_NOT_REACHABLE);
+ readerDisplaySoldOut = setup_mdb_cmd ("Display Sold Out",
+ READER_DISPLAY_REQUEST,
+ READER_DISPLAY_REQUEST_TIME
+ READER_DISPLAY_SOLD_OUT);
+
+ readerDisplayInternalError = setup_mdb_cmd ("Display Communication Error",
+ READER_DISPLAY_REQUEST,
+ READER_DISPLAY_REQUEST_TIME
+ READER_DISPLAY_INTERNAL_ERROR);
+
+ readerDisplayBackendNotReachable = setup_mdb_cmd (
+ "Display Backend not reachable",
+ READER_DISPLAY_REQUEST,
+ READER_DISPLAY_REQUEST_TIME
+ READER_DISPLAY_BACKEND_NOT_REACHABLE);
ret = GNUNET_PROGRAM_run (argc,
argv,
"taler-mdb",
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-taler-mdb] branch master updated: fix,
gnunet <=