taler-mdb

GNU Taler Extensions and Integrations
Log | Files | Refs | Submodules | README | LICENSE

commit a00c467cb8d170ce49ffb9011ff79d8f817147c5
parent f8ab6b7b487e0cb7eac2d91147ddfb52d44ea92d
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon, 11 Nov 2019 22:59:01 +0100

intermediary commit

Diffstat:
Msrc/Makefile.am | 1+
Msrc/main.c | 55+++++++++++++++++++++++++++++--------------------------
2 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am @@ -10,6 +10,7 @@ taler_nfc_SOURCES = \ main.c taler_nfc_LDADD = \ -ltalermerchant \ + -ltalerjson \ -ltalerutil \ -lgnunetcurl \ -lgnunetutil \ diff --git a/src/main.c b/src/main.c @@ -42,7 +42,9 @@ along with #include <errno.h> #include <termios.h> #include <nfc/nfc.h> +#include <microhttpd.h> #include <gnunet/gnunet_util_lib.h> +#include <taler/taler_json_lib.h> #include <taler/taler_merchant_service.h> /** @@ -72,12 +74,6 @@ along with */ #define APDU_NOT_FOUND "\x6a\x82" -/* json order request keys */ -#define SNACK_JSON_REQ_ORDER "order" -#define SNACK_JSON_REQ_SUMMARY "summary" -#define SNACK_JSON_REQ_AMOUNT "amount" -#define SNACK_JSON_REQ_FULFILLMENT "fulfillment_url" - /* curl auth header */ #define SNACK_CURL_AUTH_HEADER "Authorization" @@ -89,13 +85,15 @@ static const uint8_t taler_aid[] = { 0xF0, 0x00, 0x54, 0x41, 0x4c, 0x45, 0x52 }; static const uint8_t select_file[] = { 0x00, 0xA4, 0x04, 0x00, 0x07 }; static const uint8_t put_data[] = { 0x00, 0xDA, 0x01, 0x00, 0x7c, 0x01 }; +#if FUTURE_FEATURES /* tunneling */ static const uint8_t get_data[] = { 0x00, 0xCA, 0x01, 0x00, 0x00, 0x00 }; +#endif struct Product { - const char *price; + struct TALER_Amount price; const char *description; char key; }; @@ -152,17 +150,17 @@ static struct PaymentActivity *payment_activity; */ static struct Product products[] = { { - .price = "0.1", + // .price = "0.1", .description = "Snickers", .key = 's' }, { - .price = "0.1", + // .price = "0.1", .description = "Twix", .key = 't' }, { - .price = NULL, + // .price = NULL, .description = NULL, .key = '\0' } @@ -670,26 +668,31 @@ launch_payment (const struct Product *product) { struct PaymentActivity *pa; json_t *orderReq; - char *amountStr; char *fulflmntUrl; - - /* create the string representing the amount, e.g. "KUDOS:2.5" */ - GNUNET_asprintf (&amountStr, - "%s:%s", - currency, - product->price); + struct GNUNET_ShortHashCode uuid; + char *uuid_s; + + /* We need to ensure that every fulfillment URL is unique; + most easily done by adding a random nonce, as we may + not have a reliable counter or clock on the machine */ + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, + &uuid, + sizeof (uuid)); + uuid_s = GNUNET_STRINGS_data_to_string_alloc (&uuid, + sizeof (uuid)); /* create the fulfillment url, e.g. "taler://fulfillment-success/Enjoy+your+ice+cream!"; */ GNUNET_asprintf (&fulflmntUrl, - "%s%s%s!", + "%s%s%s#%s", fulfillmentUrl, fulfillmentMsg, - product->description); + product->description, + uuid_s); + GNUNET_free (uuid_s); /* create the json object for the order request */ orderReq = json_pack ("{ s:s, s:s, s:s }", - SNACK_JSON_REQ_SUMMARY, product->description, - SNACK_JSON_REQ_AMOUNT, amountStr, - SNACK_JSON_REQ_FULFILLMENT, fulflmntUrl); - GNUNET_free (amountStr); + "summary", product->description, + "amount", TALER_JSON_from_amount (&product->price), + "fulfillment_url", fulflmntUrl); GNUNET_free (fulflmntUrl); if (NULL == orderReq) { @@ -755,7 +758,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; NULL != products[i].description; i++) if (((char) input) == products[i].key) { payment_activity = launch_payment (&products[i]); @@ -775,7 +778,7 @@ 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; NULL != products[i].description; i++) printf ("'%c' to buy %s\n", products[i].key, products[i].description); @@ -838,7 +841,7 @@ run (void *cls, } GNUNET_asprintf (&authorization, "%s: %s", - SNACK_CURL_AUTH_HEADER, + MHD_HTTP_HEADER_AUTHORIZATION, auth); GNUNET_free (auth); }