gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-mdb] 17/93: merged jsonIntegrity


From: gnunet
Subject: [taler-taler-mdb] 17/93: merged jsonIntegrity
Date: Mon, 18 Nov 2019 21:12:40 +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 b6227efb61c02024adc70543bc76a92afbe8db6a
Author: BOSS_Marco <address@hidden>
AuthorDate: Fri Nov 1 11:02:39 2019 +0100

    merged jsonIntegrity
---
 src/communication.c | 199 ++++++++++++++++++++++++++++------------------------
 src/configuration.h |  12 ++--
 src/product.c       |  21 +++---
 src/wallet.c        |   4 +-
 4 files changed, 125 insertions(+), 111 deletions(-)

diff --git a/src/communication.c b/src/communication.c
index 69d874b..49bdbee 100644
--- a/src/communication.c
+++ b/src/communication.c
@@ -31,118 +31,125 @@ along with
 #include "wallet.h"
 #include "configuration.h"
 
-int taler_init(CURL **curl)
+int taler_init (CURL **curl)
 {
   CURLcode result;
 
-  if( *curl != NULL ){
-    printf( "taler_init: curl handle already initialized\n" );
+  if ( *curl != NULL )
+  {
+    printf ("taler_init: curl handle already initialized\n");
     return EXIT_FAILURE;
   }
 
   /* initialize curl */
-  result = curl_global_init( CURL_GLOBAL_ALL );
-  *curl = curl_easy_init();
-  if( !(*curl) || result != CURLE_OK ){
-    printf( "taler_init: could not inizialize curl handle\n" );
+  result = curl_global_init (CURL_GLOBAL_ALL);
+  *curl = curl_easy_init ();
+  if ( ! (*curl) ||(result != CURLE_OK))
+  {
+    printf ("taler_init: could not inizialize curl handle\n");
     return EXIT_FAILURE;
   }
 
   return EXIT_SUCCESS;
 }
-void taler_exit( CURL **curl )
+void taler_exit (CURL **curl)
 {
-  curl_easy_cleanup(*curl);
-  curl_global_cleanup();
+  curl_easy_cleanup (*curl);
+  curl_global_cleanup ();
 }
 
-int taler_alloc_string( char **string, size_t size )
+int taler_alloc_string (char **string, size_t size)
 {
-  *string = malloc( size );
-  if( !(*string) ){
-    printf( "taler_alloc: unable to allocate string" );
-    exit( EXIT_FAILURE );
+  *string = malloc (size);
+  if ( ! (*string) )
+  {
+    printf ("taler_alloc: unable to allocate string");
+    exit (EXIT_FAILURE);
   }
   return EXIT_SUCCESS;
 }
 
-static size_t _taler_write_response( void *contents, size_t size, size_t nmemb,
-                                     void *userp )
+static size_t _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;
+  struct TalerResponse *response = (struct TalerResponse *) userp;
 
-  tempString = realloc( response->string, response->size + realSize + 1 );
-  if( !tempString ) {
-    printf( "Allocation failure" );
+  tempString = realloc (response->string, response->size + realSize + 1);
+  if ( ! tempString )
+  {
+    printf ("Allocation failure");
     return EXIT_FAILURE;
   }
 
   response->string = tempString;
-  memcpy(&( response->string[response->size] ), contents, realSize );
+  memcpy (&(response->string[response->size]), contents, realSize);
   response->size += realSize;
   response->string[response->size] = 0;
 
   return realSize;
 }
 
-int taler_create_order_req( ProductOrder *product )
+int taler_create_order_req (ProductOrder *product)
 {
   json_t *orderReq;
-  char* temp;
+  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->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) +
-      strlen(product->product) + 2 ];
+  char fulfillmentUrl[ strlen (FULLFILLMENT_URL) + strlen (FULLFILLMENT_MSG)
+                       + 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,
-           product->product );
+  sprintf (amountStr, "%s:%s", product->currency, product->amount);
+  sprintf (fulfillmentUrl, "%s%s%s!", FULLFILLMENT_URL, FULLFILLMENT_MSG,
+           product->product);
 
   /* create the json object for the order request */
-  orderReq = json_pack( "{ s: { s:s, s:s, s:s }}", JSON_REQ_ORDER,
+  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 );
-  if( !orderReq ){
-    printf( "taler_create_order_req: error creating json object\n" );
+                        amountStr, JSON_REQ_FULFILLMENT, fulfillmentUrl);
+  if ( ! orderReq )
+  {
+    printf ("taler_create_order_req: error creating json object\n");
     return EXIT_FAILURE;
   }
 
   /* create the string to send to taler in compact format */
-  char *buffer = json_dumps( orderReq, JSON_COMPACT );
-  if( !buffer ){
-    printf("taler_create_order_req: error converting json to string\n");
+  char *buffer = json_dumps (orderReq, JSON_COMPACT);
+  if ( ! buffer )
+  {
+    printf ("taler_create_order_req: error converting json to string\n");
     return EXIT_FAILURE;
   }
 
   /* allocate memory for the string and copy it into the product */
-  temp = realloc( product->orderRequest, strlen(buffer) + 1 );
-  if( !temp ){
-    printf( "could not allocate order\n" );
+  temp = realloc (product->orderRequest, strlen (buffer) + 1);
+  if ( ! temp )
+  {
+    printf ("could not allocate order\n");
     return EXIT_FAILURE;
   }
   product->orderRequest = temp;
-  strcpy( product->orderRequest, buffer );
+  strcpy (product->orderRequest, buffer);
 
   /* print the created order request and free the json object */
-  printf( "Created order Request: \n" );
-  json_dumpf( orderReq, stdout, JSON_INDENT(2) );
-  printf("\n");
-  json_decref( orderReq );
+  printf ("Created order Request: \n");
+  json_dumpf (orderReq, stdout, JSON_INDENT (2) );
+  printf ("\n");
+  json_decref (orderReq);
 
   /* free the allocated buffer from json_dumps */
-  free( buffer );
+  free (buffer);
 
   return EXIT_SUCCESS;
 }
 
-int taler_create_order( CURL *curl, ProductOrder *product )
+int taler_create_order (CURL *curl, ProductOrder *product)
 {
-  char url[ strlen(BACKEND_BASE_URL) + strlen( ORDER ) + 1 ];
+  char url[ strlen (BACKEND_BASE_URL) + strlen (ORDER) + 1 ];
   struct curl_slist *list = NULL;
   CURLcode result;
 
@@ -150,41 +157,42 @@ int taler_create_order( CURL *curl, ProductOrder *product 
)
   product->response->size = 0;
 
   /* set the url */
-  sprintf( url, "%s%s", BACKEND_BASE_URL, ORDER );
-  curl_easy_setopt( curl, CURLOPT_URL, url );
+  sprintf (url, "%s%s", BACKEND_BASE_URL, ORDER);
+  curl_easy_setopt (curl, CURLOPT_URL, url);
 
   /* set the authentication headers */
-  list = curl_slist_append( list, AUTH_HEADER );
-  curl_easy_setopt( curl, CURLOPT_HTTPHEADER, list );
+  list = curl_slist_append (list, AUTH_HEADER);
+  curl_easy_setopt (curl, CURLOPT_HTTPHEADER, list);
 
   /* curl option "post" */
-  curl_easy_setopt( curl, CURLOPT_HTTPPOST, true );
-  curl_easy_setopt( curl, CURLOPT_POSTFIELDS, product->orderRequest );
+  curl_easy_setopt (curl, CURLOPT_HTTPPOST, true);
+  curl_easy_setopt (curl, CURLOPT_POSTFIELDS, product->orderRequest);
 
   /* pass the write function and the struct to write to */
-  curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, _taler_write_response );
-  curl_easy_setopt( curl, CURLOPT_WRITEDATA, (void *)product->response );
+  curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, _taler_write_response);
+  curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *) product->response);
 
   /* perform the call */
-  result = curl_easy_perform( curl );
-  if( result != CURLE_OK ){
-    printf( "could not communicate with \"%s\"\n", url  );
+  result = curl_easy_perform (curl);
+  if ( result != CURLE_OK )
+  {
+    printf ("could not communicate with \"%s\"\n", url);
     return EXIT_FAILURE;
   }
 
   /* reset the curl options */
-  curl_easy_reset( curl );
+  curl_easy_reset (curl);
 
   /* clean up */
-  curl_slist_free_all( list );
+  curl_slist_free_all (list);
 
 
-  printf("%s\n", product->response->string );
+  printf ("%s\n", product->response->string);
 
   return EXIT_SUCCESS;
 }
 
-int taler_check_payment_status( CURL *curl, ProductOrder *product )
+int taler_check_payment_status (CURL *curl, ProductOrder *product)
 {
   struct curl_slist *list = NULL;
   CURLcode result;
@@ -193,37 +201,38 @@ int taler_check_payment_status( CURL *curl, ProductOrder 
*product )
   product->response->size = 0;
 
   /* set the url */
-  curl_easy_setopt( curl, CURLOPT_URL, product->checkUrl );
+  curl_easy_setopt (curl, CURLOPT_URL, product->checkUrl);
 
   /* set the authentication headers */
-  list = curl_slist_append( list, AUTH_HEADER );
-  curl_easy_setopt( curl, CURLOPT_HTTPHEADER, list );
+  list = curl_slist_append (list, AUTH_HEADER);
+  curl_easy_setopt (curl, CURLOPT_HTTPHEADER, list);
 
   /* curl option "get" */
-  curl_easy_setopt( curl, CURLOPT_HTTPGET, true );
+  curl_easy_setopt (curl, CURLOPT_HTTPGET, true);
 
   /* pass the write function and the struct to write to */
-  curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, _taler_write_response );
-  curl_easy_setopt( curl, CURLOPT_WRITEDATA, (void *)product->response );
+  curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, _taler_write_response);
+  curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *) product->response);
 
   /*  perform the call */
-  result = curl_easy_perform(curl);
-  if( result != CURLE_OK ){
-    printf( "could not communicate with \"%s\"\n", product->checkUrl  );
+  result = curl_easy_perform (curl);
+  if ( result != CURLE_OK )
+  {
+    printf ("could not communicate with \"%s\"\n", product->checkUrl);
     return EXIT_FAILURE;
   }
 
   /* reset the curl options */
-  curl_easy_reset( curl );
+  curl_easy_reset (curl);
 
   /* clean up */
-  curl_slist_free_all( list );
+  curl_slist_free_all (list);
 
   return EXIT_SUCCESS;
 }
 
-int taler_parse_json( const TalerResponse *response, const char *memberName,
-                      char **returnStr )
+int taler_parse_json (const TalerResponse *response, const char *memberName,
+                      char **returnStr)
 {
   /* json variables */
   json_error_t error;
@@ -233,36 +242,40 @@ int taler_parse_json( const TalerResponse *response, 
const char *memberName,
 
   /* if the provided string was not allocated before allocate initial size 1 to
    *  realloc later */
-  if( !(*returnStr) )
-    taler_alloc_string( returnStr, 1 );
+  if ( ! (*returnStr) )
+    taler_alloc_string (returnStr, 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 ){
-    printf("taler_parse_json: %s\n", error.text );
+  root = json_loads (response->string, JSON_DISABLE_EOF_CHECK, &error);
+  if ( ! root )
+  {
+    printf ("taler_parse_json: %s\n", error.text);
     return EXIT_FAILURE;
   }
   char *result = NULL;
-  if( json_unpack( root, "{s:s}", memberName, &result ) < 0 ){
-    printf( "taler_parse_json: no member named \"%s\" found!\n", memberName );
-    json_decref( root );
+  if ( json_unpack (root, "{s:s}", memberName, &result) < 0 )
+  {
+    printf ("taler_parse_json: no member named \"%s\" found!\n", memberName);
+    json_decref (root);
     return EXIT_FAILURE;
   }
-  if( !result ){
-    printf( "taler_parse_json: no member named \"%s\" found!\n", memberName );
-    json_decref( root );
+  if ( ! result )
+  {
+    printf ("taler_parse_json: no member named \"%s\" found!\n", memberName);
+    json_decref (root);
     return EXIT_FAILURE;
   }
 
-  temp = realloc( *returnStr, strlen(result) + 1 );
-  if( !temp ){
-    printf( "taler_parse_json: could not allocate memory for member\n" );
-    json_decref( root );
+  temp = realloc (*returnStr, strlen (result) + 1);
+  if ( ! temp )
+  {
+    printf ("taler_parse_json: could not allocate memory for member\n");
+    json_decref (root);
     return EXIT_FAILURE;
   }
   *returnStr = temp;
-  strcpy( *returnStr, result );
+  strcpy (*returnStr, result);
 
-  json_decref( root );
+  json_decref (root);
   return EXIT_SUCCESS;
 }
diff --git a/src/configuration.h b/src/configuration.h
index b19b5e0..8b226d2 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -29,14 +29,14 @@ along with
 #include <stdio.h>
 #include <inttypes.h>
 
-static const char* const ORDER = "/order";
-static const char* const CHECK = "/check-payment";
+static const char*const ORDER = "/order";
+static const char*const CHECK = "/check-payment";
 
-static const char* const ORDER_CHECK = "?order_id=";
+static const char*const ORDER_CHECK = "?order_id=";
 
-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+";
+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+";
 
 static const char*const AUTH_HEADER = "Authorization: ApiKey sandbox";
 
diff --git a/src/product.c b/src/product.c
index e355566..6e6c217 100644
--- a/src/product.c
+++ b/src/product.c
@@ -127,30 +127,31 @@ int product_set_paid_status (ProductOrder *product)
   /* 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 )
+  root = json_loads (product->response->string, JSON_DISABLE_EOF_CHECK, 
&error);
+  if ( ! root )
   {
-    printf("taler_parse_json: %s\n", error.text );
+    printf ("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}", JSON_PAID, &b ) < 0 )
+  if ( json_unpack (root, "{s:b}", JSON_PAID, &b) < 0 )
   {
-    printf("taler_parse_json: no value \"%s\" found!\n", JSON_PAID );
-    json_decref( root );
+    printf ("taler_parse_json: no value \"%s\" found!\n", JSON_PAID);
+    json_decref (root);
     return EXIT_FAILURE;
   }
 
-  json_decref(root);
+  json_decref (root);
 
   /* set the paid status to true or false */
-  if( b == true || b == false )
+  if ((b == true)||(b == false))
   {
     product->paid = b;
-  }else
+  }
+  else
   {
-    printf( "product_set_paid_status: json parsing failed\n" );
+    printf ("product_set_paid_status: json parsing failed\n");
     return EXIT_FAILURE;
   }
 
diff --git a/src/wallet.c b/src/wallet.c
index 6e19b2c..44406e7 100644
--- a/src/wallet.c
+++ b/src/wallet.c
@@ -61,7 +61,7 @@ int wallet_put_message (nfc_device *pnd, const char *msg, 
size_t msgSize)
 
   int size = sizeof(put_data) + msgSize;
   uint8_t message[size];
-  if ( concat_message (put_data, sizeof(put_data), (const uint8_t*) msg,
+  if ( concat_message (put_data, sizeof(put_data), (const uint8_t *) msg,
                        message, size) )
     return EXIT_FAILURE;
 
@@ -98,7 +98,7 @@ int wallet_transmit (nfc_device *pnd, const char *msg, size_t 
msgLen)
 
 int check_response (uint8_t *response, uint8_t responseLen)
 {
-  if ( strcmp ((char*) response, APDU_SUCCESS) == 0 )
+  if ( strcmp ((char *) response, APDU_SUCCESS) == 0 )
   {
     printf ("Transmission success\n");
   }

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]