gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-exchange] branch master updated: put curl default op


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated: put curl default options on one place
Date: Sat, 22 Sep 2018 01:23:29 +0200

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

dold pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new 4e0c95f0 put curl default options on one place
4e0c95f0 is described below

commit 4e0c95f0c26a4cfdfd6d2499d13e6c1238fa5e94
Author: Florian Dold <address@hidden>
AuthorDate: Sat Sep 22 01:21:55 2018 +0200

    put curl default options on one place
---
 src/exchange-lib/Makefile.am                      |  2 +
 src/exchange-lib/curl_defaults.c                  | 53 +++++++++++++++++++++++
 src/exchange-lib/curl_defaults.h                  | 35 +++++++++++++++
 src/exchange-lib/exchange_api_deposit.c           | 11 +----
 src/exchange-lib/exchange_api_handle.c            | 15 +------
 src/exchange-lib/exchange_api_payback.c           | 11 +----
 src/exchange-lib/exchange_api_refresh.c           | 21 ++-------
 src/exchange-lib/exchange_api_refresh_link.c      | 12 ++---
 src/exchange-lib/exchange_api_refund.c            | 11 +----
 src/exchange-lib/exchange_api_reserve.c           | 17 ++------
 src/exchange-lib/exchange_api_track_transaction.c | 11 +----
 src/exchange-lib/exchange_api_track_transfer.c    | 11 +----
 src/exchange-lib/exchange_api_wire.c              | 11 +----
 13 files changed, 113 insertions(+), 108 deletions(-)

diff --git a/src/exchange-lib/Makefile.am b/src/exchange-lib/Makefile.am
index 8ac43ea8..3e1b4507 100644
--- a/src/exchange-lib/Makefile.am
+++ b/src/exchange-lib/Makefile.am
@@ -14,6 +14,7 @@ libtalerexchange_la_LDFLAGS = \
   -version-info 4:0:0 \
   -no-undefined
 libtalerexchange_la_SOURCES = \
+  curl_defaults.c \
   exchange_api_common.c \
   exchange_api_handle.c exchange_api_handle.h \
   exchange_api_deposit.c \
@@ -38,6 +39,7 @@ libtalertesting_la_LDFLAGS = \
   -version-info 0:0:0 \
   -no-undefined
 libtalertesting_la_SOURCES = \
+  curl_defaults.c \
   testing_api_cmd_exec_aggregator.c \
   testing_api_cmd_exec_wirewatch.c \
   testing_api_cmd_exec_keyup.c \
diff --git a/src/exchange-lib/curl_defaults.c b/src/exchange-lib/curl_defaults.c
new file mode 100644
index 00000000..ccadffa2
--- /dev/null
+++ b/src/exchange-lib/curl_defaults.c
@@ -0,0 +1,53 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-2018 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 exchange-lib/curl_defaults.c
+ * @brief curl easy handle defaults
+ * @author Florian Dold
+ */
+
+#include "curl_defaults.h"
+
+
+/**
+ * Get a curl handle with the right defaults
+ * for the exchange lib.  In the future, we might manage a pool of connections 
here.
+ *
+ * @param url URL to query
+ */
+CURL *
+TEL_curl_easy_get (char *url)
+{
+  CURL *eh;
+  
+  eh = curl_easy_init ();
+
+  GNUNET_assert (CURLE_OK ==
+                 curl_easy_setopt (eh,
+                                   CURLOPT_URL,
+                                   url));
+  GNUNET_assert (CURLE_OK ==
+                 curl_easy_setopt (eh,
+                                   CURLOPT_ENCODING,
+                                   "deflate"));
+  GNUNET_assert (CURLE_OK ==
+                 curl_easy_setopt (eh,
+                                   CURLOPT_TCP_FASTOPEN,
+                                   1L));
+
+  return eh;
+}
diff --git a/src/exchange-lib/curl_defaults.h b/src/exchange-lib/curl_defaults.h
new file mode 100644
index 00000000..87fccf84
--- /dev/null
+++ b/src/exchange-lib/curl_defaults.h
@@ -0,0 +1,35 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-2018 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 exchange-lib/curl_defaults.h
+ * @brief curl easy handle defaults
+ * @author Florian Dold
+ */
+
+#include "platform.h"
+#include <gnunet/gnunet_curl_lib.h>
+
+
+/**
+ * Get a curl handle with the right defaults
+ * for the exchange lib.  In the future, we might manage a pool of connections 
here.
+ *
+ * @param url URL to query
+ */
+CURL *
+TEL_curl_easy_get (char *url);
diff --git a/src/exchange-lib/exchange_api_deposit.c 
b/src/exchange-lib/exchange_api_deposit.c
index 50d52588..53fd3c6e 100644
--- a/src/exchange-lib/exchange_api_deposit.c
+++ b/src/exchange-lib/exchange_api_deposit.c
@@ -30,6 +30,7 @@
 #include "taler_exchange_service.h"
 #include "exchange_api_handle.h"
 #include "taler_signatures.h"
+#include "curl_defaults.h"
 
 
 /**
@@ -490,7 +491,7 @@ TALER_EXCHANGE_deposit (struct TALER_EXCHANGE_Handle 
*exchange,
   dh->amount_with_fee = *amount;
   dh->coin_value = dki->value;
 
-  eh = curl_easy_init ();
+  eh = TEL_curl_easy_get (dh->url);
   GNUNET_assert (NULL != (dh->json_enc =
                           json_dumps (deposit_obj,
                                       JSON_COMPACT)));
@@ -500,18 +501,10 @@ TALER_EXCHANGE_deposit (struct TALER_EXCHANGE_Handle 
*exchange,
               dh->url);
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
-                                   CURLOPT_URL,
-                                   dh->url));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
                                    CURLOPT_POSTFIELDS,
                                    dh->json_enc));
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
-                                   CURLOPT_ENCODING,
-                                   "deflate"));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
                                    CURLOPT_POSTFIELDSIZE,
                                    strlen (dh->json_enc)));
   ctx = MAH_handle_to_context (exchange);
diff --git a/src/exchange-lib/exchange_api_handle.c 
b/src/exchange-lib/exchange_api_handle.c
index 2b5ff18e..4a3c843d 100644
--- a/src/exchange-lib/exchange_api_handle.c
+++ b/src/exchange-lib/exchange_api_handle.c
@@ -27,6 +27,7 @@
 #include "taler_exchange_service.h"
 #include "taler_signatures.h"
 #include "exchange_api_handle.h"
+#include "curl_defaults.h"
 
 /**
  * Which revision of the Taler protocol is implemented
@@ -1176,7 +1177,7 @@ request_keys (void *cls)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Requesting keys with URL `%s'.\n",
               kr->url);
-  eh = curl_easy_init ();
+  eh = TEL_curl_easy_get (kr->url);
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
                                    CURLOPT_VERBOSE,
@@ -1193,18 +1194,6 @@ request_keys (void *cls)
                  curl_easy_setopt (eh,
                                    CURLOPT_HEADERDATA,
                                    kr));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_URL,
-                                   kr->url));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_ENCODING,
-                                   "deflate"));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_TCP_FASTOPEN,
-                                   1L));
   kr->job = GNUNET_CURL_job_add (exchange->ctx,
                                  eh,
                                  GNUNET_NO,
diff --git a/src/exchange-lib/exchange_api_payback.c 
b/src/exchange-lib/exchange_api_payback.c
index 767ab5c8..8eb9b0c1 100644
--- a/src/exchange-lib/exchange_api_payback.c
+++ b/src/exchange-lib/exchange_api_payback.c
@@ -29,6 +29,7 @@
 #include "taler_exchange_service.h"
 #include "exchange_api_handle.h"
 #include "taler_signatures.h"
+#include "curl_defaults.h"
 
 
 /**
@@ -317,7 +318,6 @@ TALER_EXCHANGE_payback (struct TALER_EXCHANGE_Handle 
*exchange,
   ph->cb_cls = payback_cb_cls;
   ph->url = MAH_path_to_url (exchange, "/payback");
 
-  eh = curl_easy_init ();
   ph->json_enc = json_dumps (payback_obj,
                              JSON_COMPACT);
   json_decref (payback_obj);
@@ -328,19 +328,12 @@ TALER_EXCHANGE_payback (struct TALER_EXCHANGE_Handle 
*exchange,
     GNUNET_free (ph);
     return NULL;
   }
+  eh = TEL_curl_easy_get (ph->url);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "URL for payback: `%s'\n",
               ph->url);
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
-                                   CURLOPT_URL,
-                                   ph->url));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_ENCODING,
-                                   "deflate"));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
                                    CURLOPT_POSTFIELDS,
                                    ph->json_enc));
   GNUNET_assert (CURLE_OK ==
diff --git a/src/exchange-lib/exchange_api_refresh.c 
b/src/exchange-lib/exchange_api_refresh.c
index 7610d5ca..b1eff1d5 100644
--- a/src/exchange-lib/exchange_api_refresh.c
+++ b/src/exchange-lib/exchange_api_refresh.c
@@ -29,6 +29,7 @@
 #include "taler_exchange_service.h"
 #include "exchange_api_handle.h"
 #include "taler_signatures.h"
+#include "curl_defaults.h"
 
 
 /* ********************* /refresh/ common ***************************** */
@@ -1200,25 +1201,17 @@ TALER_EXCHANGE_refresh_melt (struct 
TALER_EXCHANGE_Handle *exchange,
   rmh->md = md;
   rmh->url = MAH_path_to_url (exchange,
                               "/refresh/melt");
-  eh = curl_easy_init ();
+  eh = TEL_curl_easy_get (rmh->url);
   GNUNET_assert (NULL != (rmh->json_enc =
                           json_dumps (melt_obj,
                                       JSON_COMPACT)));
   json_decref (melt_obj);
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
-                                   CURLOPT_URL,
-                                   rmh->url));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
                                    CURLOPT_POSTFIELDS,
                                    rmh->json_enc));
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
-                                   CURLOPT_ENCODING,
-                                   "deflate"));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
                                    CURLOPT_POSTFIELDSIZE,
                                    strlen (rmh->json_enc)));
   ctx = MAH_handle_to_context (exchange);
@@ -1635,27 +1628,19 @@ TALER_EXCHANGE_refresh_reveal (struct 
TALER_EXCHANGE_Handle *exchange,
   rrh->url = MAH_path_to_url (rrh->exchange,
                               "/refresh/reveal");
 
-  eh = curl_easy_init ();
+  eh = TEL_curl_easy_get (rrh->url);
   GNUNET_assert (NULL != (rrh->json_enc =
                           json_dumps (reveal_obj,
                                       JSON_COMPACT)));
   json_decref (reveal_obj);
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
-                                   CURLOPT_URL,
-                                   rrh->url));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
                                    CURLOPT_POSTFIELDS,
                                    rrh->json_enc));
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
                                    CURLOPT_POSTFIELDSIZE,
                                    strlen (rrh->json_enc)));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_ENCODING,
-                                   "deflate"));
   ctx = MAH_handle_to_context (rrh->exchange);
   rrh->job = GNUNET_CURL_job_add (ctx,
                                   eh,
diff --git a/src/exchange-lib/exchange_api_refresh_link.c 
b/src/exchange-lib/exchange_api_refresh_link.c
index 1259a226..d7ca8165 100644
--- a/src/exchange-lib/exchange_api_refresh_link.c
+++ b/src/exchange-lib/exchange_api_refresh_link.c
@@ -27,6 +27,7 @@
 #include "taler_json_lib.h"
 #include "exchange_api_handle.h"
 #include "taler_signatures.h"
+#include "curl_defaults.h"
 
 
 /**
@@ -408,15 +409,8 @@ TALER_EXCHANGE_refresh_link (struct TALER_EXCHANGE_Handle 
*exchange,
   rlh->url = MAH_path_to_url (exchange, arg_str);
   GNUNET_free (arg_str);
 
-  eh = curl_easy_init ();
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_URL,
-                                   rlh->url));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_ENCODING,
-                                   "deflate"));
+
+  eh = TEL_curl_easy_get (rlh->url);
   ctx = MAH_handle_to_context (exchange);
   rlh->job = GNUNET_CURL_job_add (ctx,
                           eh,
diff --git a/src/exchange-lib/exchange_api_refund.c 
b/src/exchange-lib/exchange_api_refund.c
index 1a50b090..f4b118d7 100644
--- a/src/exchange-lib/exchange_api_refund.c
+++ b/src/exchange-lib/exchange_api_refund.c
@@ -29,6 +29,7 @@
 #include "taler_exchange_service.h"
 #include "exchange_api_handle.h"
 #include "taler_signatures.h"
+#include "curl_defaults.h"
 
 
 /**
@@ -365,7 +366,7 @@ refund_obj = json_pack ("{s:o, s:o," /* amount/fee */
   TALER_amount_hton (&rh->depconf.refund_fee,
                      refund_fee);
 
-  eh = curl_easy_init ();
+  eh = TEL_curl_easy_get (rh->url);
   GNUNET_assert (NULL != (rh->json_enc =
                           json_dumps (refund_obj,
                                       JSON_COMPACT)));
@@ -375,14 +376,6 @@ refund_obj = json_pack ("{s:o, s:o," /* amount/fee */
               rh->url);
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
-                                   CURLOPT_URL,
-                                   rh->url));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_ENCODING,
-                                   "deflate"));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
                                    CURLOPT_POSTFIELDS,
                                    rh->json_enc));
   GNUNET_assert (CURLE_OK ==
diff --git a/src/exchange-lib/exchange_api_reserve.c 
b/src/exchange-lib/exchange_api_reserve.c
index c75639fe..58105e42 100644
--- a/src/exchange-lib/exchange_api_reserve.c
+++ b/src/exchange-lib/exchange_api_reserve.c
@@ -29,6 +29,7 @@
 #include "taler_json_lib.h"
 #include "exchange_api_handle.h"
 #include "taler_signatures.h"
+#include "curl_defaults.h"
 
 
 /* ********************** /reserve/status ********************** */
@@ -625,15 +626,7 @@ TALER_EXCHANGE_reserve_status (struct 
TALER_EXCHANGE_Handle *exchange,
                               arg_str);
   GNUNET_free (arg_str);
 
-  eh = curl_easy_init ();
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_URL,
-                                   rsh->url));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_ENCODING,
-                                   "deflate"));
+  eh = TEL_curl_easy_get (rsh->url);
   ctx = MAH_handle_to_context (exchange);
   rsh->job = GNUNET_CURL_job_add (ctx,
                           eh,
@@ -1029,17 +1022,13 @@ reserve_withdraw_internal (struct TALER_EXCHANGE_Handle 
*exchange,
   wsh->ps = *ps;
   wsh->url = MAH_path_to_url (exchange, "/reserve/withdraw");
 
-  eh = curl_easy_init ();
+  eh = TEL_curl_easy_get (wsh->url);
   GNUNET_assert (NULL != (wsh->json_enc =
                           json_dumps (withdraw_obj,
                                       JSON_COMPACT)));
   json_decref (withdraw_obj);
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
-                                   CURLOPT_URL,
-                                   wsh->url));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
                                    CURLOPT_POSTFIELDS,
                                    wsh->json_enc));
   GNUNET_assert (CURLE_OK ==
diff --git a/src/exchange-lib/exchange_api_track_transaction.c 
b/src/exchange-lib/exchange_api_track_transaction.c
index 90585876..3febf20f 100644
--- a/src/exchange-lib/exchange_api_track_transaction.c
+++ b/src/exchange-lib/exchange_api_track_transaction.c
@@ -29,6 +29,7 @@
 #include "taler_exchange_service.h"
 #include "exchange_api_handle.h"
 #include "taler_signatures.h"
+#include "curl_defaults.h"
 
 
 /**
@@ -319,21 +320,13 @@ TALER_EXCHANGE_track_transaction (struct 
TALER_EXCHANGE_Handle *exchange,
   dwh->depconf.h_contract_terms = *h_contract_terms;
   dwh->depconf.coin_pub = *coin_pub;
 
-  eh = curl_easy_init ();
+  eh = TEL_curl_easy_get (dwh->url);
   GNUNET_assert (NULL != (dwh->json_enc =
                           json_dumps (deposit_wtid_obj,
                                       JSON_COMPACT)));
   json_decref (deposit_wtid_obj);
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
-                                   CURLOPT_URL,
-                                   dwh->url));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_ENCODING,
-                                   "deflate"));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
                                    CURLOPT_POSTFIELDS,
                                    dwh->json_enc));
   GNUNET_assert (CURLE_OK ==
diff --git a/src/exchange-lib/exchange_api_track_transfer.c 
b/src/exchange-lib/exchange_api_track_transfer.c
index 0412a174..4ec2a50c 100644
--- a/src/exchange-lib/exchange_api_track_transfer.c
+++ b/src/exchange-lib/exchange_api_track_transfer.c
@@ -28,6 +28,7 @@
 #include "taler_json_lib.h"
 #include "exchange_api_handle.h"
 #include "taler_signatures.h"
+#include "curl_defaults.h"
 
 
 /**
@@ -353,15 +354,7 @@ TALER_EXCHANGE_track_transfer (struct 
TALER_EXCHANGE_Handle *exchange,
   GNUNET_free (buf);
   GNUNET_free (path);
 
-  eh = curl_easy_init ();
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_URL,
-                                   wdh->url));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_ENCODING,
-                                   "deflate"));
+  eh = TEL_curl_easy_get (wdh->url);
   ctx = MAH_handle_to_context (exchange);
   wdh->job = GNUNET_CURL_job_add (ctx,
                           eh,
diff --git a/src/exchange-lib/exchange_api_wire.c 
b/src/exchange-lib/exchange_api_wire.c
index fe6e1c5e..af7bbf3b 100644
--- a/src/exchange-lib/exchange_api_wire.c
+++ b/src/exchange-lib/exchange_api_wire.c
@@ -30,6 +30,7 @@
 #include "taler_signatures.h"
 #include "taler_wire_plugin.h"
 #include "exchange_api_handle.h"
+#include "curl_defaults.h"
 
 
 /**
@@ -407,15 +408,7 @@ TALER_EXCHANGE_wire (struct TALER_EXCHANGE_Handle 
*exchange,
   wh->cb_cls = wire_cb_cls;
   wh->url = MAH_path_to_url (exchange, "/wire");
 
-  eh = curl_easy_init ();
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_URL,
-                                   wh->url));
-  GNUNET_assert (CURLE_OK ==
-                 curl_easy_setopt (eh,
-                                   CURLOPT_ENCODING,
-                                   "deflate"));
+  eh = TEL_curl_easy_get (wh->url);
   ctx = MAH_handle_to_context (exchange);
   wh->job = GNUNET_CURL_job_add (ctx,
                          eh,

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



reply via email to

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