summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am1
-rw-r--r--src/main.c137
-rw-r--r--taler.conf (renamed from taler-mdb.conf)9
3 files changed, 81 insertions, 66 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index f8c0fe1..27eedc2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,7 +15,6 @@ taler_nfc_LDADD = \
-lgnunetutil \
-ljansson \
-lnfc \
- -lpthread \
$(XLIB)
diff --git a/src/main.c b/src/main.c
index 22afa34..b48151c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -25,7 +25,6 @@ along with
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <pthread.h>
#include <unistd.h>
#include <nfc/nfc.h>
#include <gnunet/platform.h>
@@ -42,9 +41,6 @@ along with
#define SNACK_JSON_REQ_AMOUNT "amount"
#define SNACK_JSON_REQ_FULFILLMENT "fulfillment_url"
-/* default config file */
-#define SNACK_DEFAULT_CONFIG_FILE "taler-mdb.conf"
-
/* curl auth header */
#define SNACK_CURL_AUTH_HEADER "Authorization"
@@ -115,21 +111,21 @@ static struct PaymentActivity *payment_activity;
* 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'
- }
+{
+ .price = "0.1",
+ .description = "Snickers",
+ .key = 's'
+},
+{
+ .price = "0.1",
+ .description = "Twix",
+ .key = 't'
+},
+{
+ .price = NULL,
+ .description = NULL,
+ .key = '\0'
+}
};
@@ -223,25 +219,26 @@ wallet_transmit_uri (void *cls)
memcpy (&message[sizeof (put_data)], pa->taler_pay_uri, slen);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Sending 'PUT DATA' command to wallet\n");
- if (nfc_initiator_transceive_bytes (pa->pnd,
- message,
- sizeof (message),
- response,
- sizeof(response),
- 1 /* timeout, 1 ms */) < 0)
+ if (0 > nfc_initiator_transceive_bytes (pa->pnd,
+ message,
+ sizeof (message),
+ response,
+ sizeof(response),
+ 1 /* timeout, 1 ms */))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_wallet_put_message: Failed to put message\n");
+ "Failed to send command\n");
pa->task = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_UNIT_SECONDS /* FIXME: timeout? */,
- &wallet_select_aid, /* TBD: where to resume? */
- pa);
+ GNUNET_TIME_UNIT_SECONDS /* FIXME: timeout? */,
+ &wallet_select_aid, /* TBD: where to resume? */
+ pa);
+
return;
}
pa->task = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_UNIT_SECONDS /* FIXME: timeout? */,
- &wallet_transmit_uri, /* TBD: where to resume? */
- pa);
+ GNUNET_TIME_UNIT_SECONDS /* FIXME: timeout? */,
+ &wallet_transmit_uri, /* TBD: where to resume? */
+ pa);
}
@@ -256,19 +253,19 @@ wallet_select_aid (void *cls)
memcpy (message, select_file, sizeof (select_file));
memcpy (&message[sizeof (select_file)], taler_aid, sizeof (taler_aid));
- if (nfc_initiator_transceive_bytes (pa->pnd,
- message,
- sizeof (message),
- response,
- sizeof(response),
- 1 /* timeout in ms */) < 0)
+ if (0 > nfc_initiator_transceive_bytes (pa->pnd,
+ message,
+ sizeof (message),
+ response,
+ sizeof(response),
+ 10 /* timeout in ms */))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "nfc_initiator_transceive_bytes: Failed to select apk\n");
+ "Failed to select wallet app\n");
pa->task = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_UNIT_SECONDS /* FIXME: timeout? */,
- &wallet_select_aid, /* TBD: where to resume? */
- pa);
+ GNUNET_TIME_UNIT_SECONDS /* FIXME: timeout? */,
+ &wallet_select_aid, /* TBD: where to resume? */
+ pa);
return;
}
if (0 == memcmp (response,
@@ -286,9 +283,9 @@ wallet_select_aid (void *cls)
response[0],
response[1]);
pa->task = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_UNIT_SECONDS /* FIXME: timeout? */,
- &wallet_select_aid, /* TBD: where to resume? */
- pa);
+ GNUNET_TIME_UNIT_SECONDS /* FIXME: timeout? */,
+ &wallet_select_aid, /* TBD: where to resume? */
+ pa);
}
@@ -309,18 +306,20 @@ connect_target (void *cls)
pa->task = NULL;
pa->nt.nti.nai.szUidLen = 0;
- if (nfc_initiator_select_passive_target (pa->pnd,
- nmMifare[0], NULL, 0, &pa->nt) <=
- 0 )
+ if (0 >= nfc_initiator_select_passive_target (pa->pnd,
+ nmMifare[0],
+ NULL,
+ 0,
+ &pa->nt))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_nfc_connect_target: failed to connect\n");
+ "Failed to connect to nfc target\n");
}
else if ( (pa->nt.nti.nai.szUidLen > UID_LEN_UPPER) ||
(pa->nt.nti.nai.szUidLen < UID_LEN_LOWER) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_nfc_connect_target: failed to connect\n");
+ "Failed to connect, wrong nfc modulation\n");
SNACK_print_hex_info ("UID",
pa->nt.nti.nai.abtUid,
pa->nt.nti.nai.szUidLen);
@@ -363,18 +362,29 @@ check_payment_cb (void *cls,
struct TALER_Amount *refund_amount,
const char *taler_pay_uri)
{
+ (void)refunded;
+ (void)refund_amount;
+ (void)obj;
struct PaymentActivity *pa = cls;
pa->cpo = NULL;
// FIXME: check http_status, yada yada
- if (paid)
+ if(MHD_HTTP_OK != http_status)
{
- fprintf (stderr,
- "FIXME: yield product here!\n");
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+ "Http check payment failed: %u",
+ http_status);
cleanup_payment (pa);
GNUNET_assert (payment_activity == pa);
payment_activity = NULL;
+ return;
+ }
+
+ if (paid)
+ {
+ fprintf (stderr,
+ "FIXME: yield product here!\n");
}
else
{
@@ -391,7 +401,7 @@ check_payment_cb (void *cls,
GNUNET_assert (NULL == pa->pnd);
pa->taler_pay_uri = GNUNET_strdup (taler_pay_uri);
pa->pnd = nfc_open (context, NULL);
- if (NULL != pa->pnd)
+ if (NULL == pa->pnd)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Payment inititation: Unable to open nfc device\n");
@@ -427,6 +437,7 @@ proposal_cb (void *cls,
const json_t *obj,
const char *order_id)
{
+ (void)obj;
struct PaymentActivity *pa = cls;
pa->po = NULL;
@@ -454,12 +465,12 @@ proposal_cb (void *cls,
static struct PaymentActivity *
-launch_payment (const struct Product *product)
+ launch_payment (const struct Product *product)
{
struct PaymentActivity *pa;
json_t *orderReq;
char *amountStr;
- char *fulfillmentUrl;
+ char *fulflmntUrl;
/* create the string representing the amount, e.g. "KUDOS:2.5" */
GNUNET_asprintf (&amountStr,
@@ -467,7 +478,7 @@ launch_payment (const struct Product *product)
currency,
product->price);
/* create the fulfillment url, e.g. "taler://fulfillment-success/Enjoy+your+ice+cream!"; */
- GNUNET_asprintf (&fulfillmentUrl,
+ GNUNET_asprintf (&fulflmntUrl,
"%s%s%s!",
fulfillmentUrl,
fulfillmentMsg,
@@ -476,9 +487,9 @@ launch_payment (const struct Product *product)
orderReq = json_pack ("{ s:s, s:s, s:s }",
SNACK_JSON_REQ_SUMMARY, product->description,
SNACK_JSON_REQ_AMOUNT, amountStr,
- SNACK_JSON_REQ_FULFILLMENT, fulfillmentUrl);
+ SNACK_JSON_REQ_FULFILLMENT, fulflmntUrl);
GNUNET_free (amountStr);
- GNUNET_free (fulfillmentUrl);
+ GNUNET_free (fulflmntUrl);
if (NULL == orderReq)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -510,6 +521,7 @@ start_read_keyboard (void);
static void
read_keyboard_command (void *cls)
{
+ (void)cls;
int input;
keyboard_task = NULL;
@@ -532,10 +544,11 @@ read_keyboard_command (void *cls)
fprintf (stderr,
"No purchase activity pending\n");
}
+ getchar();
start_read_keyboard ();
return;
}
- if (NULL == payment_activity)
+ if (NULL != payment_activity)
{
fprintf (stderr,
"Purchase activity already pending\n");
@@ -550,8 +563,9 @@ read_keyboard_command (void *cls)
return;
}
fprintf (stderr,
- "Unknown command `%c'\n",
+ "Unknown command '%c'\n",
(char) input);
+ getchar();
start_read_keyboard ();
}
@@ -584,6 +598,7 @@ run (void *cls,
(void) cls;
(void) args;
(void) cfgfile;
+
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"taler",
diff --git a/taler-mdb.conf b/taler.conf
index 43343f2..89169a7 100644
--- a/taler-mdb.conf
+++ b/taler.conf
@@ -1,5 +1,9 @@
[taler]
currency = KUDOS
+
+[taler-mdb]
+backend-base-url = http://backend.demo.taler.net/
+backend-authorization = ApiKey sandbox
# taler url for success message (see taler documentation)
fulfillment-url = taler://fulfillment-success
# alternative url (see taler documentation)
@@ -7,7 +11,4 @@ fulfillment-url = taler://fulfillment-success
# 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
+fulfillment-msg = /Enjoy+your+ \ No newline at end of file