[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-mdb] 20/93: more implementations using GNUNETUtils
From: |
gnunet |
Subject: |
[taler-taler-mdb] 20/93: more implementations using GNUNETUtils |
Date: |
Mon, 18 Nov 2019 21:12:43 +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 5b90c8535be1b1c35919d7c5a828cf65c117d4b4
Author: BOSS_Marco <address@hidden>
AuthorDate: Tue Nov 5 15:38:42 2019 +0100
more implementations using GNUNETUtils
---
src/communication.c | 81 ++++++++++++-----------------------
src/communication.h | 3 +-
src/configuration.h | 42 +++++++++++-------
src/main.c | 69 ++++++++++++++++++++++--------
src/nfc.c | 5 ++-
src/product.c | 120 +++++++++++++++++++++++++++++++++-------------------
src/product.h | 18 +++++++-
src/wallet.c | 19 ++++-----
taler-mdb.conf | 13 ++++++
9 files changed, 224 insertions(+), 146 deletions(-)
diff --git a/src/communication.c b/src/communication.c
index e685fa0..40ec181 100644
--- a/src/communication.c
+++ b/src/communication.c
@@ -56,35 +56,16 @@ void SNACK_taler_exit (CURL **curl)
curl_global_cleanup ();
}
-int SNACK_taler_alloc_string (char **string, size_t size)
-{
- *string = malloc (size);
- if ( ! (*string) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_taler_alloc: unable to allocate string\n");
- exit (EXIT_FAILURE);
- }
- return EXIT_SUCCESS;
-}
-
static size_t _SNACK_taler_write_response (void *contents, size_t size, size_t
nmemb,
void *userp)
{
- char *tempString;
size_t realSize = size * nmemb;
struct TalerResponse *response = (struct TalerResponse *) userp;
- tempString = realloc (response->string, response->size + realSize + 1);
- if ( ! tempString )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_taler_write_response: allocation failure\n");
- return EXIT_FAILURE;
- }
+ response->string = GNUNET_realloc (response->string, response->size
+ + realSize + 1);
- response->string = tempString;
memcpy (&(response->string[response->size]), contents, realSize);
response->size += realSize;
response->string[response->size] = 0;
@@ -95,23 +76,26 @@ static size_t _SNACK_taler_write_response (void *contents,
size_t size, size_t
int SNACK_taler_create_order_req (ProductOrder *product)
{
json_t *orderReq;
- char*temp;
/* create the string representing the amount, e.g. "KUDOS:2.5" ( +2 because
of ':' and '\0' ) */
- char amountStr[ strlen (product->currency) + strlen (product->amount) + 2 ];
+ char amountStr[ strlen (product->talerCfg->currency) + strlen (
+ product->amount) + 2 ];
/* create the fulfillment ur, e.g.
"taler://fulfillment-success/Enjoy+your+ice+cream!"; ( +2 because of '!' and
'\0' ) */
- char fulfillmentUrl[ strlen (FULLFILLMENT_URL) + strlen (FULLFILLMENT_MSG)
+ char fulfillmentUrl[ strlen (product->talerCfg->fulfillmentUrl) + strlen (
+ product->talerCfg->fulfillmentMsg)
+ strlen (product->product) + 2 ];
/* create the strings declared earlier */
- sprintf (amountStr, "%s:%s", product->currency, product->amount);
- sprintf (fulfillmentUrl, "%s%s%s!", FULLFILLMENT_URL, FULLFILLMENT_MSG,
+ sprintf (amountStr, "%s:%s", product->talerCfg->currency, product->amount);
+ sprintf (fulfillmentUrl, "%s%s%s!", product->talerCfg->fulfillmentUrl,
+ product->talerCfg->fulfillmentMsg,
product->product);
/* create the json object for the order request */
- orderReq = json_pack ("{ s: { s:s, s:s, s:s }}", JSON_REQ_ORDER,
- JSON_REQ_SUMMARY, product->product, JSON_REQ_AMOUNT,
- amountStr, JSON_REQ_FULFILLMENT, fulfillmentUrl);
+ orderReq = json_pack ("{ s: { s:s, s:s, s:s }}", SNACK_JSON_REQ_ORDER,
+ SNACK_JSON_REQ_SUMMARY, product->product,
+ SNACK_JSON_REQ_AMOUNT,
+ amountStr, SNACK_JSON_REQ_FULFILLMENT, fulfillmentUrl);
if ( ! orderReq )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -129,14 +113,8 @@ int SNACK_taler_create_order_req (ProductOrder *product)
}
/* allocate memory for the string and copy it into the product */
- temp = realloc (product->orderRequest, strlen (buffer) + 1);
- if ( ! temp )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_taler_create_order_req: could not allocate order\n");
- return EXIT_FAILURE;
- }
- product->orderRequest = temp;
+ product->orderRequest = GNUNET_realloc (product->orderRequest, strlen (
+ buffer) + 1);
strcpy (product->orderRequest, buffer);
/* print the created order request and free the json object */
@@ -153,19 +131,20 @@ int SNACK_taler_create_order_req (ProductOrder *product)
int SNACK_taler_create_order (CURL *curl, ProductOrder *product)
{
- char url[ strlen (BACKEND_BASE_URL) + strlen (ORDER) + 1 ];
- struct curl_slist *list = NULL;
CURLcode result;
+ struct curl_slist *list = NULL;
+ char url[ strlen (product->talerCfg->backendBaseUrl) + strlen (
+ SNACK_TALER_ORDER) + 1 ];
/* reset the response size */
product->response->size = 0;
/* set the url */
- sprintf (url, "%s%s", BACKEND_BASE_URL, ORDER);
+ sprintf (url, "%s%s", product->talerCfg->backendBaseUrl, SNACK_TALER_ORDER);
curl_easy_setopt (curl, CURLOPT_URL, url);
/* set the authentication headers */
- list = curl_slist_append (list, AUTH_HEADER);
+ list = curl_slist_append (list, product->talerCfg->authorization);
curl_easy_setopt (curl, CURLOPT_HTTPHEADER, list);
/* curl option "post" */
@@ -183,6 +162,7 @@ int SNACK_taler_create_order (CURL *curl, ProductOrder
*product)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"SNACK_taler_create_order: could not communicate with
\"%s\"\n",
url);
+ curl_slist_free_all (list);
return EXIT_FAILURE;
}
@@ -200,8 +180,8 @@ int SNACK_taler_create_order (CURL *curl, ProductOrder
*product)
int SNACK_taler_check_payment_status (CURL *curl, ProductOrder *product)
{
- struct curl_slist *list = NULL;
CURLcode result;
+ struct curl_slist *list = NULL;
/* reset the response size */
product->response->size = 0;
@@ -210,7 +190,7 @@ int SNACK_taler_check_payment_status (CURL *curl,
ProductOrder *product)
curl_easy_setopt (curl, CURLOPT_URL, product->checkUrl);
/* set the authentication headers */
- list = curl_slist_append (list, AUTH_HEADER);
+ list = curl_slist_append (list, product->talerCfg->authorization);
curl_easy_setopt (curl, CURLOPT_HTTPHEADER, list);
/* curl option "get" */
@@ -227,6 +207,7 @@ int SNACK_taler_check_payment_status (CURL *curl,
ProductOrder *product)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"SNACK_taler_check_payment_status: could not communicate with
\"%s\"\n",
product->checkUrl);
+ curl_slist_free_all (list);
return EXIT_FAILURE;
}
@@ -247,12 +228,10 @@ int SNACK_taler_parse_json (const TalerResponse
*response, const
json_error_t error;
json_t *root = NULL;
- char *temp = NULL;
-
/* if the provided string was not allocated before allocate initial size 1 to
* realloc later */
if ( ! (*returnStr) )
- SNACK_taler_alloc_string (returnStr, 1);
+ returnStr = GNUNET_malloc (1);
/* load the json with th string provided from taler in the response struct */
root = json_loads (response->string, JSON_DISABLE_EOF_CHECK, &error);
@@ -280,15 +259,7 @@ int SNACK_taler_parse_json (const TalerResponse *response,
const
return EXIT_FAILURE;
}
- temp = realloc (*returnStr, strlen (result) + 1);
- if ( ! temp )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_taler_parse_json: could not allocate memory for
member\n");
- json_decref (root);
- return EXIT_FAILURE;
- }
- *returnStr = temp;
+ *returnStr = GNUNET_realloc (*returnStr, strlen (result) + 1);
strcpy (*returnStr, result);
json_decref (root);
diff --git a/src/communication.h b/src/communication.h
index 4f5f2bd..e730aef 100644
--- a/src/communication.h
+++ b/src/communication.h
@@ -38,8 +38,6 @@ int SNACK_taler_init (CURL **curl);
void SNACK_taler_exit (CURL **curl);
-int SNACK_taler_alloc_string (char **string, size_t size);
-
int SNACK_taler_create_order_req (ProductOrder *product);
int SNACK_taler_create_order (CURL *curl, ProductOrder *product);
@@ -50,4 +48,5 @@ int SNACK_taler_parse_json (const TalerResponse *response,
const
char *memberName,
char **returnStr);
+
#endif // COMM_H
diff --git a/src/configuration.h b/src/configuration.h
index 7312ac6..9dfb65b 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -28,29 +28,41 @@ along with
#include <stdio.h>
#include <inttypes.h>
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_util_lib.h>
-static const char*const CURRENCY = "KUDOS";
+/* config sections */
+#define TALER "taler"
+#define BACKOFFICE "backoffice"
-static const char*const ORDER = "/order";
-static const char*const CHECK = "/check-payment";
+/* config keys */
+#define CURRENCY "currency"
+#define AUTHORIZATION "authorization"
+#define BACKEND_BASE_URL "backend-base-url"
+#define FULLFILLMENT_URL "fulfillment-url"
+#define FULLFILLMENT_MSG "fulfillment-msg"
-static const char*const ORDER_CHECK = "?order_id=";
+/* default config file */
+#define SNACK_DEFAULT_CONFIG_FILE "taler-mdb.conf"
-static const char*const BACKEND_BASE_URL = "https://backend.demo.taler.net";
-static const char*const FULLFILLMENT_URL = "taler://fulfillment-success";
-static const char*const FULLFILLMENT_MSG = "/Enjoy+your+";
+/* taler url extensions */
+#define SNACK_TALER_ORDER "/order"
+#define SNACK_TALER_CHECK "/check-payment"
+#define SNACK_TALER_ORDER_CHECK "?order_id="
-static const char*const AUTH_HEADER = "Authorization: ApiKey sandbox";
+/* curl auth header */
+#define SNACK_CURL_AUTH_HEADER "Authorization"
-static const char*const JSON_PAID = "paid";
-static const char*const JSON_PAY_URI = "taler_pay_uri";
-static const char*const JSON_ORDER_ID = "order_id";
+/* json order check keys */
+#define SNACK_JSON_PAID "paid"
+#define SNACK_JSON_PAY_URI "taler_pay_uri"
+#define SNACK_JSON_ORDER_ID "order_id"
/* json order request keys */
-static const char*const JSON_REQ_ORDER = "order";
-static const char*const JSON_REQ_SUMMARY = "summary";
-static const char*const JSON_REQ_AMOUNT = "amount";
-static const char*const JSON_REQ_FULFILLMENT = "fulfillment_url";
+#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"
/* Wallet AID */
static const uint8_t taler_aid[] = { 0xF0, 0x00, 0x54, 0x41, 0x4c, 0x45, 0x52
};
diff --git a/src/main.c b/src/main.c
index 185dc6c..4ff8a5d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -42,7 +42,6 @@ along with
ProductOrder product;
nfc_context *context;
-
void *_SNACK_start_nfc_transmission (void *ignored)
{
/* supress warning about unused variable */
@@ -73,43 +72,75 @@ void *_SNACK_start_nfc_transmission (void *ignored)
int main (int argc, char*const*argv)
{
CURL *curl;
+ char*cfgFile;
+ struct GNUNET_CONFIGURATION_Handle *cfgHandle;
+
+ /* prepare config file name */
+ cfgFile = GNUNET_malloc (strlen (SNACK_DEFAULT_CONFIG_FILE) + 1);
+ strcpy (cfgFile, SNACK_DEFAULT_CONFIG_FILE);
+ /* the available command line options */
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_option_help (
- "This is an application for snack machines with nfc. Running with GNU
taler.\n"),
+ "This is an application for snack machines with nfc. Running with GNU
taler.\n"
+ "Current taler wallet AID: F00054414c4552\n"),
+ GNUNET_GETOPT_option_cfgfile (&cfgFile),
GNUNET_GETOPT_OPTION_END
};
+ /* parse the command line */
if ( GNUNET_GETOPT_run ("taler-mdb\n", options, argc, argv) <= 0 )
+ {
+ GNUNET_free (cfgFile);
return EXIT_SUCCESS;
+ }
+ /* setup logger */
GNUNET_assert
- (GNUNET_OK == GNUNET_log_setup ("taler-mdb", "DEBUG", NULL)); //
"taler-mdb.log"));
+ (GNUNET_OK == GNUNET_log_setup ("taler-mdb", "DEBUG", NULL)); //
"taler-mdb.log"));
- /* initialize nfc */
- nfc_init (&context);
- if ( ! context )
+ /* load config file */
+ cfgHandle = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfgHandle, cfgFile))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to init nfc\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "main: unable to load config file %s\n", cfgFile);
+ GNUNET_CONFIGURATION_destroy (cfgHandle);
+ GNUNET_free (cfgFile);
return EXIT_FAILURE;
}
- /* inizialize taler */
- if ( SNACK_taler_init (&curl) )
+ /* inizialize product */
+ if ( SNACK_product_init (&product, cfgHandle) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unable to init taler communication\n");
+ "main: unable to init product structure\n");
+ GNUNET_CONFIGURATION_destroy (cfgHandle);
+ GNUNET_free (cfgFile);
return EXIT_FAILURE;
}
- /* inizialize product */
- if ( SNACK_product_init (&product, CURRENCY) )
+ /* free cfg because its not needed anymore ( everything is now stored in
product ) */
+ GNUNET_CONFIGURATION_destroy (cfgHandle);
+ GNUNET_free (cfgFile);
+
+ /* initialize nfc */
+ nfc_init (&context);
+ if ( ! context )
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to init product structure\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "main: unable to init nfc\n");
return EXIT_FAILURE;
}
+ /* inizialize taler */
+ if ( SNACK_taler_init (&curl) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "main: nable to init taler communication\n");
+ return EXIT_FAILURE;
+ }
+ /* superloop */
while ( true )
{
printf ("Waiting for MBD input\n");
@@ -147,23 +178,26 @@ int main (int argc, char*const*argv)
if ( pthread_create (&nfcThread, NULL, _SNACK_start_nfc_transmission,
NULL) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Thread creation failed\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "main: thread creation failed\n");
return EXIT_FAILURE;
}
/* check the payment status, if paid exit while loop and end thread
transmitting nfc messages */
while ( ! product.paid )
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Order payment processing\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "main: order payment processing\n");
sleep (5);
+
while ( SNACK_taler_check_payment_status (curl, &product) )
;
+
/* set the boolean paid member of ProductOrder struct */
SNACK_product_set_paid_status (&product);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Payment status paid: %s\n",
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "main: payment status paid: %s\n",
(product.paid ? "true" : "false") );
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Order no.: %s paid!\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "main: order no.: %s paid!\n",
product.orderID);
@@ -194,6 +228,7 @@ int main (int argc, char*const*argv)
SNACK_product_reset (&product);
}
+ /* end of superloop */
/* clear all initialized data */
nfc_exit (context);
diff --git a/src/nfc.c b/src/nfc.c
index b816fd1..025e5cb 100644
--- a/src/nfc.c
+++ b/src/nfc.c
@@ -116,11 +116,12 @@ int SNACK_nfc_connect_target (nfc_device *pnd, nfc_target
*nt)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"SNACK_nfc_connect_target: failed to connect\n");
+ SNACK_print_hex_info ("UID", nt->nti.nai.abtUid, nt->nti.nai.szUidLen);
}
else {
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ /*GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"SNACK_nfc_connect_target: Target selected!\n");
- SNACK_print_hex_info ("UID", nt->nti.nai.abtUid, nt->nti.nai.szUidLen);
+ SNACK_print_hex_info ("UID", nt->nti.nai.abtUid, nt->nti.nai.szUidLen);*/
return EXIT_SUCCESS;
}
sleep (1);
diff --git a/src/product.c b/src/product.c
index 0f509fc..4d5e3cc 100644
--- a/src/product.c
+++ b/src/product.c
@@ -27,8 +27,6 @@ the attributes.
#include <string.h>
#include <jansson.h>
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_util_lib.h>
#include "product.h"
#include "configuration.h"
@@ -41,7 +39,8 @@ void SNACK_product_reset (ProductOrder *product)
product->paid = false;
}
-int SNACK_product_init (ProductOrder *product, const char *currency)
+int SNACK_product_init (ProductOrder *product, struct
+ GNUNET_CONFIGURATION_Handle *cfg)
{
if ( ! product )
{
@@ -50,28 +49,45 @@ int SNACK_product_init (ProductOrder *product, const char
*currency)
return EXIT_FAILURE;
}
- /* malloc for every string member with size 1, every other func just calls
- * realloc, because this struct gets used over and over again */
- product->response = malloc (sizeof(TalerResponse) );
- if ( ! product->response )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_product_init: unable to allocate memory for response
struct\n");
- return EXIT_FAILURE;
- }
- if ( SNACK_taler_alloc_string (&(product->response->string), 1) )
- return EXIT_FAILURE;
- if ( SNACK_taler_alloc_string (&(product->orderID), 1) )
+ /* allocate the taler config struct */
+ product->talerCfg = GNUNET_malloc (sizeof(TalerConfig));
+
+ /* get the configurable parameters and store them in the productOrder struct
*/
+ if ( SNACK_product_set_cfg_value (cfg, TALER, CURRENCY,
+ &product->talerCfg->currency))
return EXIT_FAILURE;
- if ( SNACK_taler_alloc_string (&(product->orderRequest), 1) )
+ if ( SNACK_product_set_cfg_value (cfg, BACKOFFICE, BACKEND_BASE_URL,
+ &product->talerCfg->backendBaseUrl))
return EXIT_FAILURE;
- if ( SNACK_taler_alloc_string (&(product->payUrl), 1) )
+ if ( SNACK_product_set_cfg_value (cfg, TALER, FULLFILLMENT_URL,
+ &product->talerCfg->fulfillmentUrl))
return EXIT_FAILURE;
- if ( SNACK_taler_alloc_string (&(product->checkUrl), 1) )
+ if ( SNACK_product_set_cfg_value (cfg, TALER, FULLFILLMENT_MSG,
+ &product->talerCfg->fulfillmentMsg))
return EXIT_FAILURE;
- if ( SNACK_taler_alloc_string (&(product->currency), strlen (currency) + 1) )
+
+
+ /* create the Authorization: ..... option for curl */
+ char*auth;
+ if ( SNACK_product_set_cfg_value (cfg, BACKOFFICE, AUTHORIZATION, &auth))
return EXIT_FAILURE;
- strcpy (product->currency, currency);
+ product->talerCfg->authorization = GNUNET_malloc (strlen (
+ SNACK_CURL_AUTH_HEADER)
+ + strlen (": ") + strlen (
+ auth) + 1);
+ sprintf (product->talerCfg->authorization, "%s: %s", SNACK_CURL_AUTH_HEADER,
+ auth);
+ GNUNET_free (auth);
+
+
+ /* malloc for every string member with size 1, every other func just calls
+ * realloc, because this struct gets used over and over again */
+ product->response = GNUNET_malloc (sizeof(TalerResponse));
+ product->response->string = GNUNET_malloc (1);
+ product->orderID = GNUNET_malloc (1);
+ product->orderRequest = GNUNET_malloc (1);
+ product->payUrl = GNUNET_malloc (1);
+ product->checkUrl = GNUNET_malloc (1);
product->amount = NULL;
product->product = NULL;
product->paid = false;
@@ -81,13 +97,18 @@ int SNACK_product_init (ProductOrder *product, const char
*currency)
void SNACK_product_exit (ProductOrder *product)
{
- free (product->response->string);
- free (product->response);
- free (product->orderID);
- free (product->orderRequest);
- free (product->payUrl);
- free (product->checkUrl);
- free (product->currency);
+ GNUNET_free (product->response->string);
+ GNUNET_free (product->response);
+ GNUNET_free (product->orderID);
+ GNUNET_free (product->orderRequest);
+ GNUNET_free (product->payUrl);
+ GNUNET_free (product->checkUrl);
+ GNUNET_free (product->talerCfg->currency);
+ GNUNET_free (product->talerCfg->authorization);
+ GNUNET_free (product->talerCfg->backendBaseUrl);
+ GNUNET_free (product->talerCfg->fulfillmentUrl);
+ GNUNET_free (product->talerCfg->fulfillmentMsg);
+ GNUNET_free (product->talerCfg);
product->amount = NULL;
product->product = NULL;
product->paid = false;
@@ -95,18 +116,14 @@ void SNACK_product_exit (ProductOrder *product)
int SNACK_product_set_check_url (ProductOrder *product)
{
- size_t len = strlen (BACKEND_BASE_URL) + strlen (CHECK);
- char *url = realloc (product->checkUrl, len + strlen (ORDER_CHECK) + strlen (
- product->orderID) + 1);
- if ( ! url )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_prduct_set_check_url: could not allocate memory for
order url\n");
- return EXIT_FAILURE;
- }
-
- product->checkUrl = url;
- sprintf (product->checkUrl, "%s%s%s%s", BACKEND_BASE_URL, CHECK, ORDER_CHECK,
+ product->checkUrl = GNUNET_realloc (product->checkUrl,
+ strlen
(product->talerCfg->backendBaseUrl)
+ + strlen (SNACK_TALER_CHECK)
+ + strlen (SNACK_TALER_ORDER_CHECK)
+ + strlen (product->orderID) + 1);
+
+ sprintf (product->checkUrl, "%s%s%s%s", product->talerCfg->backendBaseUrl,
+ SNACK_TALER_CHECK, SNACK_TALER_ORDER_CHECK,
product->orderID);
printf ("Url to check payment: %s\n\n", product->checkUrl);
@@ -115,13 +132,13 @@ int SNACK_product_set_check_url (ProductOrder *product)
int SNACK_product_set_order_id (ProductOrder *product)
{
- return SNACK_taler_parse_json (product->response, JSON_ORDER_ID,
+ return SNACK_taler_parse_json (product->response, SNACK_JSON_ORDER_ID,
&(product->orderID));
}
int SNACK_product_set_pay_url (ProductOrder *product)
{
- return SNACK_taler_parse_json (product->response, JSON_PAY_URI,
+ return SNACK_taler_parse_json (product->response, SNACK_JSON_PAY_URI,
&(product->payUrl));
}
@@ -142,10 +159,11 @@ int SNACK_product_set_paid_status (ProductOrder *product)
}
/* extract the boolean value of paid out of the json object */
- if ( json_unpack (root, "{s:b}", JSON_PAID, &b) < 0 )
+ if ( json_unpack (root, "{s:b}", SNACK_JSON_PAID, &b) < 0 )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_taler_parse_json: no value \"%s\" found!\n", JSON_PAID);
+ "SNACK_taler_parse_json: no value \"%s\" found!\n",
+ SNACK_JSON_PAID);
json_decref (root);
return EXIT_FAILURE;
}
@@ -166,3 +184,19 @@ int SNACK_product_set_paid_status (ProductOrder *product)
return EXIT_SUCCESS;
}
+
+
+int SNACK_product_set_cfg_value (struct GNUNET_CONFIGURATION_Handle *cfg, const
+ char*section, const char *key, char **value)
+{
+
+ if ( GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, section, key,
+ value))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "SNACK_product_set_cfg_value: no value '%s' or section '%s' in
config file found\n",
+ key, section);
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
+}
diff --git a/src/product.h b/src/product.h
index 3e1729e..5cffcd5 100644
--- a/src/product.h
+++ b/src/product.h
@@ -31,6 +31,8 @@ the attributes.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_util_lib.h>
typedef struct TalerResponse
{
@@ -38,21 +40,30 @@ typedef struct TalerResponse
size_t size;
} TalerResponse;
+typedef struct TalerConfig
+{
+ char *currency;
+ char *backendBaseUrl;
+ char *fulfillmentUrl;
+ char *fulfillmentMsg;
+ char *authorization;
+} TalerConfig;
+
typedef struct ProductOrder
{
char *product;
- char *currency;
char *amount;
char *orderRequest;
char *orderID;
char *checkUrl;
char *payUrl;
bool paid;
+ TalerConfig *talerCfg;
TalerResponse *response;
} ProductOrder;
-int SNACK_product_init (ProductOrder *product, const char*currency);
+int SNACK_product_init (ProductOrder *product, struct
GNUNET_CONFIGURATION_Handle *cfg);
void SNACK_product_exit (ProductOrder *product);
@@ -66,4 +77,7 @@ int SNACK_product_set_pay_url (ProductOrder *product);
int SNACK_product_set_paid_status (ProductOrder *product);
+int SNACK_product_set_cfg_value(struct GNUNET_CONFIGURATION_Handle* cfg, const
char* section, const char *key, char **value );
+
+
#endif // PRODUCT_H
diff --git a/src/wallet.c b/src/wallet.c
index 3b0aedb..fc3c35e 100644
--- a/src/wallet.c
+++ b/src/wallet.c
@@ -45,15 +45,17 @@ int SNACK_wallet_select_aid (nfc_device *pnd)
size) )
return EXIT_FAILURE;
+ /*
SNACK_print_hex_info (
"SNACK_wallet_select_aid: Selecting Taler apk using AID", taler_aid,
sizeof(taler_aid));
+ */
if ( nfc_initiator_transceive_bytes (pnd, message, size, response,
sizeof(response), TRANSMIT_TIMEOUT) < 0
)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_wallet_select_aid: Failed to select apk\n\n");
+ "SNACK_wallet_select_aid: Failed to select apk\n");
return EXIT_FAILURE;
}
@@ -77,7 +79,7 @@ int SNACK_put_message (nfc_device *pnd, const char *msg,
size_t msgSize)
sizeof(response), TRANSMIT_TIMEOUT) < 0
)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_wallet_put_message: Failed to put message\n\n");
+ "SNACK_wallet_put_message: Failed to put message\n");
return EXIT_FAILURE;
}
@@ -95,7 +97,7 @@ int SNACK_wallet_tunneling (nfc_device *pnd, const char *msg,
size_t msgSize)
sizeof(response), TRANSMIT_TIMEOUT) < 0
)
{
- printf ("wallet_put_message: Failed to put message\n\n");
+ printf ("wallet_put_message: Failed to put message\n");
return EXIT_FAILURE;
}
@@ -130,7 +132,7 @@ int SNACK_wallet_transmit (nfc_device *pnd, const char
*msg, size_t msgLen)
//
--------------------------------------------------------------------------------------------
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "SNACK_wallet_transmit: Transmitted message to taler
wallet\n\n");
+ "SNACK_wallet_transmit: Transmitted message to taler wallet\n");
return EXIT_SUCCESS;
}
@@ -142,11 +144,9 @@ int SNACK_check_response (uint8_t *response, uint8_t
responseLen)
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Transmission success\n");
}
else {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Transmission failure, return code:
");
- for ( uint8_t i = 0; i < responseLen; ++i ) {
- printf ("%.2x ", response[i]);
- }
- printf ("\n");
+ SNACK_print_hex_info (
+ "Transmission failure, return code: ", response,
+ responseLen);
return EXIT_FAILURE;
}
@@ -177,7 +177,6 @@ int SNACK_concat_message (const uint8_t*command, size_t
commandSize, const
void SNACK_print_hex_info (const char*message, const uint8_t *hexArray, size_t
sizeHex)
{
-
char hex[5] = {""};
char str[64] = {""};
diff --git a/taler-mdb.conf b/taler-mdb.conf
new file mode 100644
index 0000000..43343f2
--- /dev/null
+++ b/taler-mdb.conf
@@ -0,0 +1,13 @@
+[taler]
+currency = KUDOS
+# taler url for success message (see taler documentation)
+fulfillment-url = taler://fulfillment-success
+# alternative url (see taler documentation)
+#fulfillment-url = https(s)://
+# Message to diplay after purchase is completed,
+# will be concatenated with product
+# must be url - utf8 encoded
+fulfillment-msg = /Enjoy+your+
+[backoffice]
+backend-base-url = https://backend.demo.taler.net
+authorization = ApiKey sandbox
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [taler-taler-mdb] 16/93: merged jsonIntegrity, (continued)
- [taler-taler-mdb] 16/93: merged jsonIntegrity, gnunet, 2019/11/18
- [taler-taler-mdb] 25/93: no curl here, gnunet, 2019/11/18
- [taler-taler-mdb] 21/93: product.h uncrustified, gnunet, 2019/11/18
- [taler-taler-mdb] 22/93: pseudo nonce, gnunet, 2019/11/18
- [taler-taler-mdb] 26/93: use check payment instead of poll payment, gnunet, 2019/11/18
- [taler-taler-mdb] 10/93: add bootstrap and uncrustify logic, gnunet, 2019/11/18
- [taler-taler-mdb] 17/93: merged jsonIntegrity, gnunet, 2019/11/18
- [taler-taler-mdb] 23/93: chaos monkey, gnunet, 2019/11/18
- [taler-taler-mdb] 15/93: fixes, gnunet, 2019/11/18
- [taler-taler-mdb] 14/93: updated .gitignore, gnunet, 2019/11/18
- [taler-taler-mdb] 20/93: more implementations using GNUNETUtils,
gnunet <=
- [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