add compression support for bodies of POST/PUT operations

This commit is contained in:
Christian Grothoff 2019-05-03 17:36:58 +02:00
parent 5dd3c2191a
commit a16c32a474
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
15 changed files with 338 additions and 127 deletions

View File

@ -1,3 +1,7 @@
Fri 03 May 2019 05:36:10 PM CEST
Add support for compressing bodies during HTTP uploads to
exchange and auditor. -CG
Thu 02 May 2019 09:15:37 PM CEST Thu 02 May 2019 09:15:37 PM CEST
Pass hash of denomination public key in operations from Pass hash of denomination public key in operations from
clients to exchange instead of the (larger) full public key. clients to exchange instead of the (larger) full public key.

View File

@ -27,7 +27,8 @@ libtalerexchange_la_SOURCES = \
exchange_api_reserve.c \ exchange_api_reserve.c \
exchange_api_track_transaction.c \ exchange_api_track_transaction.c \
exchange_api_track_transfer.c \ exchange_api_track_transfer.c \
exchange_api_wire.c exchange_api_wire.c \
teah_common.c teah_common.h
libtalerexchange_la_LIBADD = \ libtalerexchange_la_LIBADD = \
libtalerauditor.la \ libtalerauditor.la \
$(top_builddir)/src/json/libtalerjson.la \ $(top_builddir)/src/json/libtalerjson.la \
@ -46,7 +47,8 @@ libtalerauditor_la_SOURCES = \
auditor_api_curl_defaults.c auditor_api_curl_defaults.h \ auditor_api_curl_defaults.c auditor_api_curl_defaults.h \
auditor_api_handle.c auditor_api_handle.h \ auditor_api_handle.c auditor_api_handle.h \
auditor_api_deposit_confirmation.c \ auditor_api_deposit_confirmation.c \
auditor_api_exchanges.c auditor_api_exchanges.c \
teah_common.c teah_common.h
libtalerauditor_la_LIBADD = \ libtalerauditor_la_LIBADD = \
$(top_builddir)/src/json/libtalerjson.la \ $(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \ $(top_builddir)/src/util/libtalerutil.la \

View File

@ -49,9 +49,10 @@ struct TALER_AUDITOR_DepositConfirmationHandle
char *url; char *url;
/** /**
* JSON encoding of the request to POST. * Context for #TEH_curl_easy_post(). Keeps the data that must
* persist for Curl to make the upload.
*/ */
char *json_enc; struct TEAH_PostContext ctx;
/** /**
* Handle for the request. * Handle for the request.
@ -338,26 +339,26 @@ TALER_AUDITOR_deposit_confirmation (struct TALER_AUDITOR_Handle *auditor,
dh->url = MAH_path_to_url (auditor, "/deposit-confirmation"); dh->url = MAH_path_to_url (auditor, "/deposit-confirmation");
eh = TAL_curl_easy_get (dh->url); eh = TAL_curl_easy_get (dh->url);
GNUNET_assert (NULL != (dh->json_enc =
json_dumps (deposit_confirmation_obj,
JSON_COMPACT)));
json_decref (deposit_confirmation_obj);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for deposit-confirmation: `%s'\n",
dh->url);
GNUNET_assert (CURLE_OK == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_CUSTOMREQUEST, CURLOPT_CUSTOMREQUEST,
"PUT")); "PUT"));
GNUNET_assert (CURLE_OK == if (GNUNET_OK !=
curl_easy_setopt (eh, TEAH_curl_easy_post (&dh->ctx,
CURLOPT_POSTFIELDS, eh,
dh->json_enc)); deposit_confirmation_obj))
GNUNET_assert (CURLE_OK == {
curl_easy_setopt (eh, GNUNET_break (0);
CURLOPT_POSTFIELDSIZE, curl_easy_cleanup (eh);
strlen (dh->json_enc))); json_decref (deposit_confirmation_obj);
GNUNET_free (dh->url);
GNUNET_free (dh);
return NULL;
}
json_decref (deposit_confirmation_obj);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for deposit-confirmation: `%s'\n",
dh->url);
ctx = MAH_handle_to_context (auditor); ctx = MAH_handle_to_context (auditor);
dh->job = GNUNET_CURL_job_add (ctx, dh->job = GNUNET_CURL_job_add (ctx,
eh, eh,
@ -383,7 +384,7 @@ TALER_AUDITOR_deposit_confirmation_cancel (struct TALER_AUDITOR_DepositConfirmat
deposit_confirmation->job = NULL; deposit_confirmation->job = NULL;
} }
GNUNET_free (deposit_confirmation->url); GNUNET_free (deposit_confirmation->url);
GNUNET_free (deposit_confirmation->json_enc); TEAH_curl_easy_post_finished (&deposit_confirmation->ctx);
GNUNET_free (deposit_confirmation); GNUNET_free (deposit_confirmation);
} }

View File

@ -15,7 +15,7 @@
<http://www.gnu.org/licenses/> <http://www.gnu.org/licenses/>
*/ */
/** /**
* @file auditor-lib/auditor_api_handle.c * @file lib/auditor_api_handle.c
* @brief Implementation of the "handle" component of the auditor's HTTP API * @brief Implementation of the "handle" component of the auditor's HTTP API
* @author Sree Harsha Totakura <sreeharsha@totakura.in> * @author Sree Harsha Totakura <sreeharsha@totakura.in>
* @author Christian Grothoff * @author Christian Grothoff
@ -462,6 +462,16 @@ TALER_AUDITOR_connect (struct GNUNET_CURL_Context *ctx,
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Connecting to auditor at URL `%s'.\n", "Connecting to auditor at URL `%s'.\n",
url); url);
/* Disable 100 continue processing */
GNUNET_break (GNUNET_OK ==
GNUNET_CURL_append_header (ctx,
"Expect:"));
#if COMPRESS_BODIES
/* Tell auditor we compress bodies */
GNUNET_break (GNUNET_OK ==
GNUNET_CURL_append_header (ctx,
"Content-encoding: deflate"));
#endif
auditor = GNUNET_new (struct TALER_AUDITOR_Handle); auditor = GNUNET_new (struct TALER_AUDITOR_Handle);
auditor->ctx = ctx; auditor->ctx = ctx;
auditor->url = GNUNET_strdup (url); auditor->url = GNUNET_strdup (url);

View File

@ -22,7 +22,7 @@
#include "platform.h" #include "platform.h"
#include <gnunet/gnunet_curl_lib.h> #include <gnunet/gnunet_curl_lib.h>
#include "taler_auditor_service.h" #include "taler_auditor_service.h"
#include "teah_common.h"
/** /**
* Get the context of a auditor. * Get the context of a auditor.

View File

@ -60,9 +60,10 @@ struct TALER_EXCHANGE_DepositHandle
char *url; char *url;
/** /**
* JSON encoding of the request to POST. * Context for #TEH_curl_easy_post(). Keeps the data that must
* persist for Curl to make the upload.
*/ */
char *json_enc; struct TEAH_PostContext ctx;
/** /**
* Handle for the request. * Handle for the request.
@ -581,21 +582,22 @@ TALER_EXCHANGE_deposit (struct TALER_EXCHANGE_Handle *exchange,
dh->coin_value = dki->value; dh->coin_value = dki->value;
eh = TEL_curl_easy_get (dh->url); eh = TEL_curl_easy_get (dh->url);
GNUNET_assert (NULL != (dh->json_enc = if (GNUNET_OK !=
json_dumps (deposit_obj, TEAH_curl_easy_post (&dh->ctx,
JSON_COMPACT))); eh,
deposit_obj))
{
GNUNET_break (0);
curl_easy_cleanup (eh);
json_decref (deposit_obj);
GNUNET_free (dh->url);
GNUNET_free (dh);
return NULL;
}
json_decref (deposit_obj); json_decref (deposit_obj);
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_POSTFIELDS,
dh->json_enc));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE,
strlen (dh->json_enc)));
ctx = TEAH_handle_to_context (exchange); ctx = TEAH_handle_to_context (exchange);
dh->job = GNUNET_CURL_job_add (ctx, dh->job = GNUNET_CURL_job_add (ctx,
eh, eh,
@ -621,7 +623,7 @@ TALER_EXCHANGE_deposit_cancel (struct TALER_EXCHANGE_DepositHandle *deposit)
deposit->job = NULL; deposit->job = NULL;
} }
GNUNET_free (deposit->url); GNUNET_free (deposit->url);
GNUNET_free (deposit->json_enc); TEAH_curl_easy_post_finished (&deposit->ctx);
GNUNET_free (deposit); GNUNET_free (deposit);
} }

View File

@ -33,6 +33,7 @@
#include "exchange_api_handle.h" #include "exchange_api_handle.h"
#include "exchange_api_curl_defaults.h" #include "exchange_api_curl_defaults.h"
#include "backoff.h" #include "backoff.h"
#include "teah_common.h"
/** /**
* Which revision of the Taler protocol is implemented * Which revision of the Taler protocol is implemented
@ -1783,6 +1784,12 @@ TALER_EXCHANGE_connect
GNUNET_break (GNUNET_OK == GNUNET_break (GNUNET_OK ==
GNUNET_CURL_append_header (ctx, GNUNET_CURL_append_header (ctx,
"Expect:")); "Expect:"));
#if COMPRESS_BODIES
/* Tell exchange we compress bodies */
GNUNET_break (GNUNET_OK ==
GNUNET_CURL_append_header (ctx,
"Content-encoding: deflate"));
#endif
exchange = GNUNET_new (struct TALER_EXCHANGE_Handle); exchange = GNUNET_new (struct TALER_EXCHANGE_Handle);
exchange->ctx = ctx; exchange->ctx = ctx;
exchange->url = GNUNET_strdup (url); exchange->url = GNUNET_strdup (url);
@ -1816,6 +1823,7 @@ TALER_EXCHANGE_connect
} }
/** /**
* Initiate download of /keys from the exchange. * Initiate download of /keys from the exchange.
* *

View File

@ -24,7 +24,7 @@
#include "taler_auditor_service.h" #include "taler_auditor_service.h"
#include "taler_exchange_service.h" #include "taler_exchange_service.h"
#include "taler_crypto_lib.h" #include "taler_crypto_lib.h"
#include "teah_common.h"
/** /**
* Entry in DLL of auditors used by an exchange. * Entry in DLL of auditors used by an exchange.

View File

@ -49,9 +49,10 @@ struct TALER_EXCHANGE_PaybackHandle
char *url; char *url;
/** /**
* JSON encoding of the request to POST. * Context for #TEH_curl_easy_post(). Keeps the data that must
* persist for Curl to make the upload.
*/ */
char *json_enc; struct TEAH_PostContext ctx;
/** /**
* Denomination key of the coin. * Denomination key of the coin.
@ -321,29 +322,23 @@ TALER_EXCHANGE_payback (struct TALER_EXCHANGE_Handle *exchange,
ph->cb = payback_cb; ph->cb = payback_cb;
ph->cb_cls = payback_cb_cls; ph->cb_cls = payback_cb_cls;
ph->url = TEAH_path_to_url (exchange, "/payback"); ph->url = TEAH_path_to_url (exchange, "/payback");
eh = TEL_curl_easy_get (ph->url);
ph->json_enc = json_dumps (payback_obj, if (GNUNET_OK !=
JSON_COMPACT); TEAH_curl_easy_post (&ph->ctx,
json_decref (payback_obj); eh,
if (NULL == ph->json_enc) payback_obj))
{ {
GNUNET_break (0); GNUNET_break (0);
curl_easy_cleanup (eh);
json_decref (payback_obj);
GNUNET_free (ph->url); GNUNET_free (ph->url);
GNUNET_free (ph); GNUNET_free (ph);
return NULL; return NULL;
} }
eh = TEL_curl_easy_get (ph->url); json_decref (payback_obj);
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_POSTFIELDS,
ph->json_enc));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE,
strlen (ph->json_enc)));
ctx = TEAH_handle_to_context (exchange); ctx = TEAH_handle_to_context (exchange);
ph->job = GNUNET_CURL_job_add (ctx, ph->job = GNUNET_CURL_job_add (ctx,
eh, eh,
@ -369,7 +364,7 @@ TALER_EXCHANGE_payback_cancel (struct TALER_EXCHANGE_PaybackHandle *ph)
ph->job = NULL; ph->job = NULL;
} }
GNUNET_free (ph->url); GNUNET_free (ph->url);
GNUNET_free (ph->json_enc); TEAH_curl_easy_post_finished (&ph->ctx);
GNUNET_free (ph); GNUNET_free (ph);
} }

View File

@ -834,9 +834,10 @@ struct TALER_EXCHANGE_RefreshMeltHandle
char *url; char *url;
/** /**
* JSON encoding of the request to POST. * Context for #TEH_curl_easy_post(). Keeps the data that must
* persist for Curl to make the upload.
*/ */
char *json_enc; struct TEAH_PostContext ctx;
/** /**
* Handle for the request. * Handle for the request.
@ -1206,18 +1207,19 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange,
rmh->url = TEAH_path_to_url (exchange, rmh->url = TEAH_path_to_url (exchange,
"/refresh/melt"); "/refresh/melt");
eh = TEL_curl_easy_get (rmh->url); eh = TEL_curl_easy_get (rmh->url);
GNUNET_assert (NULL != (rmh->json_enc = if (GNUNET_OK !=
json_dumps (melt_obj, TEAH_curl_easy_post (&rmh->ctx,
JSON_COMPACT))); eh,
melt_obj))
{
GNUNET_break (0);
curl_easy_cleanup (eh);
json_decref (melt_obj);
GNUNET_free (rmh->url);
GNUNET_free (rmh);
return NULL;
}
json_decref (melt_obj); json_decref (melt_obj);
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDS,
rmh->json_enc));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE,
strlen (rmh->json_enc)));
ctx = TEAH_handle_to_context (exchange); ctx = TEAH_handle_to_context (exchange);
rmh->job = GNUNET_CURL_job_add (ctx, rmh->job = GNUNET_CURL_job_add (ctx,
eh, eh,
@ -1245,7 +1247,7 @@ TALER_EXCHANGE_refresh_melt_cancel (struct TALER_EXCHANGE_RefreshMeltHandle *rmh
free_melt_data (rmh->md); /* does not free 'md' itself */ free_melt_data (rmh->md); /* does not free 'md' itself */
GNUNET_free (rmh->md); GNUNET_free (rmh->md);
GNUNET_free (rmh->url); GNUNET_free (rmh->url);
GNUNET_free (rmh->json_enc); TEAH_curl_easy_post_finished (&rmh->ctx);
GNUNET_free (rmh); GNUNET_free (rmh);
} }
@ -1270,9 +1272,10 @@ struct TALER_EXCHANGE_RefreshRevealHandle
char *url; char *url;
/** /**
* JSON encoding of the request to POST. * Context for #TEH_curl_easy_post(). Keeps the data that must
* persist for Curl to make the upload.
*/ */
char *json_enc; struct TEAH_PostContext ctx;
/** /**
* Handle for the request. * Handle for the request.
@ -1634,18 +1637,19 @@ TALER_EXCHANGE_refresh_reveal (struct TALER_EXCHANGE_Handle *exchange,
"/refresh/reveal"); "/refresh/reveal");
eh = TEL_curl_easy_get (rrh->url); eh = TEL_curl_easy_get (rrh->url);
GNUNET_assert (NULL != (rrh->json_enc = if (GNUNET_OK !=
json_dumps (reveal_obj, TEAH_curl_easy_post (&rrh->ctx,
JSON_COMPACT))); eh,
reveal_obj))
{
GNUNET_break (0);
curl_easy_cleanup (eh);
json_decref (reveal_obj);
GNUNET_free (rrh->url);
GNUNET_free (rrh);
return NULL;
}
json_decref (reveal_obj); json_decref (reveal_obj);
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)));
ctx = TEAH_handle_to_context (rrh->exchange); ctx = TEAH_handle_to_context (rrh->exchange);
rrh->job = GNUNET_CURL_job_add (ctx, rrh->job = GNUNET_CURL_job_add (ctx,
eh, eh,
@ -1671,7 +1675,7 @@ TALER_EXCHANGE_refresh_reveal_cancel (struct TALER_EXCHANGE_RefreshRevealHandle
rrh->job = NULL; rrh->job = NULL;
} }
GNUNET_free (rrh->url); GNUNET_free (rrh->url);
GNUNET_free (rrh->json_enc); TEAH_curl_easy_post_finished (&rrh->ctx);
free_melt_data (rrh->md); /* does not free 'md' itself */ free_melt_data (rrh->md); /* does not free 'md' itself */
GNUNET_free (rrh->md); GNUNET_free (rrh->md);
GNUNET_free (rrh); GNUNET_free (rrh);

View File

@ -49,9 +49,10 @@ struct TALER_EXCHANGE_RefundHandle
char *url; char *url;
/** /**
* JSON encoding of the request to POST. * Context for #TEH_curl_easy_post(). Keeps the data that must
* persist for Curl to make the upload.
*/ */
char *json_enc; struct TEAH_PostContext ctx;
/** /**
* Handle for the request. * Handle for the request.
@ -368,21 +369,22 @@ refund_obj = json_pack ("{s:o, s:o," /* amount/fee */
refund_fee); refund_fee);
eh = TEL_curl_easy_get (rh->url); eh = TEL_curl_easy_get (rh->url);
GNUNET_assert (NULL != (rh->json_enc = if (GNUNET_OK !=
json_dumps (refund_obj, TEAH_curl_easy_post (&rh->ctx,
JSON_COMPACT))); eh,
refund_obj))
{
GNUNET_break (0);
curl_easy_cleanup (eh);
json_decref (refund_obj);
GNUNET_free (rh->url);
GNUNET_free (rh);
return NULL;
}
json_decref (refund_obj); json_decref (refund_obj);
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_POSTFIELDS,
rh->json_enc));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE,
strlen (rh->json_enc)));
ctx = TEAH_handle_to_context (exchange); ctx = TEAH_handle_to_context (exchange);
rh->job = GNUNET_CURL_job_add (ctx, rh->job = GNUNET_CURL_job_add (ctx,
eh, eh,
@ -408,7 +410,7 @@ TALER_EXCHANGE_refund_cancel (struct TALER_EXCHANGE_RefundHandle *refund)
refund->job = NULL; refund->job = NULL;
} }
GNUNET_free (refund->url); GNUNET_free (refund->url);
GNUNET_free (refund->json_enc); TEAH_curl_easy_post_finished (&refund->ctx);
GNUNET_free (refund); GNUNET_free (refund);
} }

View File

@ -677,9 +677,10 @@ struct TALER_EXCHANGE_ReserveWithdrawHandle
char *url; char *url;
/** /**
* JSON encoding of the request to POST. * Context for #TEH_curl_easy_post(). Keeps the data that must
* persist for Curl to make the upload.
*/ */
char *json_enc; struct TEAH_PostContext ctx;
/** /**
* Handle for the request. * Handle for the request.
@ -1022,25 +1023,26 @@ reserve_withdraw_internal (struct TALER_EXCHANGE_Handle *exchange,
if (NULL == withdraw_obj) if (NULL == withdraw_obj)
{ {
GNUNET_break (0); GNUNET_break (0);
GNUNET_free (wsh);
return NULL; return NULL;
} }
wsh->ps = *ps; wsh->ps = *ps;
wsh->url = TEAH_path_to_url (exchange, "/reserve/withdraw"); wsh->url = TEAH_path_to_url (exchange, "/reserve/withdraw");
eh = TEL_curl_easy_get (wsh->url); eh = TEL_curl_easy_get (wsh->url);
GNUNET_assert (NULL != (wsh->json_enc = if (GNUNET_OK !=
json_dumps (withdraw_obj, TEAH_curl_easy_post (&wsh->ctx,
JSON_COMPACT))); eh,
withdraw_obj))
{
GNUNET_break (0);
curl_easy_cleanup (eh);
json_decref (withdraw_obj);
GNUNET_free (wsh->url);
GNUNET_free (wsh);
return NULL;
}
json_decref (withdraw_obj); json_decref (withdraw_obj);
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDS,
wsh->json_enc));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE,
strlen (wsh->json_enc)));
ctx = TEAH_handle_to_context (exchange); ctx = TEAH_handle_to_context (exchange);
wsh->job = GNUNET_CURL_job_add (ctx, wsh->job = GNUNET_CURL_job_add (ctx,
eh, eh,
@ -1199,7 +1201,7 @@ TALER_EXCHANGE_reserve_withdraw_cancel (struct TALER_EXCHANGE_ReserveWithdrawHan
sign->job = NULL; sign->job = NULL;
} }
GNUNET_free (sign->url); GNUNET_free (sign->url);
GNUNET_free (sign->json_enc); TEAH_curl_easy_post_finished (&sign->ctx);
GNUNET_free (sign); GNUNET_free (sign);
} }

View File

@ -49,9 +49,10 @@ struct TALER_EXCHANGE_TrackTransactionHandle
char *url; char *url;
/** /**
* JSON encoding of the request to POST. * Context for #TEH_curl_easy_post(). Keeps the data that must
* persist for Curl to make the upload.
*/ */
char *json_enc; struct TEAH_PostContext ctx;
/** /**
* Handle for the request. * Handle for the request.
@ -322,18 +323,19 @@ TALER_EXCHANGE_track_transaction (struct TALER_EXCHANGE_Handle *exchange,
dwh->depconf.coin_pub = *coin_pub; dwh->depconf.coin_pub = *coin_pub;
eh = TEL_curl_easy_get (dwh->url); eh = TEL_curl_easy_get (dwh->url);
GNUNET_assert (NULL != (dwh->json_enc = if (GNUNET_OK !=
json_dumps (deposit_wtid_obj, TEAH_curl_easy_post (&dwh->ctx,
JSON_COMPACT))); eh,
deposit_wtid_obj))
{
GNUNET_break (0);
curl_easy_cleanup (eh);
json_decref (deposit_wtid_obj);
GNUNET_free (dwh->url);
GNUNET_free (dwh);
return NULL;
}
json_decref (deposit_wtid_obj); json_decref (deposit_wtid_obj);
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDS,
dwh->json_enc));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE,
strlen (dwh->json_enc)));
ctx = TEAH_handle_to_context (exchange); ctx = TEAH_handle_to_context (exchange);
dwh->job = GNUNET_CURL_job_add (ctx, dwh->job = GNUNET_CURL_job_add (ctx,
eh, eh,
@ -359,9 +361,9 @@ TALER_EXCHANGE_track_transaction_cancel (struct TALER_EXCHANGE_TrackTransactionH
dwh->job = NULL; dwh->job = NULL;
} }
GNUNET_free (dwh->url); GNUNET_free (dwh->url);
GNUNET_free (dwh->json_enc); TEAH_curl_easy_post_finished (&dwh->ctx);
GNUNET_free (dwh); GNUNET_free (dwh);
} }
/* end of exchange_api_deposit_wtid.c */ /* end of exchange_api_track_transaction.c */

105
src/lib/teah_common.c Normal file
View File

@ -0,0 +1,105 @@
/*
This file is part of TALER
Copyright (C) 2019 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 lib/teah_common.c
* @brief Helper routines shared by libtalerexchange and libtalerauditor
* @author Christian Grothoff
*/
#include "platform.h"
#include "teah_common.h"
#if COMPRESS_BODIES
#include <zlib.h>
#endif
/**
* Add the @a body as POST data to the easy handle in
* @a ctx.
*
* @param ctx[in,out] a request context (updated)
* @param eh easy handle to use
* @param body JSON body to add to @e ctx
* @return #GNUNET_OK on success #GNUNET_SYSERR on failure
*/
int
TEAH_curl_easy_post (struct TEAH_PostContext *ctx,
CURL *eh,
const json_t *body)
{
char *str;
size_t slen;
str = json_dumps (body,
JSON_COMPACT);
if (NULL == str)
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
slen = strlen (str);
#if COMPRESS_BODIES
{
Bytef *cbuf;
uLongf cbuf_size;
int ret;
cbuf_size = compressBound (slen);
cbuf = GNUNET_malloc (cbuf_size);
ret = compress (cbuf,
&cbuf_size,
(const Bytef *) str,
slen);
if (Z_OK != ret)
{
/* compression failed!? */
GNUNET_break (0);
GNUNET_free (cbuf);
return GNUNET_SYSERR;
}
free (str);
slen = (size_t) cbuf_size;
ctx->json_enc = (char *) cbuf;
}
#else
ctx->json_enc = str;
#endif
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDS,
ctx->json_enc));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE,
slen));
return GNUNET_OK;
}
/**
* Free the data in @a ctx.
*
* @param ctx[in] a request context (updated)
*/
void
TEAH_curl_easy_post_finished (struct TEAH_PostContext *ctx)
{
GNUNET_free_non_null (ctx->json_enc);
}

74
src/lib/teah_common.h Normal file
View File

@ -0,0 +1,74 @@
/*
This file is part of TALER
Copyright (C) 2019 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 lib/teah_common.h
* @brief Helper routines shared by libtalerexchange and libtalerauditor
* @author Christian Grothoff
*/
#ifndef TEAH_COMMON_H
#define TEAH_COMMON_H
#include <gnunet/gnunet_curl_lib.h>
#include "taler_json_lib.h"
/**
* Should we compress PUT/POST bodies with 'deflate' encoding?
*/
#define COMPRESS_BODIES 0
/**
* State used for #TEAL_curl_easy_post() and
* #TEAL_curl_easy_post_finished().
*/
struct TEAH_PostContext
{
/**
* JSON encoding of the request to POST.
*/
char *json_enc;
};
/**
* Add the @a body as POST data to the easy handle in
* @a ctx.
*
* @param ctx[in,out] a request context (updated)
* @param eh easy handle to use
* @param body JSON body to add to @e ctx
* @return #GNUNET_OK on success #GNUNET_SYSERR on failure
*/
int
TEAH_curl_easy_post (struct TEAH_PostContext *ctx,
CURL *eh,
const json_t *body);
/**
* Free the data in @a ctx.
*
* @param ctx[in] a request context (updated)
*/
void
TEAH_curl_easy_post_finished (struct TEAH_PostContext *ctx);
#endif