put curl default options on one place
This commit is contained in:
parent
310b120d5d
commit
4e0c95f0c2
@ -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 \
|
||||
|
53
src/exchange-lib/curl_defaults.c
Normal file
53
src/exchange-lib/curl_defaults.c
Normal 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;
|
||||
}
|
35
src/exchange-lib/curl_defaults.h
Normal file
35
src/exchange-lib/curl_defaults.h
Normal 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);
|
@ -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)));
|
||||
@ -498,18 +499,10 @@ TALER_EXCHANGE_deposit (struct TALER_EXCHANGE_Handle *exchange,
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||
"URL for deposit: `%s'\n",
|
||||
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,
|
||||
|
@ -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,
|
||||
|
@ -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,17 +328,10 @@ 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,
|
||||
|
@ -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,23 +1201,15 @@ 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,
|
||||
@ -1635,15 +1628,11 @@ 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,
|
||||
@ -1652,10 +1641,6 @@ TALER_EXCHANGE_refresh_reveal (struct TALER_EXCHANGE_Handle *exchange,
|
||||
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,
|
||||
|
@ -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,
|
||||
|
@ -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)));
|
||||
@ -373,14 +374,6 @@ refund_obj = json_pack ("{s:o, s:o," /* amount/fee */
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||
"URL for refund: `%s'\n",
|
||||
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,
|
||||
|
@ -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,15 +1022,11 @@ 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,
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "taler_exchange_service.h"
|
||||
#include "exchange_api_handle.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.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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user