aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/exchange-lib/Makefile.am3
-rw-r--r--src/exchange-lib/exchange_api_admin.c44
-rw-r--r--src/exchange-lib/exchange_api_common.c2
-rw-r--r--src/exchange-lib/exchange_api_context.c537
-rw-r--r--src/exchange-lib/exchange_api_context.h169
-rw-r--r--src/exchange-lib/exchange_api_deposit.c46
-rw-r--r--src/exchange-lib/exchange_api_deposit_wtid.c52
-rw-r--r--src/exchange-lib/exchange_api_handle.c63
-rw-r--r--src/exchange-lib/exchange_api_handle.h2
-rw-r--r--src/exchange-lib/exchange_api_refresh.c76
-rw-r--r--src/exchange-lib/exchange_api_refresh_link.c40
-rw-r--r--src/exchange-lib/exchange_api_reserve.c94
-rw-r--r--src/exchange-lib/exchange_api_wire.c50
-rw-r--r--src/exchange-lib/exchange_api_wire_deposits.c37
-rw-r--r--src/exchange-lib/test_exchange_api.c40
-rw-r--r--src/include/taler_exchange_service.h27
16 files changed, 189 insertions, 1093 deletions
diff --git a/src/exchange-lib/Makefile.am b/src/exchange-lib/Makefile.am
index d953a7a86..ea53623fb 100644
--- a/src/exchange-lib/Makefile.am
+++ b/src/exchange-lib/Makefile.am
@@ -15,7 +15,6 @@ libtalerexchange_la_LDFLAGS = \
libtalerexchange_la_SOURCES = \
exchange_api_common.c exchange_api_common.h \
- exchange_api_context.c exchange_api_context.h \
exchange_api_handle.c exchange_api_handle.h \
exchange_api_admin.c \
exchange_api_deposit.c \
@@ -29,6 +28,7 @@ libtalerexchange_la_SOURCES = \
libtalerexchange_la_LIBADD = \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
+ -lgnunetcurl \
-lgnunetjson \
-lgnunetutil \
-ljansson \
@@ -57,6 +57,7 @@ test_exchange_api_LDADD = \
$(LIBGCRYPT_LIBS) \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
+ -lgnunetcurl \
-lgnunetutil \
-ljansson
diff --git a/src/exchange-lib/exchange_api_admin.c b/src/exchange-lib/exchange_api_admin.c
index 871a88a6b..06a39ffa4 100644
--- a/src/exchange-lib/exchange_api_admin.c
+++ b/src/exchange-lib/exchange_api_admin.c
@@ -25,9 +25,9 @@
#include <microhttpd.h> /* just for HTTP status codes */
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
#include "taler_json_lib.h"
#include "taler_exchange_service.h"
-#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
@@ -56,7 +56,7 @@ struct TALER_EXCHANGE_AdminAddIncomingHandle
/**
* Handle for the request.
*/
- struct MAC_Job *job;
+ struct GNUNET_CURL_Job *job;
/**
* HTTP headers for the request.
@@ -73,11 +73,6 @@ struct TALER_EXCHANGE_AdminAddIncomingHandle
*/
void *cb_cls;
- /**
- * Download buffer
- */
- struct MAC_DownloadBuffer db;
-
};
@@ -86,20 +81,17 @@ struct TALER_EXCHANGE_AdminAddIncomingHandle
* HTTP /admin/add/incoming request.
*
* @param cls the `struct TALER_EXCHANGE_AdminAddIncomingHandle`
- * @param eh the curl request handle
+ * @param response_code HTTP response code, 0 on error
+ * @param json parsed JSON result, NULL on error
*/
static void
handle_admin_add_incoming_finished (void *cls,
- CURL *eh)
+ long response_code,
+ const json_t *json)
{
struct TALER_EXCHANGE_AdminAddIncomingHandle *aai = cls;
- long response_code;
- json_t *json;
aai->job = NULL;
- json = MAC_download_get_result (&aai->db,
- eh,
- &response_code);
switch (response_code)
{
case 0:
@@ -138,7 +130,6 @@ handle_admin_add_incoming_finished (void *cls,
aai->cb (aai->cb_cls,
response_code,
json);
- json_decref (json);
TALER_EXCHANGE_admin_add_incoming_cancel (aai);
}
@@ -170,7 +161,7 @@ TALER_EXCHANGE_admin_add_incoming (struct TALER_EXCHANGE_Handle *exchange,
void *res_cb_cls)
{
struct TALER_EXCHANGE_AdminAddIncomingHandle *aai;
- struct TALER_EXCHANGE_Context *ctx;
+ struct GNUNET_CURL_Context *ctx;
json_t *admin_obj;
CURL *eh;
@@ -212,20 +203,12 @@ TALER_EXCHANGE_admin_add_incoming (struct TALER_EXCHANGE_Handle *exchange,
curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE,
strlen (aai->json_enc)));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEFUNCTION,
- &MAC_download_cb));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEDATA,
- &aai->db));
ctx = MAH_handle_to_context (exchange);
- aai->job = MAC_job_add (ctx,
- eh,
- GNUNET_YES,
- &handle_admin_add_incoming_finished,
- aai);
+ aai->job = GNUNET_CURL_job_add (ctx,
+ eh,
+ GNUNET_YES,
+ &handle_admin_add_incoming_finished,
+ aai);
return aai;
}
@@ -241,11 +224,10 @@ TALER_EXCHANGE_admin_add_incoming_cancel (struct TALER_EXCHANGE_AdminAddIncoming
{
if (NULL != aai->job)
{
- MAC_job_cancel (aai->job);
+ GNUNET_CURL_job_cancel (aai->job);
aai->job = NULL;
}
curl_slist_free_all (aai->headers);
- GNUNET_free_non_null (aai->db.buf);
GNUNET_free (aai->url);
GNUNET_free (aai->json_enc);
GNUNET_free (aai);
diff --git a/src/exchange-lib/exchange_api_common.c b/src/exchange-lib/exchange_api_common.c
index aacbb4a2a..c46b69a40 100644
--- a/src/exchange-lib/exchange_api_common.c
+++ b/src/exchange-lib/exchange_api_common.c
@@ -22,7 +22,7 @@
#include "platform.h"
#include "exchange_api_common.h"
#include "taler_json_lib.h"
-#include "exchange_api_context.h"
+#include <gnunet/gnunet_curl_lib.h>
#include "exchange_api_handle.h"
#include "taler_signatures.h"
diff --git a/src/exchange-lib/exchange_api_context.c b/src/exchange-lib/exchange_api_context.c
deleted file mode 100644
index 5049bb0a1..000000000
--- a/src/exchange-lib/exchange_api_context.c
+++ /dev/null
@@ -1,537 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014, 2015 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, If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file exchange-lib/exchange_api_context.c
- * @brief Implementation of the context part of the exchange's HTTP API
- * @author Sree Harsha Totakura <sreeharsha@totakura.in>
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <curl/curl.h>
-#include "taler_exchange_service.h"
-#include "exchange_api_context.h"
-
-
-/**
- * Log error related to CURL operations.
- *
- * @param type log level
- * @param function which function failed to run
- * @param code what was the curl error code
- */
-#define CURL_STRERROR(type, function, code) \
- GNUNET_log (type, \
- "Curl function `%s' has failed at `%s:%d' with error: %s\n", \
- function, __FILE__, __LINE__, curl_easy_strerror (code));
-
-/**
- * Print JSON parsing related error information
- */
-#define JSON_WARN(error) \
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
- "JSON parsing failed at %s:%u: %s (%s)\n", \
- __FILE__, __LINE__, error.text, error.source)
-
-
-/**
- * Failsafe flag. Raised if our constructor fails to initialize
- * the Curl library.
- */
-static int TALER_EXCHANGE_curl_fail;
-
-
-/**
- * Jobs are CURL requests running within a `struct TALER_EXCHANGE_Context`.
- */
-struct MAC_Job
-{
-
- /**
- * We keep jobs in a DLL.
- */
- struct MAC_Job *next;
-
- /**
- * We keep jobs in a DLL.
- */
- struct MAC_Job *prev;
-
- /**
- * Easy handle of the job.
- */
- CURL *easy_handle;
-
- /**
- * Context this job runs in.
- */
- struct TALER_EXCHANGE_Context *ctx;
-
- /**
- * Function to call upon completion.
- */
- MAC_JobCompletionCallback jcc;
-
- /**
- * Closure for @e jcc.
- */
- void *jcc_cls;
-
-};
-
-
-/**
- * Context
- */
-struct TALER_EXCHANGE_Context
-{
- /**
- * Curl multi handle
- */
- CURLM *multi;
-
- /**
- * Curl share handle
- */
- CURLSH *share;
-
- /**
- * We keep jobs in a DLL.
- */
- struct MAC_Job *jobs_head;
-
- /**
- * We keep jobs in a DLL.
- */
- struct MAC_Job *jobs_tail;
-
- /**
- * HTTP header "application/json", created once and used
- * for all requests that need it.
- */
- struct curl_slist *json_header;
-
-};
-
-
-/**
- * Initialise this library. This function should be called before using any of
- * the following functions.
- *
- * @return library context
- */
-struct TALER_EXCHANGE_Context *
-TALER_EXCHANGE_init ()
-{
- struct TALER_EXCHANGE_Context *ctx;
- CURLM *multi;
- CURLSH *share;
-
- if (TALER_EXCHANGE_curl_fail)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Curl was not initialised properly\n");
- return NULL;
- }
- if (NULL == (multi = curl_multi_init ()))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to create a Curl multi handle\n");
- return NULL;
- }
- if (NULL == (share = curl_share_init ()))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to create a Curl share handle\n");
- return NULL;
- }
- ctx = GNUNET_new (struct TALER_EXCHANGE_Context);
- ctx->multi = multi;
- ctx->share = share;
- GNUNET_assert (NULL != (ctx->json_header =
- curl_slist_append (NULL,
- "Content-Type: application/json")));
- return ctx;
-}
-
-
-/**
- * Schedule a CURL request to be executed and call the given @a jcc
- * upon its completion. Note that the context will make use of the
- * CURLOPT_PRIVATE facility of the CURL @a eh. Applications can
- * instead use #MAC_easy_to_closure to extract the @a jcc_cls argument
- * from a valid @a eh afterwards.
- *
- * This function modifies the CURL handle to add the
- * "Content-Type: application/json" header if @a add_json is set.
- *
- * @param ctx context to execute the job in
- * @param eh curl easy handle for the request, will
- * be executed AND cleaned up
- * @param add_json add "application/json" content type header
- * @param jcc callback to invoke upon completion
- * @param jcc_cls closure for @a jcc
- */
-struct MAC_Job *
-MAC_job_add (struct TALER_EXCHANGE_Context *ctx,
- CURL *eh,
- int add_json,
- MAC_JobCompletionCallback jcc,
- void *jcc_cls)
-{
- struct MAC_Job *job;
-
- if (GNUNET_YES == add_json)
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_HTTPHEADER,
- ctx->json_header));
-
- job = GNUNET_new (struct MAC_Job);
- job->easy_handle = eh;
- job->ctx = ctx;
- job->jcc = jcc;
- job->jcc_cls = jcc_cls;
- GNUNET_CONTAINER_DLL_insert (ctx->jobs_head,
- ctx->jobs_tail,
- job);
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_PRIVATE,
- job));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_SHARE,
- ctx->share));
- GNUNET_assert (CURLM_OK ==
- curl_multi_add_handle (ctx->multi,
- eh));
- return job;
-}
-
-
-/**
- * Obtain the `jcc_cls` argument from an `eh` that was
- * given to #MAC_job_add().
- *
- * @param eh easy handle that was used
- * @return the `jcc_cls` that was given to #MAC_job_add().
- */
-void *
-MAC_easy_to_closure (CURL *eh)
-{
- struct MAC_Job *job;
-
- GNUNET_assert (CURLE_OK ==
- curl_easy_getinfo (eh,
- CURLINFO_PRIVATE,
- (char **) &job));
- return job->jcc_cls;
-}
-
-
-/**
- * Cancel a job. Must only be called before the job completion
- * callback is called for the respective job.
- *
- * @param job job to cancel
- */
-void
-MAC_job_cancel (struct MAC_Job *job)
-{
- struct TALER_EXCHANGE_Context *ctx = job->ctx;
-
- GNUNET_CONTAINER_DLL_remove (ctx->jobs_head,
- ctx->jobs_tail,
- job);
- GNUNET_assert (CURLM_OK ==
- curl_multi_remove_handle (ctx->multi,
- job->easy_handle));
- curl_easy_cleanup (job->easy_handle);
- GNUNET_free (job);
-}
-
-
-/**
- * Run the main event loop for the Taler interaction.
- *
- * @param ctx the library context
- */
-void
-TALER_EXCHANGE_perform (struct TALER_EXCHANGE_Context *ctx)
-{
- CURLMsg *cmsg;
- struct MAC_Job *job;
- int n_running;
- int n_completed;
-
- (void) curl_multi_perform (ctx->multi,
- &n_running);
- while (NULL != (cmsg = curl_multi_info_read (ctx->multi,
- &n_completed)))
- {
- /* Only documented return value is CURLMSG_DONE */
- GNUNET_break (CURLMSG_DONE == cmsg->msg);
- GNUNET_assert (CURLE_OK ==
- curl_easy_getinfo (cmsg->easy_handle,
- CURLINFO_PRIVATE,
- (char **) &job));
- GNUNET_assert (job->ctx == ctx);
- job->jcc (job->jcc_cls,
- cmsg->easy_handle);
- MAC_job_cancel (job);
- }
-}
-
-
-/**
- * Obtain the information for a select() call to wait until
- * #TALER_EXCHANGE_perform() is ready again. Note that calling
- * any other TALER_EXCHANGE-API may also imply that the library
- * is again ready for #TALER_EXCHANGE_perform().
- *
- * Basically, a client should use this API to prepare for select(),
- * then block on select(), then call #TALER_EXCHANGE_perform() and then
- * start again until the work with the context is done.
- *
- * This function will NOT zero out the sets and assumes that @a max_fd
- * and @a timeout are already set to minimal applicable values. It is
- * safe to give this API FD-sets and @a max_fd and @a timeout that are
- * already initialized to some other descriptors that need to go into
- * the select() call.
- *
- * @param ctx context to get the event loop information for
- * @param read_fd_set will be set for any pending read operations
- * @param write_fd_set will be set for any pending write operations
- * @param except_fd_set is here because curl_multi_fdset() has this argument
- * @param max_fd set to the highest FD included in any set;
- * if the existing sets have no FDs in it, the initial
- * value should be "-1". (Note that `max_fd + 1` will need
- * to be passed to select().)
- * @param timeout set to the timeout in milliseconds (!); -1 means
- * no timeout (NULL, blocking forever is OK), 0 means to
- * proceed immediately with #TALER_EXCHANGE_perform().
- */
-void
-TALER_EXCHANGE_get_select_info (struct TALER_EXCHANGE_Context *ctx,
- fd_set *read_fd_set,
- fd_set *write_fd_set,
- fd_set *except_fd_set,
- int *max_fd,
- long *timeout)
-{
- long to;
- int m;
-
- m = -1;
- GNUNET_assert (CURLM_OK ==
- curl_multi_fdset (ctx->multi,
- read_fd_set,
- write_fd_set,
- except_fd_set,
- &m));
- to = *timeout;
- *max_fd = GNUNET_MAX (m, *max_fd);
- GNUNET_assert (CURLM_OK ==
- curl_multi_timeout (ctx->multi,
- &to));
-
- /* Only if what we got back from curl is smaller than what we
- already had (-1 == infinity!), then update timeout */
- if ( (to < *timeout) &&
- (-1 != to) )
- *timeout = to;
- if ( (-1 == (*timeout)) &&
- (NULL != ctx->jobs_head) )
- *timeout = to;
-}
-
-
-/**
- * Cleanup library initialisation resources. This function should be called
- * after using this library to cleanup the resources occupied during library's
- * initialisation.
- *
- * @param ctx the library context
- */
-void
-TALER_EXCHANGE_fini (struct TALER_EXCHANGE_Context *ctx)
-{
- /* all jobs must have been cancelled at this time, assert this */
- GNUNET_assert (NULL == ctx->jobs_head);
- curl_share_cleanup (ctx->share);
- curl_multi_cleanup (ctx->multi);
- curl_slist_free_all (ctx->json_header);
- GNUNET_free (ctx);
-}
-
-
-/**
- * Callback used when downloading the reply to an HTTP request.
- * Just appends all of the data to the `buf` in the
- * `struct MAC_DownloadBuffer` for further processing. The size of
- * the download is limited to #GNUNET_MAX_MALLOC_CHECKED, if
- * the download exceeds this size, we abort with an error.
- *
- * @param bufptr data downloaded via HTTP
- * @param size size of an item in @a bufptr
- * @param nitems number of items in @a bufptr
- * @param cls the `struct MAC_DownloadBuffer`
- * @return number of bytes processed from @a bufptr
- */
-size_t
-MAC_download_cb (char *bufptr,
- size_t size,
- size_t nitems,
- void *cls)
-{
- struct MAC_DownloadBuffer *db = cls;
- size_t msize;
- void *buf;
-
- if (0 == size * nitems)
- {
- /* Nothing (left) to do */
- return 0;
- }
- msize = size * nitems;
- if ( (msize + db->buf_size) >= GNUNET_MAX_MALLOC_CHECKED)
- {
- db->eno = ENOMEM;
- return 0; /* signals an error to curl */
- }
- db->buf = GNUNET_realloc (db->buf,
- db->buf_size + msize);
- buf = db->buf + db->buf_size;
- memcpy (buf, bufptr, msize);
- db->buf_size += msize;
- return msize;
-}
-
-
-/**
- * Obtain information about the final result about the
- * HTTP download. If the download was successful, parses
- * the JSON in the @a db and returns it. Also returns
- * the HTTP @a response_code. If the download failed,
- * the return value is NULL. The response code is set
- * in any case, on download errors to zero.
- *
- * Calling this function also cleans up @a db.
- *
- * @param db download buffer
- * @param eh CURL handle (to get the response code)
- * @param[out] response_code set to the HTTP response code
- * (or zero if we aborted the download, i.e.
- * because the response was too big, or if
- * the JSON we received was malformed).
- * @return NULL if downloading a JSON reply failed
- */
-json_t *
-MAC_download_get_result (struct MAC_DownloadBuffer *db,
- CURL *eh,
- long *response_code)
-{
- json_t *json;
- json_error_t error;
- char *ct;
-
- if ( (CURLE_OK !=
- curl_easy_getinfo (eh,
- CURLINFO_CONTENT_TYPE,
- &ct)) ||
- (NULL == ct) ||
- (0 != strcasecmp (ct,
- "application/json")) )
- {
- /* No content type or explicitly not JSON, refuse to parse
- (but keep response code) */
- if (CURLE_OK !=
- curl_easy_getinfo (eh,
- CURLINFO_RESPONSE_CODE,
- response_code))
- {
- /* unexpected error... */
- GNUNET_break (0);
- *response_code = 0;
- }
- return NULL;
- }
-
- json = NULL;
- if (0 == db->eno)
- {
- json = json_loadb (db->buf,
- db->buf_size,
- JSON_REJECT_DUPLICATES | JSON_DISABLE_EOF_CHECK,
- &error);
- if (NULL == json)
- {
- JSON_WARN (error);
- *response_code = 0;
- }
- }
- GNUNET_free_non_null (db->buf);
- db->buf = NULL;
- db->buf_size = 0;
- if (NULL != json)
- {
- if (CURLE_OK !=
- curl_easy_getinfo (eh,
- CURLINFO_RESPONSE_CODE,
- response_code))
- {
- /* unexpected error... */
- GNUNET_break (0);
- *response_code = 0;
- }
- }
- return json;
-}
-
-
-/**
- * Initial global setup logic, specifically runs the Curl setup.
- */
-__attribute__ ((constructor))
-void
-TALER_EXCHANGE_constructor__ (void)
-{
- CURLcode ret;
-
- if (CURLE_OK != (ret = curl_global_init (CURL_GLOBAL_DEFAULT)))
- {
- CURL_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "curl_global_init",
- ret);
- TALER_EXCHANGE_curl_fail = 1;
- }
-}
-
-
-/**
- * Cleans up after us, specifically runs the Curl cleanup.
- */
-__attribute__ ((destructor))
-void
-TALER_EXCHANGE_destructor__ (void)
-{
- if (TALER_EXCHANGE_curl_fail)
- return;
- curl_global_cleanup ();
-}
-
-/* end of exchange_api_context.c */
diff --git a/src/exchange-lib/exchange_api_context.h b/src/exchange-lib/exchange_api_context.h
deleted file mode 100644
index ed954c696..000000000
--- a/src/exchange-lib/exchange_api_context.h
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014, 2015 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, If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file exchange-lib/exchange_api_context.h
- * @brief Internal interface to the context part of the exchange's HTTP API
- * @author Sree Harsha Totakura <sreeharsha@totakura.in>
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <curl/curl.h>
-#include <gnunet/gnunet_util_lib.h>
-#include "taler_exchange_service.h"
-#include "taler_signatures.h"
-
-
-/**
- * Entry in the context's job queue.
- */
-struct MAC_Job;
-
-/**
- * Function to call upon completion of a job.
- *
- * @param cls closure
- * @param eh original easy handle (for inspection)
- */
-typedef void
-(*MAC_JobCompletionCallback)(void *cls,
- CURL *eh);
-
-
-/**
- * Schedule a CURL request to be executed and call the given @a jcc
- * upon its completion. Note that the context will make use of the
- * CURLOPT_PRIVATE facility of the CURL @a eh. Applications can
- * instead use #MAC_easy_to_closure to extract the @a jcc_cls argument
- * from a valid @a eh afterwards.
- *
- * This function modifies the CURL handle to add the
- * "Content-Type: application/json" header if @a add_json is set.
- *
- * @param ctx context to execute the job in
- * @param eh curl easy handle for the request, will
- * be executed AND cleaned up
- * @param add_json add "application/json" content type header
- * @param jcc callback to invoke upon completion
- * @param jcc_cls closure for @a jcc
- */
-struct MAC_Job *
-MAC_job_add (struct TALER_EXCHANGE_Context *ctx,
- CURL *eh,
- int add_json,
- MAC_JobCompletionCallback jcc,
- void *jcc_cls);
-
-
-/**
- * Obtain the `jcc_cls` argument from an `eh` that was
- * given to #MAC_job_add().
- *
- * @param eh easy handle that was used
- * @return the `jcc_cls` that was given to #MAC_job_add().
- */
-void *
-MAC_easy_to_closure (CURL *eh);
-
-
-/**
- * Cancel a job. Must only be called before the job completion
- * callback is called for the respective job.
- *
- * @param job job to cancel
- */
-void
-MAC_job_cancel (struct MAC_Job *job);
-
-
-/**
- * @brief Buffer data structure we use to buffer the HTTP download
- * before giving it to the JSON parser.
- */
-struct MAC_DownloadBuffer
-{
-
- /**
- * Download buffer
- */
- void *buf;
-
- /**
- * The size of the download buffer
- */
- size_t buf_size;
-
- /**
- * Error code (based on libc errno) if we failed to download
- * (i.e. response too large).
- */
- int eno;
-
-};
-
-
-/**
- * Callback used when downloading the reply to an HTTP request.
- * Just appends all of the data to the `buf` in the
- * `struct MAC_DownloadBuffer` for further processing. The size of
- * the download is limited to #GNUNET_MAX_MALLOC_CHECKED, if
- * the download exceeds this size, we abort with an error.
- *
- * Should be used by the various routines as the
- * CURLOPT_WRITEFUNCTION. A `struct MAC_DownloadBuffer` needs to be
- * passed to the CURLOPT_WRITEDATA.
- *
- * Afterwards, `eno` needs to be checked to ensure that the download
- * completed correctly.
- *
- * @param bufptr data downloaded via HTTP
- * @param size size of an item in @a bufptr
- * @param nitems number of items in @a bufptr
- * @param cls the `struct MAC_DownloadBuffer`
- * @return number of bytes processed from @a bufptr
- */
-size_t
-MAC_download_cb (char *bufptr,
- size_t size,
- size_t nitems,
- void *cls);
-
-
-/**
- * Obtain information about the final result about the
- * HTTP download. If the download was successful, parses
- * the JSON in the @a db and returns it. Also returns
- * the HTTP @a response_code. If the download failed,
- * the return value is NULL. The response code is set
- * in any case, on download errors to zero.
- *
- * Calling this function also cleans up @a db.
- *
- * @param db download buffer
- * @param eh CURL handle (to get the response code)
- * @param[out] response_code set to the HTTP response code
- * (or zero if we aborted the download, i.e.
- * because the response was too big, or if
- * the JSON we received was malformed).
- * @return NULL if downloading a JSON reply failed
- */
-json_t *
-MAC_download_get_result (struct MAC_DownloadBuffer *db,
- CURL *eh,
- long *response_code);
-
-
-/* end of exchange_api_context.h */
diff --git a/src/exchange-lib/exchange_api_deposit.c b/src/exchange-lib/exchange_api_deposit.c
index 8ec45a23f..d5dbdcff1 100644
--- a/src/exchange-lib/exchange_api_deposit.c
+++ b/src/exchange-lib/exchange_api_deposit.c
@@ -26,10 +26,10 @@
#include <microhttpd.h> /* just for HTTP status codes */
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
#include "taler_json_lib.h"
#include "taler_exchange_service.h"
#include "exchange_api_common.h"
-#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
@@ -58,7 +58,7 @@ struct TALER_EXCHANGE_DepositHandle
/**
* Handle for the request.
*/
- struct MAC_Job *job;
+ struct GNUNET_CURL_Job *job;
/**
* Function to call with the result.
@@ -71,11 +71,6 @@ struct TALER_EXCHANGE_DepositHandle
void *cb_cls;
/**
- * Download buffer
- */
- struct MAC_DownloadBuffer db;
-
- /**
* Information the exchange should sign in response.
*/
struct TALER_DepositConfirmationPS depconf;
@@ -103,7 +98,7 @@ struct TALER_EXCHANGE_DepositHandle
*/
static int
verify_deposit_signature_ok (const struct TALER_EXCHANGE_DepositHandle *dh,
- json_t *json)
+ const json_t *json)
{
struct TALER_ExchangeSignatureP exchange_sig;
struct TALER_ExchangePublicKeyP exchange_pub;
@@ -153,7 +148,7 @@ verify_deposit_signature_ok (const struct TALER_EXCHANGE_DepositHandle *dh,
*/
static int
verify_deposit_signature_forbidden (const struct TALER_EXCHANGE_DepositHandle *dh,
- json_t *json)
+ const json_t *json)
{
json_t *history;
struct TALER_Amount total;
@@ -162,9 +157,9 @@ verify_deposit_signature_forbidden (const struct TALER_EXCHANGE_DepositHandle *d
"history");
if (GNUNET_OK !=
TALER_EXCHANGE_verify_coin_history_ (dh->coin_value.currency,
- &dh->depconf.coin_pub,
- history,
- &total))
+ &dh->depconf.coin_pub,
+ history,
+ &total))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -196,20 +191,17 @@ verify_deposit_signature_forbidden (const struct TALER_EXCHANGE_DepositHandle *d
* HTTP /deposit request.
*
* @param cls the `struct TALER_EXCHANGE_DepositHandle`
- * @param eh the curl request handle
+ * @param response_code HTTP response code, 0 on error
+ * @param json parsed JSON result, NULL on error
*/
static void
handle_deposit_finished (void *cls,
- CURL *eh)
+ long response_code,
+ const json_t *json)
{
struct TALER_EXCHANGE_DepositHandle *dh = cls;
- long response_code;
- json_t *json;
dh->job = NULL;
- json = MAC_download_get_result (&dh->db,
- eh,
- &response_code);
switch (response_code)
{
case 0:
@@ -262,7 +254,6 @@ handle_deposit_finished (void *cls,
dh->cb (dh->cb_cls,
response_code,
json);
- json_decref (json);
TALER_EXCHANGE_deposit_cancel (dh);
}
@@ -407,7 +398,7 @@ TALER_EXCHANGE_deposit (struct TALER_EXCHANGE_Handle *exchange,
const struct TALER_EXCHANGE_Keys *key_state;
const struct TALER_EXCHANGE_DenomPublicKey *dki;
struct TALER_EXCHANGE_DepositHandle *dh;
- struct TALER_EXCHANGE_Context *ctx;
+ struct GNUNET_CURL_Context *ctx;
json_t *deposit_obj;
CURL *eh;
struct GNUNET_HashCode h_wire;
@@ -529,16 +520,8 @@ TALER_EXCHANGE_deposit (struct TALER_EXCHANGE_Handle *exchange,
curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE,
strlen (dh->json_enc)));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEFUNCTION,
- &MAC_download_cb));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEDATA,
- &dh->db));
ctx = MAH_handle_to_context (exchange);
- dh->job = MAC_job_add (ctx,
+ dh->job = GNUNET_CURL_job_add (ctx,
eh,
GNUNET_YES,
&handle_deposit_finished,
@@ -558,10 +541,9 @@ TALER_EXCHANGE_deposit_cancel (struct TALER_EXCHANGE_DepositHandle *deposit)
{
if (NULL != deposit->job)
{
- MAC_job_cancel (deposit->job);
+ GNUNET_CURL_job_cancel (deposit->job);
deposit->job = NULL;
}
- GNUNET_free_non_null (deposit->db.buf);
GNUNET_free (deposit->url);
GNUNET_free (deposit->json_enc);
GNUNET_free (deposit);
diff --git a/src/exchange-lib/exchange_api_deposit_wtid.c b/src/exchange-lib/exchange_api_deposit_wtid.c
index 1ad1dd019..dc3bf1677 100644
--- a/src/exchange-lib/exchange_api_deposit_wtid.c
+++ b/src/exchange-lib/exchange_api_deposit_wtid.c
@@ -25,10 +25,10 @@
#include <microhttpd.h> /* just for HTTP status codes */
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
#include "taler_json_lib.h"
#include "taler_exchange_service.h"
#include "exchange_api_common.h"
-#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
@@ -57,7 +57,7 @@ struct TALER_EXCHANGE_DepositWtidHandle
/**
* Handle for the request.
*/
- struct MAC_Job *job;
+ struct GNUNET_CURL_Job *job;
/**
* Function to call with the result.
@@ -70,11 +70,6 @@ struct TALER_EXCHANGE_DepositWtidHandle
void *cb_cls;
/**
- * Download buffer
- */
- struct MAC_DownloadBuffer db;
-
- /**
* Information the exchange should sign in response.
* (with pre-filled fields from the request).
*/
@@ -93,7 +88,7 @@ struct TALER_EXCHANGE_DepositWtidHandle
*/
static int
verify_deposit_wtid_signature_ok (const struct TALER_EXCHANGE_DepositWtidHandle *dwh,
- json_t *json)
+ const json_t *json)
{
struct TALER_ExchangeSignatureP exchange_sig;
struct TALER_ExchangePublicKeyP exchange_pub;
@@ -138,24 +133,21 @@ verify_deposit_wtid_signature_ok (const struct TALER_EXCHANGE_DepositWtidHandle
* HTTP /deposit/wtid request.
*
* @param cls the `struct TALER_EXCHANGE_DepositWtidHandle`
- * @param eh the curl request handle
+ * @param response_code HTTP response code, 0 on error
+ * @param json parsed JSON result, NULL on error
*/
static void
handle_deposit_wtid_finished (void *cls,
- CURL *eh)
+ long response_code,
+ const json_t *json)
{
struct TALER_EXCHANGE_DepositWtidHandle *dwh = cls;
- long response_code;
- json_t *json;
const struct TALER_WireTransferIdentifierRawP *wtid = NULL;
struct GNUNET_TIME_Absolute execution_time = GNUNET_TIME_UNIT_FOREVER_ABS;
const struct TALER_Amount *coin_contribution = NULL;
struct TALER_Amount coin_contribution_s;
dwh->job = NULL;
- json = MAC_download_get_result (&dwh->db,
- eh,
- &response_code);
switch (response_code)
{
case 0:
@@ -243,7 +235,6 @@ handle_deposit_wtid_finished (void *cls,
wtid,
execution_time,
coin_contribution);
- json_decref (json);
TALER_EXCHANGE_deposit_wtid_cancel (dwh);
}
@@ -263,18 +254,18 @@ handle_deposit_wtid_finished (void *cls,
*/
struct TALER_EXCHANGE_DepositWtidHandle *
TALER_EXCHANGE_deposit_wtid (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_MerchantPrivateKeyP *merchant_priv,
- const struct GNUNET_HashCode *h_wire,
- const struct GNUNET_HashCode *h_contract,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- uint64_t transaction_id,
- TALER_EXCHANGE_DepositWtidCallback cb,
- void *cb_cls)
+ const struct TALER_MerchantPrivateKeyP *merchant_priv,
+ const struct GNUNET_HashCode *h_wire,
+ const struct GNUNET_HashCode *h_contract,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t transaction_id,
+ TALER_EXCHANGE_DepositWtidCallback cb,
+ void *cb_cls)
{
struct TALER_DepositTrackPS dtp;
struct TALER_MerchantSignatureP merchant_sig;
struct TALER_EXCHANGE_DepositWtidHandle *dwh;
- struct TALER_EXCHANGE_Context *ctx;
+ struct GNUNET_CURL_Context *ctx;
json_t *deposit_wtid_obj;
CURL *eh;
@@ -341,16 +332,8 @@ TALER_EXCHANGE_deposit_wtid (struct TALER_EXCHANGE_Handle *exchange,
curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE,
strlen (dwh->json_enc)));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEFUNCTION,
- &MAC_download_cb));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEDATA,
- &dwh->db));
ctx = MAH_handle_to_context (exchange);
- dwh->job = MAC_job_add (ctx,
+ dwh->job = GNUNET_CURL_job_add (ctx,
eh,
GNUNET_YES,
&handle_deposit_wtid_finished,
@@ -370,10 +353,9 @@ TALER_EXCHANGE_deposit_wtid_cancel (struct TALER_EXCHANGE_DepositWtidHandle *dwh
{
if (NULL != dwh->job)
{
- MAC_job_cancel (dwh->job);
+ GNUNET_CURL_job_cancel (dwh->job);
dwh->job = NULL;
}
- GNUNET_free_non_null (dwh->db.buf);
GNUNET_free (dwh->url);
GNUNET_free (dwh->json_enc);
GNUNET_free (dwh);
diff --git a/src/exchange-lib/exchange_api_handle.c b/src/exchange-lib/exchange_api_handle.c
index 65597126c..bd4746565 100644
--- a/src/exchange-lib/exchange_api_handle.c
+++ b/src/exchange-lib/exchange_api_handle.c
@@ -23,10 +23,10 @@
#include "platform.h"
#include <curl/curl.h>
#include <microhttpd.h>
+#include <gnunet/gnunet_curl_lib.h>
#include "taler_json_lib.h"
#include "taler_exchange_service.h"
#include "taler_signatures.h"
-#include "exchange_api_context.h"
#include "exchange_api_handle.h"
@@ -78,7 +78,7 @@ struct TALER_EXCHANGE_Handle
/**
* The context of this handle
*/
- struct TALER_EXCHANGE_Context *ctx;
+ struct GNUNET_CURL_Context *ctx;
/**
* The URL of the exchange (i.e. "http://exchange.taler.net/")
@@ -134,14 +134,9 @@ struct KeysRequest
char *url;
/**
- * Entry for this request with the `struct TALER_EXCHANGE_Context`.
+ * Entry for this request with the `struct GNUNET_CURL_Context`.
*/
- struct MAC_Job *job;
-
- /**
- * Data structure for the download.
- */
- struct MAC_DownloadBuffer db;
+ struct GNUNET_CURL_Job *job;
};
@@ -156,7 +151,6 @@ struct KeysRequest
static void
free_keys_request (struct KeysRequest *kr)
{
- GNUNET_free_non_null (kr->db.buf);
GNUNET_free (kr->url);
GNUNET_free (kr);
}
@@ -468,7 +462,7 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor,
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error (malformed JSON)
*/
static int
-decode_keys_json (json_t *resp_obj,
+decode_keys_json (const json_t *resp_obj,
struct TALER_EXCHANGE_Keys *key_data)
{
struct GNUNET_TIME_Absolute list_issue_date;
@@ -601,21 +595,18 @@ decode_keys_json (json_t *resp_obj,
* is complete.
*
* @param cls the `struct KeysRequest`
- * @param eh easy handle of the original request
+ * @param response_code HTTP response code, 0 on error
+ * @param resp_obj parsed JSON result, NULL on error
*/
static void
keys_completed_cb (void *cls,
- CURL *eh)
+ long response_code,
+ const json_t *resp_obj)
{
struct KeysRequest *kr = cls;
struct TALER_EXCHANGE_Handle *exchange = kr->exchange;
- json_t *resp_obj;
- long response_code;
TALER_EXCHANGE_CertificationCallback cb;
- resp_obj = MAC_download_get_result (&kr->db,
- eh,
- &response_code);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received keys from URL `%s' with status %ld.\n",
kr->url,
@@ -636,8 +627,6 @@ keys_completed_cb (void *cls,
response_code);
break;
}
- if (NULL != resp_obj)
- json_decref (resp_obj);
if (MHD_HTTP_OK != response_code)
{
@@ -675,7 +664,7 @@ keys_completed_cb (void *cls,
* @param h the exchange handle to query
* @return ctx context to execute jobs in
*/
-struct TALER_EXCHANGE_Context *
+struct GNUNET_CURL_Context *
MAH_handle_to_context (struct TALER_EXCHANGE_Handle *h)
{
return h->ctx;
@@ -738,11 +727,11 @@ MAH_path_to_url (struct TALER_EXCHANGE_Handle *h,
* @return the exchange handle; NULL upon error
*/
struct TALER_EXCHANGE_Handle *
-TALER_EXCHANGE_connect (struct TALER_EXCHANGE_Context *ctx,
- const char *url,
- TALER_EXCHANGE_CertificationCallback cert_cb,
- void *cert_cb_cls,
- ...)
+TALER_EXCHANGE_connect (struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ TALER_EXCHANGE_CertificationCallback cert_cb,
+ void *cert_cb_cls,
+ ...)
{
struct TALER_EXCHANGE_Handle *exchange;
struct KeysRequest *kr;
@@ -772,19 +761,11 @@ TALER_EXCHANGE_connect (struct TALER_EXCHANGE_Context *ctx,
curl_easy_setopt (c,
CURLOPT_URL,
kr->url));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (c,
- CURLOPT_WRITEFUNCTION,
- &MAC_download_cb));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (c,
- CURLOPT_WRITEDATA,
- &kr->db));
- kr->job = MAC_job_add (exchange->ctx,
- c,
- GNUNET_NO,
- &keys_completed_cb,
- kr);
+ kr->job = GNUNET_CURL_job_add (exchange->ctx,
+ c,
+ GNUNET_NO,
+ &keys_completed_cb,
+ kr);
exchange->kr = kr;
return exchange;
}
@@ -802,7 +783,7 @@ TALER_EXCHANGE_disconnect (struct TALER_EXCHANGE_Handle *exchange)
if (NULL != exchange->kr)
{
- MAC_job_cancel (exchange->kr->job);
+ GNUNET_CURL_job_cancel (exchange->kr->job);
free_keys_request (exchange->kr);
exchange->kr = NULL;
}
@@ -832,7 +813,7 @@ TALER_EXCHANGE_disconnect (struct TALER_EXCHANGE_Handle *exchange)
*/
int
TALER_EXCHANGE_test_signing_key (const struct TALER_EXCHANGE_Keys *keys,
- const struct TALER_ExchangePublicKeyP *pub)
+ const struct TALER_ExchangePublicKeyP *pub)
{
struct GNUNET_TIME_Absolute now;
unsigned int i;
diff --git a/src/exchange-lib/exchange_api_handle.h b/src/exchange-lib/exchange_api_handle.h
index 48423a7b8..2cf2166d0 100644
--- a/src/exchange-lib/exchange_api_handle.h
+++ b/src/exchange-lib/exchange_api_handle.h
@@ -30,7 +30,7 @@
* @param h the exchange handle to query
* @return ctx context to execute jobs in
*/
-struct TALER_EXCHANGE_Context *
+struct GNUNET_CURL_Context *
MAH_handle_to_context (struct TALER_EXCHANGE_Handle *h);
diff --git a/src/exchange-lib/exchange_api_refresh.c b/src/exchange-lib/exchange_api_refresh.c
index 5cdf059b7..8435a469c 100644
--- a/src/exchange-lib/exchange_api_refresh.c
+++ b/src/exchange-lib/exchange_api_refresh.c
@@ -25,10 +25,10 @@
#include <microhttpd.h> /* just for HTTP status codes */
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
#include "taler_json_lib.h"
#include "taler_exchange_service.h"
#include "exchange_api_common.h"
-#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
@@ -1044,7 +1044,7 @@ struct TALER_EXCHANGE_RefreshMeltHandle
/**
* Handle for the request.
*/
- struct MAC_Job *job;
+ struct GNUNET_CURL_Job *job;
/**
* Function to call with refresh melt failure results.
@@ -1057,11 +1057,6 @@ struct TALER_EXCHANGE_RefreshMeltHandle
void *melt_cb_cls;
/**
- * Download buffer
- */
- struct MAC_DownloadBuffer db;
-
- /**
* Actual information about the melt operation.
*/
struct MeltData *md;
@@ -1079,7 +1074,7 @@ struct TALER_EXCHANGE_RefreshMeltHandle
*/
static int
verify_refresh_melt_signature_ok (struct TALER_EXCHANGE_RefreshMeltHandle *rmh,
- json_t *json,
+ const json_t *json,
uint16_t *noreveal_index)
{
struct TALER_ExchangeSignatureP exchange_sig;
@@ -1148,7 +1143,7 @@ verify_refresh_melt_signature_ok (struct TALER_EXCHANGE_RefreshMeltHandle *rmh,
*/
static int
verify_refresh_melt_signature_forbidden (struct TALER_EXCHANGE_RefreshMeltHandle *rmh,
- json_t *json)
+ const json_t *json)
{
json_t *history;
struct TALER_Amount original_value;
@@ -1265,21 +1260,18 @@ verify_refresh_melt_signature_forbidden (struct TALER_EXCHANGE_RefreshMeltHandle
* HTTP /refresh/melt request.
*
* @param cls the `struct TALER_EXCHANGE_RefreshMeltHandle`
- * @param eh the curl request handle
+ * @param response_code HTTP response code, 0 on error
+ * @param json parsed JSON result, NULL on error
*/
static void
handle_refresh_melt_finished (void *cls,
- CURL *eh)
+ long response_code,
+ const json_t *json)
{
struct TALER_EXCHANGE_RefreshMeltHandle *rmh = cls;
- long response_code;
- json_t *json;
uint16_t noreveal_index = TALER_CNC_KAPPA; /* invalid value */
rmh->job = NULL;
- json = MAC_download_get_result (&rmh->db,
- eh,
- &response_code);
switch (response_code)
{
case 0:
@@ -1343,7 +1335,6 @@ handle_refresh_melt_finished (void *cls,
response_code,
UINT16_MAX,
json);
- json_decref (json);
TALER_EXCHANGE_refresh_melt_cancel (rmh);
}
@@ -1427,7 +1418,7 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange,
json_t *tmp;
struct TALER_EXCHANGE_RefreshMeltHandle *rmh;
CURL *eh;
- struct TALER_EXCHANGE_Context *ctx;
+ struct GNUNET_CURL_Context *ctx;
struct MeltData *md;
unsigned int i;
unsigned int j;
@@ -1610,16 +1601,8 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange,
curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE,
strlen (rmh->json_enc)));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEFUNCTION,
- &MAC_download_cb));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEDATA,
- &rmh->db));
ctx = MAH_handle_to_context (exchange);
- rmh->job = MAC_job_add (ctx,
+ rmh->job = GNUNET_CURL_job_add (ctx,
eh,
GNUNET_YES,
&handle_refresh_melt_finished,
@@ -1639,10 +1622,9 @@ TALER_EXCHANGE_refresh_melt_cancel (struct TALER_EXCHANGE_RefreshMeltHandle *rmh
{
if (NULL != rmh->job)
{
- MAC_job_cancel (rmh->job);
+ GNUNET_CURL_job_cancel (rmh->job);
rmh->job = NULL;
}
- GNUNET_free_non_null (rmh->db.buf);
free_melt_data (rmh->md); /* does not free 'md' itself */
GNUNET_free (rmh->md);
GNUNET_free (rmh->url);
@@ -1678,7 +1660,7 @@ struct TALER_EXCHANGE_RefreshRevealHandle
/**
* Handle for the request.
*/
- struct MAC_Job *job;
+ struct GNUNET_CURL_Job *job;
/**
* Function to call with the result.
@@ -1691,11 +1673,6 @@ struct TALER_EXCHANGE_RefreshRevealHandle
void *reveal_cb_cls;
/**
- * Download buffer
- */
- struct MAC_DownloadBuffer db;
-
- /**
* Actual information about the melt operation.
*/
struct MeltData *md;
@@ -1726,7 +1703,7 @@ struct TALER_EXCHANGE_RefreshRevealHandle
*/
static int
refresh_reveal_ok (struct TALER_EXCHANGE_RefreshRevealHandle *rrh,
- json_t *json,
+ const json_t *json,
struct TALER_CoinSpendPrivateKeyP *coin_privs,
struct TALER_DenominationSignature *sigs)
{
@@ -1820,20 +1797,17 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshRevealHandle *rrh,
* HTTP /refresh/reveal request.
*
* @param cls the `struct TALER_EXCHANGE_RefreshHandle`
- * @param eh the curl request handle
+ * @param response_code HTTP response code, 0 on error
+ * @param json parsed JSON result, NULL on error
*/
static void
handle_refresh_reveal_finished (void *cls,
- CURL *eh)
+ long response_code,
+ const json_t *json)
{
struct TALER_EXCHANGE_RefreshRevealHandle *rrh = cls;
- long response_code;
- json_t *json;
rrh->job = NULL;
- json = MAC_download_get_result (&rrh->db,
- eh,
- &response_code);
switch (response_code)
{
case 0:
@@ -1896,7 +1870,6 @@ handle_refresh_reveal_finished (void *cls,
response_code,
0, NULL, NULL,
json);
- json_decref (json);
TALER_EXCHANGE_refresh_reveal_cancel (rrh);
}
@@ -1936,7 +1909,7 @@ TALER_EXCHANGE_refresh_reveal (struct TALER_EXCHANGE_Handle *exchange,
json_t *reveal_obj;
json_t *tmp;
CURL *eh;
- struct TALER_EXCHANGE_Context *ctx;
+ struct GNUNET_CURL_Context *ctx;
struct MeltData *md;
unsigned int i;
unsigned int j;
@@ -2022,16 +1995,8 @@ 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_WRITEFUNCTION,
- &MAC_download_cb));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEDATA,
- &rrh->db));
ctx = MAH_handle_to_context (rrh->exchange);
- rrh->job = MAC_job_add (ctx,
+ rrh->job = GNUNET_CURL_job_add (ctx,
eh,
GNUNET_YES,
&handle_refresh_reveal_finished,
@@ -2051,10 +2016,9 @@ TALER_EXCHANGE_refresh_reveal_cancel (struct TALER_EXCHANGE_RefreshRevealHandle
{
if (NULL != rrh->job)
{
- MAC_job_cancel (rrh->job);
+ GNUNET_CURL_job_cancel (rrh->job);
rrh->job = NULL;
}
- GNUNET_free_non_null (rrh->db.buf);
GNUNET_free (rrh->url);
GNUNET_free (rrh->json_enc);
free_melt_data (rrh->md); /* does not free 'md' itself */
diff --git a/src/exchange-lib/exchange_api_refresh_link.c b/src/exchange-lib/exchange_api_refresh_link.c
index 8bb40d7f4..e809c3f14 100644
--- a/src/exchange-lib/exchange_api_refresh_link.c
+++ b/src/exchange-lib/exchange_api_refresh_link.c
@@ -23,9 +23,9 @@
#include <curl/curl.h>
#include <microhttpd.h> /* just for HTTP status codes */
#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
#include "taler_exchange_service.h"
#include "taler_json_lib.h"
-#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
@@ -49,7 +49,7 @@ struct TALER_EXCHANGE_RefreshLinkHandle
/**
* Handle for the request.
*/
- struct MAC_Job *job;
+ struct GNUNET_CURL_Job *job;
/**
* Function to call with the result.
@@ -62,11 +62,6 @@ struct TALER_EXCHANGE_RefreshLinkHandle
void *link_cb_cls;
/**
- * Download buffer
- */
- struct MAC_DownloadBuffer db;
-
- /**
* Private key of the coin, required to decode link information.
*/
struct TALER_CoinSpendPrivateKeyP coin_priv;
@@ -89,7 +84,7 @@ struct TALER_EXCHANGE_RefreshLinkHandle
*/
static int
parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
- json_t *json,
+ const json_t *json,
const struct TALER_TransferPublicKeyP *trans_pub,
const struct TALER_EncryptedLinkSecretP *secret_enc,
struct TALER_CoinSpendPrivateKeyP *coin_priv,
@@ -173,7 +168,7 @@ parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
*/
static int
parse_refresh_link_ok (struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
- json_t *json)
+ const json_t *json)
{
unsigned int session;
unsigned int num_coins;
@@ -329,20 +324,17 @@ parse_refresh_link_ok (struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
* HTTP /refresh/link request.
*
* @param cls the `struct TALER_EXCHANGE_RefreshLinkHandle`
- * @param eh the curl request handle
+ * @param response_code HTTP response code, 0 on error
+ * @param json parsed JSON result, NULL on error
*/
static void
handle_refresh_link_finished (void *cls,
- CURL *eh)
+ long response_code,
+ const json_t *json)
{
struct TALER_EXCHANGE_RefreshLinkHandle *rlh = cls;
- long response_code;
- json_t *json;
rlh->job = NULL;
- json = MAC_download_get_result (&rlh->db,
- eh,
- &response_code);
switch (response_code)
{
case 0:
@@ -382,7 +374,6 @@ handle_refresh_link_finished (void *cls,
response_code,
0, NULL, NULL, NULL,
json);
- json_decref (json);
TALER_EXCHANGE_refresh_link_cancel (rlh);
}
@@ -409,7 +400,7 @@ TALER_EXCHANGE_refresh_link (struct TALER_EXCHANGE_Handle *exchange,
{
struct TALER_EXCHANGE_RefreshLinkHandle *rlh;
CURL *eh;
- struct TALER_EXCHANGE_Context *ctx;
+ struct GNUNET_CURL_Context *ctx;
struct TALER_CoinSpendPublicKeyP coin_pub;
char *pub_str;
char *arg_str;
@@ -443,16 +434,8 @@ TALER_EXCHANGE_refresh_link (struct TALER_EXCHANGE_Handle *exchange,
curl_easy_setopt (eh,
CURLOPT_URL,
rlh->url));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEFUNCTION,
- &MAC_download_cb));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEDATA,
- &rlh->db));
ctx = MAH_handle_to_context (exchange);
- rlh->job = MAC_job_add (ctx,
+ rlh->job = GNUNET_CURL_job_add (ctx,
eh,
GNUNET_YES,
&handle_refresh_link_finished,
@@ -472,10 +455,9 @@ TALER_EXCHANGE_refresh_link_cancel (struct TALER_EXCHANGE_RefreshLinkHandle *rlh
{
if (NULL != rlh->job)
{
- MAC_job_cancel (rlh->job);
+ GNUNET_CURL_job_cancel (rlh->job);
rlh->job = NULL;
}
- GNUNET_free_non_null (rlh->db.buf);
GNUNET_free (rlh->url);
GNUNET_free (rlh);
}
diff --git a/src/exchange-lib/exchange_api_reserve.c b/src/exchange-lib/exchange_api_reserve.c
index 8c3663244..d3e55ed93 100644
--- a/src/exchange-lib/exchange_api_reserve.c
+++ b/src/exchange-lib/exchange_api_reserve.c
@@ -25,9 +25,9 @@
#include <microhttpd.h> /* just for HTTP status codes */
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
#include "taler_exchange_service.h"
#include "taler_json_lib.h"
-#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
@@ -53,7 +53,7 @@ struct TALER_EXCHANGE_ReserveStatusHandle
/**
* Handle for the request.
*/
- struct MAC_Job *job;
+ struct GNUNET_CURL_Job *job;
/**
* Function to call with the result.
@@ -70,11 +70,6 @@ struct TALER_EXCHANGE_ReserveStatusHandle
*/
void *cb_cls;
- /**
- * Download buffer
- */
- struct MAC_DownloadBuffer db;
-
};
@@ -94,7 +89,7 @@ struct TALER_EXCHANGE_ReserveStatusHandle
* #GNUNET_SYSERR if there was a protocol violation in @a history
*/
static int
-parse_reserve_history (json_t *history,
+parse_reserve_history (const json_t *history,
const struct TALER_ReservePublicKeyP *reserve_pub,
const char *currency,
struct TALER_Amount *balance,
@@ -273,20 +268,17 @@ parse_reserve_history (json_t *history,
* HTTP /reserve/status request.
*
* @param cls the `struct TALER_EXCHANGE_ReserveStatusHandle`
- * @param eh curl handle of the request that finished
+ * @param response_code HTTP response code, 0 on error
+ * @param json parsed JSON result, NULL on error
*/
static void
handle_reserve_status_finished (void *cls,
- CURL *eh)
+ long response_code,
+ const json_t *json)
{
struct TALER_EXCHANGE_ReserveStatusHandle *wsh = cls;
- long response_code;
- json_t *json;
wsh->job = NULL;
- json = MAC_download_get_result (&wsh->db,
- eh,
- &response_code);
switch (response_code)
{
case 0:
@@ -382,7 +374,6 @@ handle_reserve_status_finished (void *cls,
json,
NULL,
0, NULL);
- json_decref (json);
TALER_EXCHANGE_reserve_status_cancel (wsh);
}
@@ -405,12 +396,12 @@ handle_reserve_status_finished (void *cls,
*/
struct TALER_EXCHANGE_ReserveStatusHandle *
TALER_EXCHANGE_reserve_status (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- TALER_EXCHANGE_ReserveStatusResultCallback cb,
- void *cb_cls)
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ TALER_EXCHANGE_ReserveStatusResultCallback cb,
+ void *cb_cls)
{
struct TALER_EXCHANGE_ReserveStatusHandle *wsh;
- struct TALER_EXCHANGE_Context *ctx;
+ struct GNUNET_CURL_Context *ctx;
CURL *eh;
char *pub_str;
char *arg_str;
@@ -441,16 +432,8 @@ TALER_EXCHANGE_reserve_status (struct TALER_EXCHANGE_Handle *exchange,
curl_easy_setopt (eh,
CURLOPT_URL,
wsh->url));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEFUNCTION,
- &MAC_download_cb));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEDATA,
- &wsh->db));
ctx = MAH_handle_to_context (exchange);
- wsh->job = MAC_job_add (ctx,
+ wsh->job = GNUNET_CURL_job_add (ctx,
eh,
GNUNET_NO,
&handle_reserve_status_finished,
@@ -470,10 +453,9 @@ TALER_EXCHANGE_reserve_status_cancel (struct TALER_EXCHANGE_ReserveStatusHandle
{
if (NULL != wsh->job)
{
- MAC_job_cancel (wsh->job);
+ GNUNET_CURL_job_cancel (wsh->job);
wsh->job = NULL;
}
- GNUNET_free_non_null (wsh->db.buf);
GNUNET_free (wsh->url);
GNUNET_free (wsh);
}
@@ -505,7 +487,7 @@ struct TALER_EXCHANGE_ReserveWithdrawHandle
/**
* Handle for the request.
*/
- struct MAC_Job *job;
+ struct GNUNET_CURL_Job *job;
/**
* Function to call with the result.
@@ -528,11 +510,6 @@ struct TALER_EXCHANGE_ReserveWithdrawHandle
void *cb_cls;
/**
- * Download buffer
- */
- struct MAC_DownloadBuffer db;
-
- /**
* Hash of the public key of the coin we are signing.
*/
struct GNUNET_HashCode c_hash;
@@ -561,7 +538,7 @@ struct TALER_EXCHANGE_ReserveWithdrawHandle
*/
static int
reserve_withdraw_ok (struct TALER_EXCHANGE_ReserveWithdrawHandle *wsh,
- json_t *json)
+ const json_t *json)
{
struct GNUNET_CRYPTO_RsaSignature *blind_sig;
struct GNUNET_CRYPTO_RsaSignature *sig;
@@ -619,7 +596,7 @@ reserve_withdraw_ok (struct TALER_EXCHANGE_ReserveWithdrawHandle *wsh,
*/
static int
reserve_withdraw_payment_required (struct TALER_EXCHANGE_ReserveWithdrawHandle *wsh,
- json_t *json)
+ const json_t *json)
{
struct TALER_Amount balance;
struct TALER_Amount balance_from_history;
@@ -702,20 +679,17 @@ reserve_withdraw_payment_required (struct TALER_EXCHANGE_ReserveWithdrawHandle *
* HTTP /reserve/withdraw request.
*
* @param cls the `struct TALER_EXCHANGE_ReserveWithdrawHandle`
- * @param eh curl handle of the request that finished
+ * @param response_code HTTP response code, 0 on error
+ * @param json parsed JSON result, NULL on error
*/
static void
handle_reserve_withdraw_finished (void *cls,
- CURL *eh)
+ long response_code,
+ const json_t *json)
{
struct TALER_EXCHANGE_ReserveWithdrawHandle *wsh = cls;
- long response_code;
- json_t *json;
wsh->job = NULL;
- json = MAC_download_get_result (&wsh->db,
- eh,
- &response_code);
switch (response_code)
{
case 0:
@@ -774,7 +748,6 @@ handle_reserve_withdraw_finished (void *cls,
response_code,
NULL,
json);
- json_decref (json);
TALER_EXCHANGE_reserve_withdraw_cancel (wsh);
}
@@ -801,18 +774,18 @@ handle_reserve_withdraw_finished (void *cls,
*/
struct TALER_EXCHANGE_ReserveWithdrawHandle *
TALER_EXCHANGE_reserve_withdraw (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_EXCHANGE_DenomPublicKey *pk,
- const struct TALER_ReservePrivateKeyP *reserve_priv,
- const struct TALER_CoinSpendPrivateKeyP *coin_priv,
- const struct TALER_DenominationBlindingKey *blinding_key,
- TALER_EXCHANGE_ReserveWithdrawResultCallback res_cb,
- void *res_cb_cls)
+ const struct TALER_EXCHANGE_DenomPublicKey *pk,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ const struct TALER_CoinSpendPrivateKeyP *coin_priv,
+ const struct TALER_DenominationBlindingKey *blinding_key,
+ TALER_EXCHANGE_ReserveWithdrawResultCallback res_cb,
+ void *res_cb_cls)
{
struct TALER_EXCHANGE_ReserveWithdrawHandle *wsh;
struct TALER_WithdrawRequestPS req;
struct TALER_ReserveSignatureP reserve_sig;
struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_EXCHANGE_Context *ctx;
+ struct GNUNET_CURL_Context *ctx;
struct TALER_Amount amount_with_fee;
char *coin_ev;
size_t coin_ev_size;
@@ -894,16 +867,8 @@ TALER_EXCHANGE_reserve_withdraw (struct TALER_EXCHANGE_Handle *exchange,
curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE,
strlen (wsh->json_enc)));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEFUNCTION,
- &MAC_download_cb));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEDATA,
- &wsh->db));
ctx = MAH_handle_to_context (exchange);
- wsh->job = MAC_job_add (ctx,
+ wsh->job = GNUNET_CURL_job_add (ctx,
eh,
GNUNET_YES,
&handle_reserve_withdraw_finished,
@@ -923,10 +888,9 @@ TALER_EXCHANGE_reserve_withdraw_cancel (struct TALER_EXCHANGE_ReserveWithdrawHan
{
if (NULL != sign->job)
{
- MAC_job_cancel (sign->job);
+ GNUNET_CURL_job_cancel (sign->job);
sign->job = NULL;
}
- GNUNET_free_non_null (sign->db.buf);
GNUNET_free (sign->url);
GNUNET_free (sign->json_enc);
GNUNET_free (sign);
diff --git a/src/exchange-lib/exchange_api_wire.c b/src/exchange-lib/exchange_api_wire.c
index 0e93a9d20..453da14d2 100644
--- a/src/exchange-lib/exchange_api_wire.c
+++ b/src/exchange-lib/exchange_api_wire.c
@@ -24,11 +24,11 @@
#include <jansson.h>
#include <microhttpd.h> /* just for HTTP status codes */
#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
#include "taler_exchange_service.h"
#include "taler_json_lib.h"
#include "taler_wire_plugin.h"
#include "exchange_api_common.h"
-#include "exchange_api_context.h"
#include "exchange_api_handle.h"
@@ -51,7 +51,7 @@ struct TALER_EXCHANGE_WireHandle
/**
* Handle for the request.
*/
- struct MAC_Job *job;
+ struct GNUNET_CURL_Job *job;
/**
* Function to call with the result.
@@ -64,11 +64,6 @@ struct TALER_EXCHANGE_WireHandle
void *cb_cls;
/**
- * Download buffer
- */
- struct MAC_DownloadBuffer db;
-
- /**
* Set to the "methods" JSON array returned by the
* /wire request.
*/
@@ -96,7 +91,7 @@ struct TALER_EXCHANGE_WireHandle
static int
verify_wire_method_signature_ok (const struct TALER_EXCHANGE_WireHandle *wh,
const char *method,
- json_t *json)
+ const json_t *json)
{
const struct TALER_EXCHANGE_Keys *key_state;
struct TALER_WIRE_Plugin *plugin;
@@ -133,20 +128,18 @@ verify_wire_method_signature_ok (const struct TALER_EXCHANGE_WireHandle *wh,
* HTTP /wire request.
*
* @param cls the `struct TALER_EXCHANGE_WireHandle`
- * @param eh the curl request handle
+ * @param response_code HTTP response code, 0 on error
+ * @param json parsed JSON result, NULL on error
*/
static void
handle_wire_finished (void *cls,
- CURL *eh)
+ long response_code,
+ const json_t *json)
{
struct TALER_EXCHANGE_WireHandle *wh = cls;
- long response_code;
- json_t *json;
+ json_t *keep = NULL;
wh->job = NULL;
- json = MAC_download_get_result (&wh->db,
- eh,
- &response_code);
switch (response_code)
{
case 0:
@@ -155,14 +148,13 @@ handle_wire_finished (void *cls,
{
const char *key;
json_t *method;
- json_t *keep;
int ret;
/* We 'keep' methods that we support and that are well-formed;
we fail (by setting response_code=0) if any method that we do
support fails to verify. */
keep = json_object ();
- json_object_foreach (json, key, method) {
+ json_object_foreach ((json_t *) json, key, method) {
ret = verify_wire_method_signature_ok (wh,
key,
method);
@@ -184,8 +176,6 @@ handle_wire_finished (void *cls,
if (0 != response_code)
{
/* all supported methods were valid, use 'keep' for 'json' */
- json_decref (json);
- json = keep;
break;
}
else
@@ -193,6 +183,7 @@ handle_wire_finished (void *cls,
/* some supported methods were invalid, release 'keep', preserve
full 'json' for application-level error handling. */
json_decref (keep);
+ keep = NULL;
}
}
break;
@@ -219,9 +210,9 @@ handle_wire_finished (void *cls,
}
wh->cb (wh->cb_cls,
response_code,
- json);
- if (NULL != json)
- json_decref (json);
+ (NULL != keep) ? keep : json);
+ if (NULL != keep)
+ json_decref (keep);
TALER_EXCHANGE_wire_cancel (wh);
}
@@ -252,7 +243,7 @@ TALER_EXCHANGE_wire (struct TALER_EXCHANGE_Handle *exchange,
void *wire_cb_cls)
{
struct TALER_EXCHANGE_WireHandle *wh;
- struct TALER_EXCHANGE_Context *ctx;
+ struct GNUNET_CURL_Context *ctx;
CURL *eh;
if (GNUNET_YES !=
@@ -272,16 +263,8 @@ TALER_EXCHANGE_wire (struct TALER_EXCHANGE_Handle *exchange,
curl_easy_setopt (eh,
CURLOPT_URL,
wh->url));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEFUNCTION,
- &MAC_download_cb));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEDATA,
- &wh->db));
ctx = MAH_handle_to_context (exchange);
- wh->job = MAC_job_add (ctx,
+ wh->job = GNUNET_CURL_job_add (ctx,
eh,
GNUNET_YES,
&handle_wire_finished,
@@ -301,7 +284,7 @@ TALER_EXCHANGE_wire_cancel (struct TALER_EXCHANGE_WireHandle *wh)
{
if (NULL != wh->job)
{
- MAC_job_cancel (wh->job);
+ GNUNET_CURL_job_cancel (wh->job);
wh->job = NULL;
}
if (NULL != wh->methods)
@@ -309,7 +292,6 @@ TALER_EXCHANGE_wire_cancel (struct TALER_EXCHANGE_WireHandle *wh)
json_decref (wh->methods);
wh->methods = NULL;
}
- GNUNET_free_non_null (wh->db.buf);
GNUNET_free (wh->url);
GNUNET_free (wh);
}
diff --git a/src/exchange-lib/exchange_api_wire_deposits.c b/src/exchange-lib/exchange_api_wire_deposits.c
index 49a50f640..bcb29e872 100644
--- a/src/exchange-lib/exchange_api_wire_deposits.c
+++ b/src/exchange-lib/exchange_api_wire_deposits.c
@@ -24,10 +24,10 @@
#include <jansson.h>
#include <microhttpd.h> /* just for HTTP status codes */
#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
#include "taler_exchange_service.h"
#include "exchange_api_common.h"
#include "taler_json_lib.h"
-#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
@@ -51,7 +51,7 @@ struct TALER_EXCHANGE_WireDepositsHandle
/**
* Handle for the request.
*/
- struct MAC_Job *job;
+ struct GNUNET_CURL_Job *job;
/**
* Function to call with the result.
@@ -63,11 +63,6 @@ struct TALER_EXCHANGE_WireDepositsHandle
*/
void *cb_cls;
- /**
- * Download buffer
- */
- struct MAC_DownloadBuffer db;
-
};
@@ -76,20 +71,17 @@ struct TALER_EXCHANGE_WireDepositsHandle
* HTTP /wire/deposits request.
*
* @param cls the `struct TALER_EXCHANGE_WireDepositsHandle`
- * @param eh the curl request handle
+ * @param response_code HTTP response code, 0 on error
+ * @param json parsed JSON result, NULL on error
*/
static void
handle_wire_deposits_finished (void *cls,
- CURL *eh)
+ long response_code,
+ const json_t *json)
{
struct TALER_EXCHANGE_WireDepositsHandle *wdh = cls;
- long response_code;
- json_t *json;
wdh->job = NULL;
- json = MAC_download_get_result (&wdh->db,
- eh,
- &response_code);
switch (response_code)
{
case 0:
@@ -199,7 +191,6 @@ handle_wire_deposits_finished (void *cls,
&total_amount,
num_details,
details);
- json_decref (json);
TALER_EXCHANGE_wire_deposits_cancel (wdh);
return;
}
@@ -235,7 +226,6 @@ handle_wire_deposits_finished (void *cls,
response_code,
json,
NULL, NULL, 0, NULL);
- json_decref (json);
TALER_EXCHANGE_wire_deposits_cancel (wdh);
}
@@ -257,7 +247,7 @@ TALER_EXCHANGE_wire_deposits (struct TALER_EXCHANGE_Handle *exchange,
void *cb_cls)
{
struct TALER_EXCHANGE_WireDepositsHandle *wdh;
- struct TALER_EXCHANGE_Context *ctx;
+ struct GNUNET_CURL_Context *ctx;
char *buf;
char *path;
CURL *eh;
@@ -289,16 +279,8 @@ TALER_EXCHANGE_wire_deposits (struct TALER_EXCHANGE_Handle *exchange,
curl_easy_setopt (eh,
CURLOPT_URL,
wdh->url));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEFUNCTION,
- &MAC_download_cb));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_WRITEDATA,
- &wdh->db));
ctx = MAH_handle_to_context (exchange);
- wdh->job = MAC_job_add (ctx,
+ wdh->job = GNUNET_CURL_job_add (ctx,
eh,
GNUNET_YES,
&handle_wire_deposits_finished,
@@ -318,10 +300,9 @@ TALER_EXCHANGE_wire_deposits_cancel (struct TALER_EXCHANGE_WireDepositsHandle *w
{
if (NULL != wdh->job)
{
- MAC_job_cancel (wdh->job);
+ GNUNET_CURL_job_cancel (wdh->job);
wdh->job = NULL;
}
- GNUNET_free_non_null (wdh->db.buf);
GNUNET_free (wdh->url);
GNUNET_free (wdh);
}
diff --git a/src/exchange-lib/test_exchange_api.c b/src/exchange-lib/test_exchange_api.c
index 3659e119e..2936f68fb 100644
--- a/src/exchange-lib/test_exchange_api.c
+++ b/src/exchange-lib/test_exchange_api.c
@@ -40,7 +40,7 @@
/**
* Main execution context for the main loop.
*/
-static struct TALER_EXCHANGE_Context *ctx;
+static struct GNUNET_CURL_Context *ctx;
/**
* Handle to access the exchange.
@@ -655,7 +655,7 @@ interpreter_run (void *cls);
static void
add_incoming_cb (void *cls,
unsigned int http_status,
- json_t *full_response)
+ const json_t *full_response)
{
struct InterpreterState *is = cls;
struct Command *cmd = &is->commands[is->ip];
@@ -756,7 +756,7 @@ compare_reserve_withdraw_history (const struct TALER_EXCHANGE_ReserveHistory *h,
static void
reserve_status_cb (void *cls,
unsigned int http_status,
- json_t *json,
+ const json_t *json,
const struct TALER_Amount *balance,
unsigned int history_length,
const struct TALER_EXCHANGE_ReserveHistory *history)
@@ -873,7 +873,7 @@ static void
reserve_withdraw_cb (void *cls,
unsigned int http_status,
const struct TALER_DenominationSignature *sig,
- json_t *full_response)
+ const json_t *full_response)
{
struct InterpreterState *is = cls;
struct Command *cmd = &is->commands[is->ip];
@@ -928,7 +928,7 @@ reserve_withdraw_cb (void *cls,
static void
deposit_cb (void *cls,
unsigned int http_status,
- json_t *obj)
+ const json_t *obj)
{
struct InterpreterState *is = cls;
struct Command *cmd = &is->commands[is->ip];
@@ -964,7 +964,7 @@ static void
melt_cb (void *cls,
unsigned int http_status,
uint16_t noreveal_index,
- json_t *full_response)
+ const json_t *full_response)
{
struct InterpreterState *is = cls;
struct Command *cmd = &is->commands[is->ip];
@@ -1004,7 +1004,7 @@ reveal_cb (void *cls,
unsigned int num_coins,
const struct TALER_CoinSpendPrivateKeyP *coin_privs,
const struct TALER_DenominationSignature *sigs,
- json_t *full_response)
+ const json_t *full_response)
{
struct InterpreterState *is = cls;
struct Command *cmd = &is->commands[is->ip];
@@ -1071,7 +1071,7 @@ link_cb (void *cls,
const struct TALER_CoinSpendPrivateKeyP *coin_privs,
const struct TALER_DenominationSignature *sigs,
const struct TALER_DenominationPublicKey *pubs,
- json_t *full_response)
+ const json_t *full_response)
{
struct InterpreterState *is = cls;
struct Command *cmd = &is->commands[is->ip];
@@ -1218,7 +1218,7 @@ find_pk (const struct TALER_EXCHANGE_Keys *keys,
static void
wire_cb (void *cls,
unsigned int http_status,
- json_t *obj)
+ const json_t *obj)
{
struct InterpreterState *is = cls;
struct Command *cmd = &is->commands[is->ip];
@@ -1281,7 +1281,7 @@ wire_cb (void *cls,
static void
wire_deposits_cb (void *cls,
unsigned int http_status,
- json_t *json,
+ const json_t *json,
const struct GNUNET_HashCode *h_wire,
const struct TALER_Amount *total_amount,
unsigned int details_length,
@@ -1371,7 +1371,7 @@ wire_deposits_cb (void *cls,
static void
deposit_wtid_cb (void *cls,
unsigned int http_status,
- json_t *json,
+ const json_t *json,
const struct TALER_WireTransferIdentifierRawP *wtid,
struct GNUNET_TIME_Absolute execution_time,
const struct TALER_Amount *coin_contribution)
@@ -2168,7 +2168,7 @@ do_shutdown (void *cls)
}
if (NULL != ctx)
{
- TALER_EXCHANGE_fini (ctx);
+ GNUNET_CURL_fini (ctx);
ctx = NULL;
}
}
@@ -2226,18 +2226,18 @@ context_task (void *cls)
struct GNUNET_TIME_Relative delay;
ctx_task = NULL;
- TALER_EXCHANGE_perform (ctx);
+ GNUNET_CURL_perform (ctx);
max_fd = -1;
timeout = -1;
FD_ZERO (&read_fd_set);
FD_ZERO (&write_fd_set);
FD_ZERO (&except_fd_set);
- TALER_EXCHANGE_get_select_info (ctx,
- &read_fd_set,
- &write_fd_set,
- &except_fd_set,
- &max_fd,
- &timeout);
+ GNUNET_CURL_get_select_info (ctx,
+ &read_fd_set,
+ &write_fd_set,
+ &except_fd_set,
+ &max_fd,
+ &timeout);
if (timeout >= 0)
delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
timeout);
@@ -2507,7 +2507,7 @@ run (void *cls)
is = GNUNET_new (struct InterpreterState);
is->commands = commands;
- ctx = TALER_EXCHANGE_init ();
+ ctx = GNUNET_CURL_init ();
GNUNET_assert (NULL != ctx);
ctx_task = GNUNET_SCHEDULER_add_now (&context_task,
ctx);
diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h
index 4a1592cf2..fa240ee9c 100644
--- a/src/include/taler_exchange_service.h
+++ b/src/include/taler_exchange_service.h
@@ -24,6 +24,7 @@
#include <jansson.h>
#include "taler_util.h"
+#include <gnunet/gnunet_curl_lib.h>
/* ********************* event loop *********************** */
@@ -319,7 +320,7 @@ struct TALER_EXCHANGE_Handle;
* @return the exchange handle; NULL upon error
*/
struct TALER_EXCHANGE_Handle *
-TALER_EXCHANGE_connect (struct TALER_EXCHANGE_Context *ctx,
+TALER_EXCHANGE_connect (struct GNUNET_CURL_Context *ctx,
const char *url,
TALER_EXCHANGE_CertificationCallback cert_cb,
void *cert_cb_cls,
@@ -409,7 +410,7 @@ struct TALER_EXCHANGE_WireHandle;
typedef void
(*TALER_EXCHANGE_WireResultCallback) (void *cls,
unsigned int http_status,
- json_t *obj);
+ const json_t *obj);
/**
@@ -469,7 +470,7 @@ struct TALER_EXCHANGE_DepositHandle;
typedef void
(*TALER_EXCHANGE_DepositResultCallback) (void *cls,
unsigned int http_status,
- json_t *obj);
+ const json_t *obj);
/**
@@ -612,7 +613,7 @@ struct TALER_EXCHANGE_ReserveHistory
typedef void
(*TALER_EXCHANGE_ReserveStatusResultCallback) (void *cls,
unsigned int http_status,
- json_t *json,
+ const json_t *json,
const struct TALER_Amount *balance,
unsigned int history_length,
const struct TALER_EXCHANGE_ReserveHistory *history);
@@ -674,7 +675,7 @@ typedef void
(*TALER_EXCHANGE_ReserveWithdrawResultCallback) (void *cls,
unsigned int http_status,
const struct TALER_DenominationSignature *sig,
- json_t *full_response);
+ const json_t *full_response);
/**
@@ -797,9 +798,9 @@ struct TALER_EXCHANGE_RefreshMeltHandle;
*/
typedef void
(*TALER_EXCHANGE_RefreshMeltCallback) (void *cls,
- unsigned int http_status,
- uint16_t noreveal_index,
- json_t *full_response);
+ unsigned int http_status,
+ uint16_t noreveal_index,
+ const json_t *full_response);
/**
@@ -866,7 +867,7 @@ typedef void
unsigned int num_coins,
const struct TALER_CoinSpendPrivateKeyP *coin_privs,
const struct TALER_DenominationSignature *sigs,
- json_t *full_response);
+ const json_t *full_response);
/**
@@ -947,7 +948,7 @@ typedef void
const struct TALER_CoinSpendPrivateKeyP *coin_privs,
const struct TALER_DenominationSignature *sigs,
const struct TALER_DenominationPublicKey *pubs,
- json_t *full_response);
+ const json_t *full_response);
/**
@@ -1003,7 +1004,7 @@ struct TALER_EXCHANGE_AdminAddIncomingHandle;
typedef void
(*TALER_EXCHANGE_AdminAddIncomingResultCallback) (void *cls,
unsigned int http_status,
- json_t *full_response);
+ const json_t *full_response);
/**
@@ -1103,7 +1104,7 @@ struct TALER_WireDepositDetails
typedef void
(*TALER_EXCHANGE_WireDepositsCallback)(void *cls,
unsigned int http_status,
- json_t *json,
+ const json_t *json,
const struct GNUNET_HashCode *h_wire,
const struct TALER_Amount *total_amount,
unsigned int details_length,
@@ -1161,7 +1162,7 @@ struct TALER_EXCHANGE_DepositWtidHandle;
typedef void
(*TALER_EXCHANGE_DepositWtidCallback)(void *cls,
unsigned int http_status,
- json_t *json,
+ const json_t *json,
const struct TALER_WireTransferIdentifierRawP *wtid,
struct GNUNET_TIME_Absolute execution_time,
const struct TALER_Amount *coin_contribution);