put curl default options on one place

This commit is contained in:
Florian Dold 2018-09-22 01:21:55 +02:00
parent 310b120d5d
commit 4e0c95f0c2
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
13 changed files with 113 additions and 108 deletions

View File

@ -14,6 +14,7 @@ libtalerexchange_la_LDFLAGS = \
-version-info 4:0:0 \ -version-info 4:0:0 \
-no-undefined -no-undefined
libtalerexchange_la_SOURCES = \ libtalerexchange_la_SOURCES = \
curl_defaults.c \
exchange_api_common.c \ exchange_api_common.c \
exchange_api_handle.c exchange_api_handle.h \ exchange_api_handle.c exchange_api_handle.h \
exchange_api_deposit.c \ exchange_api_deposit.c \
@ -38,6 +39,7 @@ libtalertesting_la_LDFLAGS = \
-version-info 0:0:0 \ -version-info 0:0:0 \
-no-undefined -no-undefined
libtalertesting_la_SOURCES = \ libtalertesting_la_SOURCES = \
curl_defaults.c \
testing_api_cmd_exec_aggregator.c \ testing_api_cmd_exec_aggregator.c \
testing_api_cmd_exec_wirewatch.c \ testing_api_cmd_exec_wirewatch.c \
testing_api_cmd_exec_keyup.c \ testing_api_cmd_exec_keyup.c \

View File

@ -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;
}

View File

@ -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);

View File

@ -30,6 +30,7 @@
#include "taler_exchange_service.h" #include "taler_exchange_service.h"
#include "exchange_api_handle.h" #include "exchange_api_handle.h"
#include "taler_signatures.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->amount_with_fee = *amount;
dh->coin_value = dki->value; dh->coin_value = dki->value;
eh = curl_easy_init (); eh = TEL_curl_easy_get (dh->url);
GNUNET_assert (NULL != (dh->json_enc = GNUNET_assert (NULL != (dh->json_enc =
json_dumps (deposit_obj, json_dumps (deposit_obj,
JSON_COMPACT))); JSON_COMPACT)));
@ -498,18 +499,10 @@ TALER_EXCHANGE_deposit (struct TALER_EXCHANGE_Handle *exchange,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for deposit: `%s'\n", "URL for deposit: `%s'\n",
dh->url); dh->url);
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_URL,
dh->url));
GNUNET_assert (CURLE_OK == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_POSTFIELDS, CURLOPT_POSTFIELDS,
dh->json_enc)); dh->json_enc));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_ENCODING,
"deflate"));
GNUNET_assert (CURLE_OK == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE, CURLOPT_POSTFIELDSIZE,

View File

@ -27,6 +27,7 @@
#include "taler_exchange_service.h" #include "taler_exchange_service.h"
#include "taler_signatures.h" #include "taler_signatures.h"
#include "exchange_api_handle.h" #include "exchange_api_handle.h"
#include "curl_defaults.h"
/** /**
* Which revision of the Taler protocol is implemented * Which revision of the Taler protocol is implemented
@ -1176,7 +1177,7 @@ request_keys (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Requesting keys with URL `%s'.\n", "Requesting keys with URL `%s'.\n",
kr->url); kr->url);
eh = curl_easy_init (); eh = TEL_curl_easy_get (kr->url);
GNUNET_assert (CURLE_OK == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_VERBOSE, CURLOPT_VERBOSE,
@ -1193,18 +1194,6 @@ request_keys (void *cls)
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_HEADERDATA, CURLOPT_HEADERDATA,
kr)); 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, kr->job = GNUNET_CURL_job_add (exchange->ctx,
eh, eh,
GNUNET_NO, GNUNET_NO,

View File

@ -29,6 +29,7 @@
#include "taler_exchange_service.h" #include "taler_exchange_service.h"
#include "exchange_api_handle.h" #include "exchange_api_handle.h"
#include "taler_signatures.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->cb_cls = payback_cb_cls;
ph->url = MAH_path_to_url (exchange, "/payback"); ph->url = MAH_path_to_url (exchange, "/payback");
eh = curl_easy_init ();
ph->json_enc = json_dumps (payback_obj, ph->json_enc = json_dumps (payback_obj,
JSON_COMPACT); JSON_COMPACT);
json_decref (payback_obj); json_decref (payback_obj);
@ -328,17 +328,10 @@ TALER_EXCHANGE_payback (struct TALER_EXCHANGE_Handle *exchange,
GNUNET_free (ph); GNUNET_free (ph);
return NULL; return NULL;
} }
eh = TEL_curl_easy_get (ph->url);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for payback: `%s'\n", "URL for payback: `%s'\n",
ph->url); 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 == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_POSTFIELDS, CURLOPT_POSTFIELDS,

View File

@ -29,6 +29,7 @@
#include "taler_exchange_service.h" #include "taler_exchange_service.h"
#include "exchange_api_handle.h" #include "exchange_api_handle.h"
#include "taler_signatures.h" #include "taler_signatures.h"
#include "curl_defaults.h"
/* ********************* /refresh/ common ***************************** */ /* ********************* /refresh/ common ***************************** */
@ -1200,23 +1201,15 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange,
rmh->md = md; rmh->md = md;
rmh->url = MAH_path_to_url (exchange, rmh->url = MAH_path_to_url (exchange,
"/refresh/melt"); "/refresh/melt");
eh = curl_easy_init (); eh = TEL_curl_easy_get (rmh->url);
GNUNET_assert (NULL != (rmh->json_enc = GNUNET_assert (NULL != (rmh->json_enc =
json_dumps (melt_obj, json_dumps (melt_obj,
JSON_COMPACT))); JSON_COMPACT)));
json_decref (melt_obj); json_decref (melt_obj);
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_URL,
rmh->url));
GNUNET_assert (CURLE_OK == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_POSTFIELDS, CURLOPT_POSTFIELDS,
rmh->json_enc)); rmh->json_enc));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_ENCODING,
"deflate"));
GNUNET_assert (CURLE_OK == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE, CURLOPT_POSTFIELDSIZE,
@ -1635,15 +1628,11 @@ TALER_EXCHANGE_refresh_reveal (struct TALER_EXCHANGE_Handle *exchange,
rrh->url = MAH_path_to_url (rrh->exchange, rrh->url = MAH_path_to_url (rrh->exchange,
"/refresh/reveal"); "/refresh/reveal");
eh = curl_easy_init (); eh = TEL_curl_easy_get (rrh->url);
GNUNET_assert (NULL != (rrh->json_enc = GNUNET_assert (NULL != (rrh->json_enc =
json_dumps (reveal_obj, json_dumps (reveal_obj,
JSON_COMPACT))); JSON_COMPACT)));
json_decref (reveal_obj); json_decref (reveal_obj);
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_URL,
rrh->url));
GNUNET_assert (CURLE_OK == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_POSTFIELDS, CURLOPT_POSTFIELDS,
@ -1652,10 +1641,6 @@ TALER_EXCHANGE_refresh_reveal (struct TALER_EXCHANGE_Handle *exchange,
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE, CURLOPT_POSTFIELDSIZE,
strlen (rrh->json_enc))); strlen (rrh->json_enc)));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_ENCODING,
"deflate"));
ctx = MAH_handle_to_context (rrh->exchange); ctx = MAH_handle_to_context (rrh->exchange);
rrh->job = GNUNET_CURL_job_add (ctx, rrh->job = GNUNET_CURL_job_add (ctx,
eh, eh,

View File

@ -27,6 +27,7 @@
#include "taler_json_lib.h" #include "taler_json_lib.h"
#include "exchange_api_handle.h" #include "exchange_api_handle.h"
#include "taler_signatures.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); rlh->url = MAH_path_to_url (exchange, arg_str);
GNUNET_free (arg_str); GNUNET_free (arg_str);
eh = curl_easy_init ();
GNUNET_assert (CURLE_OK == eh = TEL_curl_easy_get (rlh->url);
curl_easy_setopt (eh,
CURLOPT_URL,
rlh->url));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_ENCODING,
"deflate"));
ctx = MAH_handle_to_context (exchange); ctx = MAH_handle_to_context (exchange);
rlh->job = GNUNET_CURL_job_add (ctx, rlh->job = GNUNET_CURL_job_add (ctx,
eh, eh,

View File

@ -29,6 +29,7 @@
#include "taler_exchange_service.h" #include "taler_exchange_service.h"
#include "exchange_api_handle.h" #include "exchange_api_handle.h"
#include "taler_signatures.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, TALER_amount_hton (&rh->depconf.refund_fee,
refund_fee); refund_fee);
eh = curl_easy_init (); eh = TEL_curl_easy_get (rh->url);
GNUNET_assert (NULL != (rh->json_enc = GNUNET_assert (NULL != (rh->json_enc =
json_dumps (refund_obj, json_dumps (refund_obj,
JSON_COMPACT))); JSON_COMPACT)));
@ -373,14 +374,6 @@ refund_obj = json_pack ("{s:o, s:o," /* amount/fee */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for refund: `%s'\n", "URL for refund: `%s'\n",
rh->url); 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 == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_POSTFIELDS, CURLOPT_POSTFIELDS,

View File

@ -29,6 +29,7 @@
#include "taler_json_lib.h" #include "taler_json_lib.h"
#include "exchange_api_handle.h" #include "exchange_api_handle.h"
#include "taler_signatures.h" #include "taler_signatures.h"
#include "curl_defaults.h"
/* ********************** /reserve/status ********************** */ /* ********************** /reserve/status ********************** */
@ -625,15 +626,7 @@ TALER_EXCHANGE_reserve_status (struct TALER_EXCHANGE_Handle *exchange,
arg_str); arg_str);
GNUNET_free (arg_str); GNUNET_free (arg_str);
eh = curl_easy_init (); eh = TEL_curl_easy_get (rsh->url);
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_URL,
rsh->url));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_ENCODING,
"deflate"));
ctx = MAH_handle_to_context (exchange); ctx = MAH_handle_to_context (exchange);
rsh->job = GNUNET_CURL_job_add (ctx, rsh->job = GNUNET_CURL_job_add (ctx,
eh, eh,
@ -1029,15 +1022,11 @@ reserve_withdraw_internal (struct TALER_EXCHANGE_Handle *exchange,
wsh->ps = *ps; wsh->ps = *ps;
wsh->url = MAH_path_to_url (exchange, "/reserve/withdraw"); 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 = GNUNET_assert (NULL != (wsh->json_enc =
json_dumps (withdraw_obj, json_dumps (withdraw_obj,
JSON_COMPACT))); JSON_COMPACT)));
json_decref (withdraw_obj); json_decref (withdraw_obj);
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_URL,
wsh->url));
GNUNET_assert (CURLE_OK == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_POSTFIELDS, CURLOPT_POSTFIELDS,

View File

@ -29,6 +29,7 @@
#include "taler_exchange_service.h" #include "taler_exchange_service.h"
#include "exchange_api_handle.h" #include "exchange_api_handle.h"
#include "taler_signatures.h" #include "taler_signatures.h"
#include "curl_defaults.h"
/** /**
@ -319,19 +320,11 @@ TALER_EXCHANGE_track_transaction (struct TALER_EXCHANGE_Handle *exchange,
dwh->depconf.h_contract_terms = *h_contract_terms; dwh->depconf.h_contract_terms = *h_contract_terms;
dwh->depconf.coin_pub = *coin_pub; dwh->depconf.coin_pub = *coin_pub;
eh = curl_easy_init (); eh = TEL_curl_easy_get (dwh->url);
GNUNET_assert (NULL != (dwh->json_enc = GNUNET_assert (NULL != (dwh->json_enc =
json_dumps (deposit_wtid_obj, json_dumps (deposit_wtid_obj,
JSON_COMPACT))); JSON_COMPACT)));
json_decref (deposit_wtid_obj); 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 == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_POSTFIELDS, CURLOPT_POSTFIELDS,

View File

@ -28,6 +28,7 @@
#include "taler_json_lib.h" #include "taler_json_lib.h"
#include "exchange_api_handle.h" #include "exchange_api_handle.h"
#include "taler_signatures.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 (buf);
GNUNET_free (path); GNUNET_free (path);
eh = curl_easy_init (); eh = TEL_curl_easy_get (wdh->url);
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_URL,
wdh->url));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_ENCODING,
"deflate"));
ctx = MAH_handle_to_context (exchange); ctx = MAH_handle_to_context (exchange);
wdh->job = GNUNET_CURL_job_add (ctx, wdh->job = GNUNET_CURL_job_add (ctx,
eh, eh,

View File

@ -30,6 +30,7 @@
#include "taler_signatures.h" #include "taler_signatures.h"
#include "taler_wire_plugin.h" #include "taler_wire_plugin.h"
#include "exchange_api_handle.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->cb_cls = wire_cb_cls;
wh->url = MAH_path_to_url (exchange, "/wire"); wh->url = MAH_path_to_url (exchange, "/wire");
eh = curl_easy_init (); eh = TEL_curl_easy_get (wh->url);
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_URL,
wh->url));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_ENCODING,
"deflate"));
ctx = MAH_handle_to_context (exchange); ctx = MAH_handle_to_context (exchange);
wh->job = GNUNET_CURL_job_add (ctx, wh->job = GNUNET_CURL_job_add (ctx,
eh, eh,