[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-mdb] 50/93: slight logic clean up
From: |
gnunet |
Subject: |
[taler-taler-mdb] 50/93: slight logic clean up |
Date: |
Mon, 18 Nov 2019 21:13:13 +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 52c25ba37e4dfa1ca7bad9c25a419eb9364f1603
Merge: a00c467 f3f840a
Author: Christian Grothoff <address@hidden>
AuthorDate: Mon Nov 11 23:13:48 2019 +0100
slight logic clean up
src/main.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++-------------
taler.conf | 29 +++++++++++++++
2 files changed, 128 insertions(+), 25 deletions(-)
diff --cc src/main.c
index abf291c,ab6433f..4b65e13
--- a/src/main.c
+++ b/src/main.c
@@@ -93,11 -95,12 +93,13 @@@ static const uint8_t get_data[] = { 0x0
struct Product
{
- char *price;
+ struct TALER_Amount price;
- const char *description;
+ char *description;
+ char *number;
char key;
};
++
struct PaymentActivity
{
@@@ -143,30 -147,8 +145,11 @@@ static char *authorization
static struct PaymentActivity *payment_activity;
+ static struct Product *products;
- /**
- * 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 unsigned int products_length;
+
+
#if HAVE_QRENCODE_H
#include <qrencode.h>
@@@ -320,6 -302,15 +303,17 @@@ shutdown_task (void *cls
GNUNET_CURL_gnunet_rc_destroy (rc);
rc = NULL;
}
+ if (NULL != products)
+ {
- for (unsigned int i = 0; NrOfProducts > i; i++)
++ for (unsigned int i = 0; i < products_length; i++)
+ {
+ GNUNET_free (products[i].description);
- GNUNET_free (products[i].price);
+ GNUNET_free (products[i].number);
+ }
++ GNUNET_array_grow (products,
++ products_length,
++ 0);
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Shutdown complete\n");
}
@@@ -758,7 -744,7 +752,7 @@@ read_keyboard_command (void *cls
start_read_keyboard ();
return;
}
- for (unsigned int i = 0; NULL != products[i].description; i++)
- for (unsigned int i = 0; NrOfProducts > i; i++)
++ for (unsigned int i = 0; i < products_length; i++)
if (((char) input) == products[i].key)
{
payment_activity = launch_payment (&products[i]);
@@@ -778,7 -763,7 +772,7 @@@ start_read_keyboard (
struct GNUNET_DISK_FileHandle fh = { STDIN_FILENO };
GNUNET_assert (NULL == keyboard_task);
- for (unsigned int i = 0; NULL != products[i].description; i++)
- for (unsigned int i = 0; NrOfProducts > i; i++)
++ for (unsigned int i = 0; i < products_length; i++)
printf ("'%c' to buy %s\n",
products[i].key,
products[i].description);
@@@ -790,7 -775,87 +784,83 @@@
NULL);
}
+
+ static void
-read_products (void*cls,
++read_products (void *cls,
+ const char *section)
+ {
+ struct Product tmpProduct;
- char*tmpKey;
++ char *tmpKey;
+
- if (0 == strncmp (section,
- "product",
- strlen ("product")))
++ if (0 != strncmp (section,
++ "product-",
++ strlen ("product-")))
++ return;
++ 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 !=
++ TALER_config_get_denom (cls,
++ section,
++ "price",
++ &tmpProduct.price))
++ {
++ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
++ section,
++ "price");
++ GNUNET_free (tmpProduct.description);
++ return;
++ }
++ if (0 != strcasecmp (currency,
++ tmpProduct.price.currency))
++ {
++ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
++ section,
++ "price",
++ "currency missmatch");
++ GNUNET_free (tmpProduct.description);
++ return;
++ }
++ if (GNUNET_OK ==
++ GNUNET_CONFIGURATION_get_value_string (cls,
++ section,
++ "key",
++ &tmpKey))
+ {
- 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; /* maybe the keys don't have to mandatory, if not
remove this "error" block */
- }
+ 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);
++ }
++ else
++ {
++ /* no key */
++ tmpProduct.key = '\0';
++ }
++ if (GNUNET_OK !=
++ GNUNET_CONFIGURATION_get_value_string (cls,
++ section,
++ "number",
++ &tmpProduct.number))
++ {
++ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
++ section,
++ "number");
+ 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;
-
++ return;
+ }
++ GNUNET_array_append (products,
++ products_length,
++ tmpProduct);
+ }
+
++
static void
run (void *cls,
char *const *args,
diff --cc taler.conf
index f20e1b7,04233ea..aa4eb02
--- a/taler.conf
+++ b/taler.conf
@@@ -12,3 -12,30 +12,32 @@@ fulfillment-url = taler://fulfillment-s
# will be concatenated with product
# must be url - utf8 encoded
fulfillment-msg = /Enjoy+your+
+
+ #Products
+ #end declaration
-[product_3]
++
++[product-3]
+ description = KitKat
-price = 0.1
++price = TESTKUDOS:0.1
+ key = k
+ number = 4
-[product_2]
++
++[product-2]
+ description = Mars
-price = 0.1
++price = TESTKUDOS:0.1
+ key = m
+ number = 3
+ #twix
-[product_1]
++
++[product-1]
+ description = Twix
-price = 0.1
++price = TESTKDUOS:0.1
+ key = t
+ number = 2
+ #snickers
-[product_0]
++
++[product-0]
+ description = Snickers
-price = 0.1
++price = TESTKUDOS:0.1
+ key = s
+ number = 1
-
-
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [taler-taler-mdb] 61/93: qr gen, (continued)
- [taler-taler-mdb] 61/93: qr gen, gnunet, 2019/11/18
- [taler-taler-mdb] 59/93: when no display, show on stdout, gnunet, 2019/11/18
- [taler-taler-mdb] 54/93: first (half working) qrcode, gnunet, 2019/11/18
- [taler-taler-mdb] 52/93: stop NFC interaction after payment succeeded, gnunet, 2019/11/18
- [taler-taler-mdb] 58/93: fix, gnunet, 2019/11/18
- [taler-taler-mdb] 65/93: qr gen, gnunet, 2019/11/18
- [taler-taler-mdb] 57/93: stick to convention, gnunet, 2019/11/18
- [taler-taler-mdb] 49/93: intermediary commit, gnunet, 2019/11/18
- [taler-taler-mdb] 62/93: qr gen, gnunet, 2019/11/18
- [taler-taler-mdb] 47/93: Merge branch 'refactor' of https://git.taler.net/taler-mdb into refactor, gnunet, 2019/11/18
- [taler-taler-mdb] 50/93: slight logic clean up,
gnunet <=
- [taler-taler-mdb] 51/93: fix json construction, gnunet, 2019/11/18
- [taler-taler-mdb] 63/93: qr gen, gnunet, 2019/11/18
- [taler-taler-mdb] 66/93: swap xy, gnunet, 2019/11/18
- [taler-taler-mdb] 68/93: see stuff, gnunet, 2019/11/18
- [taler-taler-mdb] 82/93: see stuff, gnunet, 2019/11/18
- [taler-taler-mdb] 72/93: see stuff, gnunet, 2019/11/18
- [taler-taler-mdb] 67/93: swap xy, gnunet, 2019/11/18
- [taler-taler-mdb] 75/93: see stuff, gnunet, 2019/11/18
- [taler-taler-mdb] 80/93: see stuff, gnunet, 2019/11/18
- [taler-taler-mdb] 74/93: see stuff, gnunet, 2019/11/18