commit 5ed8feaf2ecba28d88f3e746bf3f5e79782306bf
parent 95bfa5d0aab39df60778f5441abca997aa8a0d28
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 9 Nov 2019 16:09:56 +0100
dce
Diffstat:
| D | src/communication.c | | | 126 | ------------------------------------------------------------------------------- |
| D | src/communication.h | | | 52 | ---------------------------------------------------- |
| D | src/configuration.h | | | 62 | -------------------------------------------------------------- |
| D | src/nfc.c | | | 32 | -------------------------------- |
| D | src/nfc.h | | | 33 | --------------------------------- |
| D | src/product.c | | | 101 | ------------------------------------------------------------------------------- |
| D | src/product.h | | | 77 | ----------------------------------------------------------------------------- |
| D | src/wallet.c | | | 107 | ------------------------------------------------------------------------------- |
| D | src/wallet.h | | | 51 | --------------------------------------------------- |
9 files changed, 0 insertions(+), 641 deletions(-)
diff --git a/src/communication.c b/src/communication.c
@@ -1,126 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2019 GNUnet e.V.
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more
-details.
-
- You should have received a copy of the GNU General Public License
-along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-
-/**
-* @file communication.c
-* @brief functions to communicate with taler backend
-* @author BOSS Marco
-*/
-
-#include <string.h>
-#include <stdbool.h>
-#include <jansson.h>
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_util_lib.h>
-
-#include "communication.h"
-#include "wallet.h"
-#include "configuration.h"
-
-
-int SNACK_taler_check_payment_status (CURL *curl, ProductOrder *product)
-{
- CURLcode result;
- struct curl_slist *list = NULL;
-
- /* reset the response size */
- product->response->size = 0;
-
- /* set the url */
- curl_easy_setopt (curl, CURLOPT_URL, product->checkUrl);
-
- /* set the authentication headers */
- list = curl_slist_append (list, product->talerCfg->authorization);
- curl_easy_setopt (curl, CURLOPT_HTTPHEADER, list);
-
- /* curl option "get" */
- curl_easy_setopt (curl, CURLOPT_HTTPGET, true);
-
- /* pass the write function and the struct to write to */
- curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, _SNACK_taler_write_response);
- curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *) product->response);
-
- /* perform the call */
- result = curl_easy_perform (curl);
- if ( result != CURLE_OK )
- {
- 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;
- }
-
- /* reset the curl options */
- curl_easy_reset (curl);
-
- /* clean up */
- curl_slist_free_all (list);
-
-
- printf ("%s\n", product->response->string);
-
- return EXIT_SUCCESS;
-}
-
-int SNACK_taler_parse_json (const TalerResponse *response, const
- char *memberName,
- char **returnStr)
-{
- /* json variables */
- json_error_t error;
- json_t *root = NULL;
-
- /* if the provided string was not allocated before allocate initial size 1 to
- * realloc later */
- if ( ! (*returnStr) )
- 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);
- if ( ! root )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "SNACK_taler_parse_json: %s\n",
- error.text);
- return EXIT_FAILURE;
- }
- char *result = NULL;
- if ( json_unpack (root, "{s:s}", memberName, &result) < 0 )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_taler_parse_json: no member named \"%s\" found!\n",
- memberName);
- json_decref (root);
- return EXIT_FAILURE;
- }
- if ( ! result )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_taler_parse_json: no member named \"%s\" found!\n",
- memberName);
- json_decref (root);
- return EXIT_FAILURE;
- }
-
- *returnStr = GNUNET_realloc (*returnStr, strlen (result) + 1);
- strcpy (*returnStr, result);
-
- json_decref (root);
- return EXIT_SUCCESS;
-}
diff --git a/src/communication.h b/src/communication.h
@@ -1,52 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2019 GNUnet e.V.
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more
-details.
-
- You should have received a copy of the GNU General Public License
-along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-
-/**
-* @file communication.h
-* @brief functions to communicate with taler backend
-* @author BOSS Marco
-*/
-
-
-#ifndef COMM_H
-#define COMM_H
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <curl/curl.h>
-
-#include "product.h"
-
-int SNACK_taler_init (CURL **curl);
-
-void SNACK_taler_exit (CURL **curl);
-
-int SNACK_taler_create_order_req (ProductOrder *product);
-
-int SNACK_taler_create_order (CURL *curl, ProductOrder *product);
-
-int SNACK_taler_check_payment_status (CURL *curl, ProductOrder *product);
-
-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
@@ -1,62 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2019 GNUnet e.V.
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more
-details.
-
- You should have received a copy of the GNU General Public License
-along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-
-/**
-* @file configuration.h
-* @brief in this file you can set your url specifications needed to comminicate with taler
-* @author BOSS Marco
-*/
-
-#ifndef URL_H
-#define URL_H
-
-#include <stdio.h>
-#include <inttypes.h>
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_util_lib.h>
-
-/* config sections */
-#define TALER "taler"
-#define BACKOFFICE "backoffice"
-
-/* 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"
-
-
-/* taler url extensions */
-#define SNACK_TALER_ORDER "/order"
-#define SNACK_TALER_CHECK "/check-payment"
-#define SNACK_TALER_ORDER_CHECK "?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"
-
-
-/* nonce definitions */
-#define NONCE_SIZE 32
-
-
-#endif // URL_H
diff --git a/src/nfc.c b/src/nfc.c
@@ -1,32 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2019 GNUnet e.V.
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more
-details.
-
- You should have received a copy of the GNU General Public License
-along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-
-/**
-* @file nfc.c
-* @brief functions used to comunicate over nfc interface
-* @author BOSS Marco
-*/
-
-#include <string.h>
-#include <unistd.h>
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_util_lib.h>
-
-#include "nfc.h"
-#include "wallet.h"
diff --git a/src/nfc.h b/src/nfc.h
@@ -1,33 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2019 GNUnet e.V.
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more
-details.
-
- You should have received a copy of the GNU General Public License
-along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-
-/**
-* @file nfc.h
-* @brief functions used to comunicate over nfc interface
-* @author BOSS Marco
-*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <nfc/nfc.h>
-
-int SNACK_nfc_transmit (nfc_context *context, const char *talerPayUrl, size_t
- urlSize);
-
-int SNACK_nfc_connect_target (nfc_device *pnd, nfc_target *nt);
diff --git a/src/product.c b/src/product.c
@@ -1,101 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2019 GNUnet e.V.
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more
-details.
-
- You should have received a copy of the GNU General Public License
-along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-
-/**
-* @file product.c
-* @brief defined a product order with the attributes of the product and
-the links used to communicate with taler. Provides setter methods to set
-the attributes.
-* @author BOSS Marco
-*/
-
-#include <string.h>
-#include <jansson.h>
-
-#include "product.h"
-#include "configuration.h"
-#include "communication.h"
-
-
-
-int SNACK_product_set_check_url (ProductOrder *product)
-{
- 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);
-
- return EXIT_SUCCESS;
-}
-
-
-int SNACK_product_set_pay_url (ProductOrder *product)
-{
- return SNACK_taler_parse_json (product->response, SNACK_JSON_PAY_URI,
- &(product->payUrl));
-}
-
-int SNACK_product_set_paid_status (ProductOrder *product)
-{
- json_error_t error;
- json_t *root = NULL;
-
- /* variable to extract the boolean value out of json object */
- int b = -1;
-
- root = json_loads (product->response->string, JSON_DISABLE_EOF_CHECK, &error);
- if ( ! root )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "SNACK_taler_parse_json: %s\n",
- error.text);
- return EXIT_FAILURE;
- }
-
- /* extract the boolean value of paid out of the json object */
- 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",
- SNACK_JSON_PAID);
- json_decref (root);
- return EXIT_FAILURE;
- }
-
- json_decref (root);
-
- /* set the paid status to true or false */
- if ((b == true)||(b == false))
- {
- product->paid = b;
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_product_set_paid_status: json parsing failed\n");
- return EXIT_FAILURE;
- }
-
- return EXIT_SUCCESS;
-}
diff --git a/src/product.h b/src/product.h
@@ -1,77 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2019 GNUnet e.V.
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more
-details.
-
- You should have received a copy of the GNU General Public License
-along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-
-/**
-* @file product.h
-* @brief defined a product order with the attributes of the product and
-the links used to communicate with taler. Provides setter methods to set
-the attributes.
-* @author BOSS Marco
-*/
-
-#ifndef PRODUCT_H
-#define PRODUCT_H
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_util_lib.h>
-
-typedef struct TalerResponse
-{
- char *string;
- size_t size;
-} TalerResponse;
-
-typedef struct ProductOrder
-{
- char *product;
- char *amount;
- char *nonce;
- char *orderID;
- char *checkUrl;
- char *payUrl;
- char *orderRequest;
- bool paid;
- TalerResponse *response;
-} ProductOrder;
-
-
-int SNACK_product_init (ProductOrder *product, struct
- GNUNET_CONFIGURATION_Handle *cfg);
-
-void SNACK_product_exit (ProductOrder *product);
-
-void SNACK_product_reset (ProductOrder *product);
-
-int SNACK_product_set_check_url (ProductOrder *product);
-
-int SNACK_product_set_order_id (ProductOrder *product);
-
-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);
-
-void SNACK_product_generate_nonce (char **nonce, size_t size);
-
-#endif // PRODUCT_H
diff --git a/src/wallet.c b/src/wallet.c
@@ -1,107 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2019 GNUnet e.V.
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more
-details.
-
- You should have received a copy of the GNU General Public License
-along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-
-/**
-* @file wallet.c
-* @brief functions to communicate with taler wallet over nfc
-* @author BOSS Marco
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <jansson.h>
-#include <unistd.h>
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_util_lib.h>
-
-#include "wallet.h"
-#include "configuration.h"
-
-int SNACK_wallet_select_aid (nfc_device *pnd)
-{
-}
-
-int SNACK_put_message (nfc_device *pnd, const char *msg, size_t msgSize)
-{
-
- return SNACK_check_response (response, sizeof(response) );
-}
-
-int SNACK_wallet_tunneling (nfc_device *pnd, const char *msg, size_t msgSize)
-{
- uint8_t response[255] = {0x00};
-
- printf ("checking for tunneling request\n");
-
- if ( nfc_initiator_transceive_bytes (pnd, get_data, sizeof(get_data),
- response,
- sizeof(response), TRANSMIT_TIMEOUT) < 0 )
-
- {
- printf ("wallet_put_message: Failed to put message\n");
- return EXIT_FAILURE;
- }
-
- for ( uint8_t i = 0; i < 255; ++i ) {
- printf ("%.2x ", response[i]);
- }
- printf ("\n");
-
- return SNACK_check_response (response, sizeof(response) );
-
-}
-
-
-int SNACK_check_response (uint8_t *response, uint8_t responseLen)
-{
- if ( strcmp ((char *) response, APDU_SUCCESS) == 0 )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Transmission success\n");
- }
- else {
- SNACK_print_hex_info (
- "Transmission failure, return code: ", response,
- responseLen);
- return EXIT_FAILURE;
- }
-
- return EXIT_SUCCESS;
-}
-
-int SNACK_concat_message (const uint8_t*command, size_t commandSize, const
- uint8_t*message, uint8_t *retMsg, size_t returnSize)
-{
- if ( ! command || ! message )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "SNACK_concat_message: command and message can't be null");
- return EXIT_FAILURE;
- }
-
- uint8_t i = 0;
- for (; i < commandSize; ++i ) {
- retMsg[i] = command[i];
- }
- for (; i < returnSize; ++i) {
- retMsg[i] = message[i - commandSize];
- }
-
- return EXIT_SUCCESS;
-}
diff --git a/src/wallet.h b/src/wallet.h
@@ -1,51 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2019 GNUnet e.V.
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more
-details.
-
- You should have received a copy of the GNU General Public License
-along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-
-/**
-* @file wallet.h
-* @brief functions to communicate with taler wallet over nfc
-* @author BOSS Marco
-*/
-
-#ifndef WALLET_H
-#define WALLET_H
-
-#include <nfc/nfc.h>
-
-
-#define TRANSMIT_TIMEOUT 500
-
-
-int SNACK_wallet_select_aid (nfc_device *pnd);
-
-int SNACK_wallet_put_message (nfc_device *pnd, const char *msg, size_t msgSize);
-
-int SNACK_wallet_tunneling (nfc_device *pnd, const char *msg, size_t msgSize);
-
-int SNACK_wallet_transmit (nfc_device*pnd, const char *msg, size_t msgLen);
-
-int SNACK_concat_message (const uint8_t*command, size_t commandSize, const
- uint8_t *message, uint8_t *retMsg, size_t returnSize);
-
-int SNACK_check_response (uint8_t *response, uint8_t responseLen);
-
-void SNACK_print_hex_info (const char*message, const uint8_t *hexArray, size_t
- sizeHex);
-
-#endif // WALLET_H