gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] branch master updated (69e616d -> 2ec30cc)


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated (69e616d -> 2ec30cc)
Date: Thu, 23 May 2019 21:08:11 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a change to branch master
in repository merchant.

    from 69e616d  rename
     new d565780  indent
     new 2ec30cc  compressing lib pay

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/lib/merchant_api_pay.c      | 242 +++++++++++++++++++++++-----------------
 src/lib/merchant_api_proposal.c |  28 ++---
 2 files changed, 152 insertions(+), 118 deletions(-)

diff --git a/src/lib/merchant_api_pay.c b/src/lib/merchant_api_pay.c
index 84d86e5..af7b8c9 100644
--- a/src/lib/merchant_api_pay.c
+++ b/src/lib/merchant_api_pay.c
@@ -2,22 +2,26 @@
   This file is part of TALER
   Copyright (C) 2014, 2015, 2016, 2017 GNUnet e.V. and INRIA
 
-  TALER is free software; you can redistribute it and/or modify it under the
-  terms of the GNU Lesser General Public License as published by the Free 
Software
-  Foundation; either version 2.1, 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 Lesser General Public License for more 
details.
-
-  You should have received a copy of the GNU Lesser General Public License 
along with
-  TALER; see the file COPYING.LGPL.  If not, see
-  <http://www.gnu.org/licenses/>
+  TALER is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as
+  published by the Free Software Foundation; either version 2.1,
+  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 Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General
+  Public License along with TALER; see the file COPYING.LGPL.
+  If not, see <http://www.gnu.org/licenses/>
 */
 /**
  * @file lib/merchant_api_pay.c
- * @brief Implementation of the /pay request of the merchant's HTTP API
+ * @brief Implementation of the /pay request
+ *        of the merchant's HTTP API
  * @author Christian Grothoff
+ * @author Marcello Stanisci
  */
 #include "platform.h"
 #include <curl/curl.h>
@@ -29,6 +33,7 @@
 #include <taler/taler_json_lib.h>
 #include <taler/taler_signatures.h>
 #include <taler/taler_exchange_service.h>
+#include <taler/teah_common.h>
 
 
 /**
@@ -43,11 +48,6 @@ struct TALER_MERCHANT_Pay
   char *url;
 
   /**
-   * JSON encoding of the request to POST.
-   */
-  char *json_enc;
-
-  /**
    * Handle for the request.
    */
   struct GNUNET_CURL_Job *job;
@@ -83,6 +83,11 @@ struct TALER_MERCHANT_Pay
   struct GNUNET_CURL_Context *ctx;
 
   /**
+   * Minor context that holds body and headers.
+   */
+  struct TEAH_PostContext post_ctx;
+
+  /**
    * The coins we are paying with.
    */
   struct TALER_MERCHANT_PaidCoin *coins;
@@ -160,8 +165,10 @@ check_abort_refund (struct TALER_MERCHANT_Pay *ph,
         return GNUNET_SYSERR;
       }
 
-      rr.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_REFUND);
-      rr.purpose.size = htonl (sizeof (struct TALER_RefundRequestPS));
+      rr.purpose.purpose = htonl
+        (TALER_SIGNATURE_MERCHANT_REFUND);
+      rr.purpose.size = htonl
+        (sizeof (struct TALER_RefundRequestPS));
       rr.h_contract_terms = ph->h_contract_terms;
       rr.coin_pub = res[i].coin_pub;
       rr.merchant = merchant_pub;
@@ -171,7 +178,8 @@ check_abort_refund (struct TALER_MERCHANT_Pay *ph,
       {
        if (0 == memcmp (&ph->coins[j].coin_pub,
                         &res[i].coin_pub,
-                        sizeof (struct TALER_CoinSpendPublicKeyP)))
+                        sizeof
+                           (struct TALER_CoinSpendPublicKeyP)))
        {
          TALER_amount_hton (&rr.refund_amount,
                             &ph->coins[j].amount_with_fee);
@@ -187,10 +195,11 @@ check_abort_refund (struct TALER_MERCHANT_Pay *ph,
       }
 
       if (GNUNET_OK !=
-         GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_REFUND,
-                                     &rr.purpose,
-                                     &sig->eddsa_sig,
-                                     &merchant_pub.eddsa_pub))
+         GNUNET_CRYPTO_eddsa_verify
+            (TALER_SIGNATURE_MERCHANT_REFUND,
+            &rr.purpose,
+            &sig->eddsa_sig,
+            &merchant_pub.eddsa_pub))
       {
        GNUNET_break_op (0);
        return GNUNET_SYSERR;
@@ -217,8 +226,8 @@ check_abort_refund (struct TALER_MERCHANT_Pay *ph,
  * coin was actually already spent!
  *
  * @param pc handle of the original coin we paid with
- * @param json cryptographic proof of coin's transaction history as
- *        was returned by the exchange/merchant
+ * @param json cryptographic proof of coin's transaction
+ *        history as was returned by the exchange/merchant
  * @return #GNUNET_OK if proof checks out
  */
 static int
@@ -229,10 +238,11 @@ check_coin_history (const struct TALER_MERCHANT_PaidCoin 
*pc,
   struct TALER_Amount spent_plus_contrib;
 
   if (GNUNET_OK !=
-      TALER_EXCHANGE_verify_coin_history (pc->amount_with_fee.currency,
-                                          &pc->coin_pub,
-                                          json,
-                                          &spent))
+      TALER_EXCHANGE_verify_coin_history
+        (pc->amount_with_fee.currency,
+         &pc->coin_pub,
+         json,
+         &spent))
   {
     /* Exchange's history fails to verify */
     GNUNET_break_op (0);
@@ -267,7 +277,8 @@ check_coin_history (const struct TALER_MERCHANT_PaidCoin 
*pc,
  * coin was actually already spent!
  *
  * @param ph handle of the original pay operation
- * @param json cryptographic proof returned by the exchange/merchant
+ * @param json cryptographic proof returned by the
+ *        exchange/merchant
  * @return #GNUNET_OK if proof checks out
  */
 static int
@@ -344,8 +355,9 @@ handle_pay_finished (void *cls,
     case MHD_HTTP_NOT_ACCEPTABLE:
       break;
     case MHD_HTTP_BAD_REQUEST:
-      /* This should never happen, either us or the merchant is buggy
-        (or API version conflict); just pass JSON reply to the application */
+      /* This should never happen, either us
+       * or the merchant is buggy (or API version conflict);
+       * just pass JSON reply to the application */
       break;
     case MHD_HTTP_FORBIDDEN:
       if (GNUNET_OK != check_forbidden (ph,
@@ -356,21 +368,23 @@ handle_pay_finished (void *cls,
       }
       break;
     case MHD_HTTP_UNAUTHORIZED:
-      /* Nothing really to verify, merchant says one of the signatures is
-        invalid; as we checked them, this should never happen, we
-        should pass the JSON reply to the application */
+      /* Nothing really to verify, merchant says one of the
+       * signatures is invalid; as we checked them, this
+       * should never happen, we should pass the JSON reply
+       * to the application */
       break;
     case MHD_HTTP_NOT_FOUND:
       /* Nothing really to verify, this should never
-        happen, we should pass the JSON reply to the application */
+        happen, we should pass the JSON reply to the
+         application */
       break;
     case MHD_HTTP_INTERNAL_SERVER_ERROR:
-      /* Server had an internal issue; we should retry, but this API
-        leaves this to the application */
+      /* Server had an internal issue; we should retry,
+         but this API leaves this to the application */
       break;
     case MHD_HTTP_SERVICE_UNAVAILABLE:
-      /* Exchange couldn't respond properly; the retry is left to the
-       * application */
+      /* Exchange couldn't respond properly; the retry is
+         left to the application */
       break;
     default:
       /* unexpected response code */
@@ -406,23 +420,26 @@ handle_pay_finished (void *cls,
       response_code = 0;
       break;
     case MHD_HTTP_BAD_REQUEST:
-      /* This should never happen, either us or the merchant is buggy
-        (or API version conflict); just pass JSON reply to the application */
+      /* This should never happen, either us or the
+         merchant is buggy (or API version conflict); just
+         pass JSON reply to the application */
       break;
     case MHD_HTTP_FORBIDDEN:
       break;
     case MHD_HTTP_UNAUTHORIZED:
-      /* Nothing really to verify, merchant says one of the signatures is
-        invalid; as we checked them, this should never happen, we
-        should pass the JSON reply to the application */
+      /* Nothing really to verify, merchant says one of
+         the signatures is invalid; as we checked them,
+         this should never happen, we should pass the JSON
+         reply to the application */
       break;
     case MHD_HTTP_NOT_FOUND:
       /* Nothing really to verify, this should never
-        happen, we should pass the JSON reply to the application */
+        happen, we should pass the JSON reply to the
+         application */
       break;
     case MHD_HTTP_INTERNAL_SERVER_ERROR:
-      /* Server had an internal issue; we should retry, but this API
-        leaves this to the application */
+      /* Server had an internal issue; we should retry,
+         but this API leaves this to the application */
       break;
     default:
       /* unexpected response code */
@@ -457,24 +474,26 @@ handle_pay_finished (void *cls,
  * @param num_coins number of coins used to pay
  * @param coins array of coins we use to pay
  * @param mode mode string to use ("pay" or "abort-refund").
- * @param pay_cb the callback to call when a reply for this request is 
available
+ * @param pay_cb the callback to call when a reply for this
+ *        request is available
  * @param pay_cb_cls closure for @a pay_cb
  * @param abort_cb callback to call for the abort-refund variant
  * @param abort_cb_cls closure for @a abort_cb
  * @return a handle for this request
  */
 static struct TALER_MERCHANT_Pay *
-request_pay_generic (struct GNUNET_CURL_Context *ctx,
-                    const char *merchant_url,
-                    const struct TALER_MerchantPublicKeyP *merchant_pub,
-                    const char *order_id,
-                    unsigned int num_coins,
-                    const struct TALER_MERCHANT_PaidCoin *coins,
-                    const char *mode,
-                    TALER_MERCHANT_PayCallback pay_cb,
-                    void *pay_cb_cls,
-                    TALER_MERCHANT_PayRefundCallback abort_cb,
-                    void *abort_cb_cls)
+request_pay_generic
+  (struct GNUNET_CURL_Context *ctx,
+   const char *merchant_url,
+   const struct TALER_MerchantPublicKeyP *merchant_pub,
+   const char *order_id,
+   unsigned int num_coins,
+   const struct TALER_MERCHANT_PaidCoin *coins,
+   const char *mode,
+   TALER_MERCHANT_PayCallback pay_cb,
+   void *pay_cb_cls,
+   TALER_MERCHANT_PayRefundCallback abort_cb,
+   void *abort_cb_cls)
 {
   struct TALER_MERCHANT_Pay *ph;
   json_t *pay_obj;
@@ -530,16 +549,20 @@ request_pay_generic (struct GNUNET_CURL_Context *ctx,
     }
 
     /* create JSON for this coin */
-    j_coin = json_pack ("{s:o, s:o," /* contribution/coin_pub */
-                       " s:s, s:o," /* exchange_url / denom_pub */
-                       " s:o, s:o}", /* ub_sig / coin_sig */
-                       "contribution", TALER_JSON_from_amount 
(&pc->amount_with_fee),
-                       "coin_pub", GNUNET_JSON_from_data_auto (&pc->coin_pub),
-                       "exchange_url", pc->exchange_url,
-                       "denom_pub", GNUNET_JSON_from_rsa_public_key 
(pc->denom_pub.rsa_public_key),
-                       "ub_sig", GNUNET_JSON_from_rsa_signature 
(pc->denom_sig.rsa_signature),
-                       "coin_sig", GNUNET_JSON_from_data_auto (&pc->coin_sig)
-                       );
+    j_coin = json_pack
+      ("{s:o, s:o," /* contribution/coin_pub */
+       " s:s, s:o," /* exchange_url / denom_pub */
+       " s:o, s:o}", /* ub_sig / coin_sig */
+       "contribution", TALER_JSON_from_amount
+         (&pc->amount_with_fee),
+       "coin_pub", GNUNET_JSON_from_data_auto
+         (&pc->coin_pub),
+       "exchange_url", pc->exchange_url,
+       "denom_pub", GNUNET_JSON_from_rsa_public_key
+         (pc->denom_pub.rsa_public_key),
+       "ub_sig", GNUNET_JSON_from_rsa_signature
+         (pc->denom_sig.rsa_signature),
+       "coin_sig", GNUNET_JSON_from_data_auto (&pc->coin_sig));
     if (0 !=
         json_array_append_new (j_coins,
                                j_coin))
@@ -559,7 +582,8 @@ request_pay_generic (struct GNUNET_CURL_Context *ctx,
                       "mode", mode,
                       "coins", j_coins,
                        "order_id", order_id,
-                       "merchant_pub", GNUNET_JSON_from_data_auto 
(merchant_pub));
+                       "merchant_pub", GNUNET_JSON_from_data_auto
+                         (merchant_pub));
   if (NULL == pay_obj)
   {
     GNUNET_break (0);
@@ -581,53 +605,61 @@ request_pay_generic (struct GNUNET_CURL_Context *ctx,
           num_coins * sizeof (struct TALER_MERCHANT_PaidCoin));
 
   eh = curl_easy_init ();
-  GNUNET_assert (NULL != (ph->json_enc =
-                          json_dumps (pay_obj,
-                                      JSON_COMPACT)));
+
+  if (GNUNET_OK != TALER_curl_easy_post (&ph->post_ctx,
+                                         eh,
+                                         pay_obj))
+  {
+    GNUNET_break (0);
+    GNUNET_free (ph);
+    return NULL;
+  }
+
   json_decref (pay_obj);
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_URL,
-                                   ph->url));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_POSTFIELDS,
-                                   ph->json_enc));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_POSTFIELDSIZE,
-                                   strlen (ph->json_enc)));
-  ph->job = GNUNET_CURL_job_add (ctx,
-                                 eh,
-                                 GNUNET_YES,
-                                 &handle_pay_finished,
-                                 ph);
+  GNUNET_assert (CURLE_OK == curl_easy_setopt (eh,
+                                               CURLOPT_URL,
+                                               ph->url));
+  ph->job = GNUNET_CURL_job_add2 (ctx,
+                                  eh,
+                                  ph->post_ctx.headers,
+                                  &handle_pay_finished,
+                                  ph);
   return ph;
 }
 
 
 /**
- * Pay a merchant.  API for wallets that have the coin's private keys.
- * _NOTE_: this function does NOT calculate each coin amount in order
- * to match the contract total price.  This calculation is to be made
- * by the logic using this library.
+ * Pay a merchant.  API for wallets that have the coin's private
+ * keys.
+ * _NOTE_: this function does NOT calculate each coin amount in
+ * order to match the contract total price.  This calculation is
+ * to be made by the logic using this library.
  *
  * @param ctx the execution loop context
  * @param merchant_url base URL of the merchant's backend
- * @param instance which merchant instance will receive this payment
+ * @param instance which merchant instance will receive this
+ *        payment
  * @param h_contract_terms hashcode of the proposal being paid
- * @param amount total value of the contract to be paid to the merchant
- * @param max_fee maximum fee covered by the merchant (according to the 
contract)
- * @param merchant_pub the public key of the merchant (used to identify the 
merchant for refund requests)
- * @param merchant_sig signature from the merchant over the original contract
- * @param timestamp timestamp when the contract was finalized, must match 
approximately the current time of the merchant
- * @param refund_deadline date until which the merchant can issue a refund to 
the customer via the merchant (can be zero if refunds are not allowed)
+ * @param amount total value of the contract to be paid to the
+ *        merchant
+ * @param max_fee maximum fee covered by the merchant
+ *        (according to the contract)
+ * @param merchant_pub the public key of the merchant
+ *        (used to identify the merchant for refund requests)
+ * @param merchant_sig signature from the merchant over the
+ *        original contract
+ * @param timestamp timestamp when the contract was finalized,
+ *        must match approximately the current time of the merchant
+ * @param refund_deadline date until which the merchant can issue
+ *        a refund to the customer via the merchant (can be zero
+ *        if refunds are not allowed)
  * @param pay_deadline maximum time limit to pay for this contract
  * @param h_wire hash of the merchant’s account details
  * @param order_id order id of the proposal being paid
  * @param num_coins number of coins used to pay
  * @param coins array of coins we use to pay
- * @param pay_cb the callback to call when a reply for this request is 
available
+ * @param pay_cb the callback to call when a reply for this
+ *        request is available
  * @param pay_cb_cls closure for @a pay_cb
  * @return a handle for this request
  */
@@ -924,7 +956,7 @@ TALER_MERCHANT_pay_cancel (struct TALER_MERCHANT_Pay *pay)
   }
   GNUNET_free (pay->coins);
   GNUNET_free (pay->url);
-  GNUNET_free (pay->json_enc);
+  GNUNET_free (pay->post_ctx.json_enc);
   GNUNET_free (pay);
 }
 
diff --git a/src/lib/merchant_api_proposal.c b/src/lib/merchant_api_proposal.c
index 0013a5f..acbda06 100644
--- a/src/lib/merchant_api_proposal.c
+++ b/src/lib/merchant_api_proposal.c
@@ -163,23 +163,25 @@ handle_proposal_finished (void *cls,
     }
     break;
   case MHD_HTTP_BAD_REQUEST:
-      /* This should never happen, either us or the merchant is buggy
-         (or API version conflict); just pass JSON reply to the application */
+      /* This should never happen, either us or
+         the merchant is buggy (or API version conflict);
+         just pass JSON reply to the application */
     break;
   case MHD_HTTP_FORBIDDEN:
     break;
   case MHD_HTTP_UNAUTHORIZED:
-    /* Nothing really to verify, merchant says one of the signatures is
-       invalid; as we checked them, this should never happen, we
-       should pass the JSON reply to the application */
+    /* Nothing really to verify, merchant says one
+       of the signatures is invalid; as we checked them,
+       this should never happen, we should pass the JSON
+       reply to the application */
     break;
   case MHD_HTTP_NOT_FOUND:
     /* Nothing really to verify, this should never
        happen, we should pass the JSON reply to the application */
     break;
   case MHD_HTTP_INTERNAL_SERVER_ERROR:
-    /* Server had an internal issue; we should retry, but this API
-       leaves this to the application */
+    /* Server had an internal issue; we should retry,
+       but this API leaves this to the application */
     break;
   default:
     /* unexpected response code */
@@ -204,10 +206,10 @@ handle_proposal_finished (void *cls,
  *
  * @param ctx execution context
  * @param backend_url URL of the backend
- * @param order basic information about this purchase, to be extended by the
- * backend
- * @param proposal_cb the callback to call when a reply for this request is
- * available
+ * @param order basic information about this purchase,
+ *        to be extended by the backend
+ * @param proposal_cb the callback to call when a reply
+ *        for this request is available
  * @param proposal_cb_cls closure for @a proposal_cb
  * @return a handle for this request, NULL on error
  */
@@ -232,8 +234,8 @@ TALER_MERCHANT_order_put
                    "order", (json_t *) order);
   eh = curl_easy_init ();
   if (GNUNET_OK != TALER_curl_easy_post (&po->post_ctx,
-                                        eh,
-                                        req))
+                                         eh,
+                                         req))
   {
     GNUNET_break (0);
     GNUNET_free (po);

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



reply via email to

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