[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-mdb] 45/93: first steps in configurable products
From: |
gnunet |
Subject: |
[taler-taler-mdb] 45/93: first steps in configurable products |
Date: |
Mon, 18 Nov 2019 21:13:08 +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.
commit 3e131ed22a9e809e8a7ba79e853bef83fab3823f
Author: Boss Marco <address@hidden>
AuthorDate: Mon Nov 11 17:53:39 2019 +0100
first steps in configurable products
---
src/main.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++---------------
taler.conf | 27 +++++++++++++
2 files changed, 130 insertions(+), 32 deletions(-)
diff --git a/src/main.c b/src/main.c
index 4b82e9a..5cdfe6a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,7 +19,7 @@ along with
/**
* @file main.c
* @brief main functionality of the application
-* @author BOSS Marco
+* @author Boss Marco
* @author Christian Grothoff
*/
#include <stdio.h>
@@ -42,7 +42,7 @@ along with
#define NFC_TIMEOUT 500
#define MAX_HTTP_RETRY_FREQ GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_MILLISECONDS, 500)
+ GNUNET_TIME_UNIT_MILLISECONDS, 500)
/**
* Code returned by libnfc in case of success.
@@ -77,8 +77,9 @@ static const uint8_t get_data[] = { 0x00, 0xCA, 0x01, 0x00,
0x00, 0x00 };
struct Product
{
- const char *price;
- const char *description;
+ char *price;
+ char *description;
+ char *number;
char key;
};
@@ -104,6 +105,7 @@ struct PaymentActivity
int wallet_has_uri;
};
+static size_t NrOfProducts;
static nfc_context *context;
@@ -127,29 +129,7 @@ static char *authorization;
static struct PaymentActivity *payment_activity;
-
-/**
- * FIXME: read from configuration file instead!
- * GNUNET_CONFIGURATION_* iteration over values.
- */
-static struct Product products[] = {
- {
- .price = "0.1",
- .description = "Snickers",
- .key = 's'
- },
- {
- .price = "0.1",
- .description = "Twix",
- .key = 't'
- },
- {
- .price = NULL,
- .description = NULL,
- .key = '\0'
- }
-};
-
+static struct Product *products;
static void
SNACK_print_hex_info (const char*message,
@@ -225,6 +205,15 @@ shutdown_task (void *cls)
GNUNET_CURL_gnunet_rc_destroy (rc);
rc = NULL;
}
+ if (NULL != products)
+ {
+ for (unsigned int i = 0; NrOfProducts > i; i++)
+ {
+ GNUNET_free(products[i].description);
+ GNUNET_free(products[i].price);
+ GNUNET_free(products[i].number);
+ }
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Shutdown complete\n");
}
@@ -275,7 +264,7 @@ wallet_transmit_uri (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"'PUT DATA' command transmission failed, return code: %x%x\n",
response[0],
- response[1]);
+ response[1]);
pa->task = GNUNET_SCHEDULER_add_now (&connect_target,
pa);
return;
@@ -339,7 +328,7 @@ wallet_select_aid (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"AID selection failure, return code: %x%x, trying to find
another NFC client\n",
response[0],
- response[1]);
+ response[1]);
pa->task = GNUNET_SCHEDULER_add_delayed (NFC_FAILURE_RETRY_FREQ,
&connect_target,
pa);
@@ -642,7 +631,7 @@ read_keyboard_command (void *cls)
start_read_keyboard ();
return;
}
- for (unsigned int i = 0; NULL != products[i].price; i++)
+ for (unsigned int i = 0; NrOfProducts > i; i++)
if (((char) input) == products[i].key)
{
payment_activity = launch_payment (&products[i]);
@@ -655,14 +644,13 @@ read_keyboard_command (void *cls)
start_read_keyboard ();
}
-
static void
start_read_keyboard ()
{
struct GNUNET_DISK_FileHandle fh = { STDIN_FILENO };
GNUNET_assert (NULL == keyboard_task);
- for (unsigned int i = 0; NULL != products[i].price; i++)
+ for (unsigned int i = 0; NrOfProducts > i; i++)
printf ("'%c' to buy %s\n",
products[i].key,
products[i].description);
@@ -674,6 +662,85 @@ start_read_keyboard ()
NULL);
}
+static void
+read_products (void* cls,
+ const char *section)
+{
+ struct Product tmpProduct;
+ char* tmpKey;
+
+ if(0 == strncmp(section,
+ "product",
+ strlen("product")))
+ {
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cls,
+ section,
+ "description",
+ &tmpProduct.description))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "description");
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cls,
+ section,
+ "price",
+ &tmpProduct.price))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "price");
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cls,
+ section,
+ "key",
+ &tmpKey))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "key");
+ return;
+ }
+ tmpProduct.key = tmpKey[0];
+ GNUNET_free(tmpKey);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cls,
+ section,
+ "number",
+ &tmpProduct.number))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "number");
+ return;
+ }
+ NrOfProducts++;
+ if(NULL == products)
+ /*products = GNUNET_new_array(1,
+ sizeof(struct Product)); */
+ products = GNUNET_new(struct Product);
+ else
+ /*GNUNET_array_grow(products,
+ sizeof(products),
+ sizeof(products)+sizeof(struct Product)); NOT WORKING
? */
+ products = GNUNET_realloc(products,
+ NrOfProducts*sizeof(struct Product));
+
+ products[NrOfProducts-1].description =
GNUNET_strdup(tmpProduct.description);
+ GNUNET_free(tmpProduct.description);
+ products[NrOfProducts-1].price = GNUNET_strdup(tmpProduct.price);
+ GNUNET_free(tmpProduct.price);
+ products[NrOfProducts-1].number = GNUNET_strdup(tmpProduct.number);
+ GNUNET_free(tmpProduct.number);
+ products[NrOfProducts-1].key = tmpProduct.key;
+
+ }
+}
static void
run (void *cls,
@@ -753,6 +820,10 @@ run (void *cls,
global_ret = EXIT_FAILURE;
return;
}
+ GNUNET_CONFIGURATION_iterate_sections(cfg,
+ &read_products,
+ (void*)cfg);
+ GNUNET_assert(NULL != products);
GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
NULL);
diff --git a/taler.conf b/taler.conf
index f20e1b7..04233ea 100644
--- a/taler.conf
+++ b/taler.conf
@@ -12,3 +12,30 @@ fulfillment-url = taler://fulfillment-success
# will be concatenated with product
# must be url - utf8 encoded
fulfillment-msg = /Enjoy+your+
+
+#Products
+#end declaration
+[product_3]
+description = KitKat
+price = 0.1
+key = k
+number = 4
+[product_2]
+description = Mars
+price = 0.1
+key = m
+number = 3
+#twix
+[product_1]
+description = Twix
+price = 0.1
+key = t
+number = 2
+#snickers
+[product_0]
+description = Snickers
+price = 0.1
+key = s
+number = 1
+
+
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [taler-taler-mdb] 19/93: GNUnet logs added, -h option added, (continued)
- [taler-taler-mdb] 19/93: GNUnet logs added, -h option added, gnunet, 2019/11/18
- [taler-taler-mdb] 12/93: initial indenting, gnunet, 2019/11/18
- [taler-taler-mdb] 31/93: cleanup, gnunet, 2019/11/18
- [taler-taler-mdb] 33/93: typo, gnunet, 2019/11/18
- [taler-taler-mdb] 30/93: cleanup, gnunet, 2019/11/18
- [taler-taler-mdb] 24/93: use event loop, gnunet, 2019/11/18
- [taler-taler-mdb] 32/93: retry NFC failures more nicely, gnunet, 2019/11/18
- [taler-taler-mdb] 36/93: fixed delay when cancelling, new bugs detected marked with FIXME, gnunet, 2019/11/18
- [taler-taler-mdb] 46/93: first steps in configurable products, gnunet, 2019/11/18
- [taler-taler-mdb] 28/93: misc cleanup, gnunet, 2019/11/18
- [taler-taler-mdb] 45/93: first steps in configurable products,
gnunet <=
- [taler-taler-mdb] 40/93: fix, gnunet, 2019/11/18
- [taler-taler-mdb] 43/93: preparations for QR code alternative path, gnunet, 2019/11/18
- [taler-taler-mdb] 35/93: explicitly detect not-found code, gnunet, 2019/11/18
- [taler-taler-mdb] 39/93: use test for now, gnunet, 2019/11/18
- [taler-taler-mdb] 38/93: merged, gnunet, 2019/11/18
- [taler-taler-mdb] 37/93: fixed delay when cancelling, new bugs detected marked with FIXME, gnunet, 2019/11/18
- [taler-taler-mdb] 34/93: fix, gnunet, 2019/11/18
- [taler-taler-mdb] 42/93: print URI sent to wallet for diagnostics, gnunet, 2019/11/18
- [taler-taler-mdb] 18/93: GNUnet logs added, -h option added, gnunet, 2019/11/18
- [taler-taler-mdb] 27/93: fixes, gnunet, 2019/11/18