commit f9441ca8541756e454a6560f8f7dc11afd8b300c
parent 921344236b01e5e6c39eb21d3602eb4bf31b90f3
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 17 Apr 2016 22:04:58 +0200
finish FTBFS caused by refactoring
Diffstat:
6 files changed, 89 insertions(+), 204 deletions(-)
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
@@ -28,5 +28,6 @@ taler_merchant_httpd_LDADD = \
-ltalerpq \
-lmicrohttpd \
-ljansson \
+ -lgnunetcurl \
-lgnunetjson \
-lgnunetutil
diff --git a/src/backend/taler-merchant-httpd_exchanges.c b/src/backend/taler-merchant-httpd_exchanges.c
@@ -141,7 +141,7 @@ struct Exchange
/**
* Context for all exchange operations (useful to the event loop)
*/
-static struct TALER_EXCHANGE_Context *ctx;
+static struct GNUNET_CURL_Context *ctx;
/**
* Task we use to drive the interaction with this exchange.
@@ -232,18 +232,18 @@ context_task (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In exchange context polling task\n");
poller_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);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"In exchange context polling task, max_fd=%d, timeout=%ld\n",
max_fd, timeout);
@@ -372,10 +372,10 @@ TMH_EXCHANGES_find_exchange (const char *chosen_exchange,
(GNUNET_YES == exchange->pending) )
{
exchange->conn = TALER_EXCHANGE_connect (ctx,
- exchange->uri,
- &keys_mgmt_cb,
- exchange,
- TALER_EXCHANGE_OPTION_END);
+ exchange->uri,
+ &keys_mgmt_cb,
+ exchange,
+ TALER_EXCHANGE_OPTION_END);
GNUNET_break (NULL != exchange->conn);
}
return fo;
@@ -464,10 +464,10 @@ parse_exchanges (void *cls,
exchange);
exchange->pending = GNUNET_YES;
exchange->conn = TALER_EXCHANGE_connect (ctx,
- exchange->uri,
- &keys_mgmt_cb,
- exchange,
- TALER_EXCHANGE_OPTION_END);
+ exchange->uri,
+ &keys_mgmt_cb,
+ exchange,
+ TALER_EXCHANGE_OPTION_END);
GNUNET_break (NULL != exchange->conn);
}
@@ -485,7 +485,7 @@ TMH_EXCHANGES_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
struct Exchange *exchange;
json_t *j_exchange;
- ctx = TALER_EXCHANGE_init ();
+ ctx = GNUNET_CURL_init ();
if (NULL == ctx)
{
GNUNET_break (0);
@@ -536,5 +536,6 @@ TMH_EXCHANGES_done ()
GNUNET_SCHEDULER_cancel (poller_task);
poller_task = NULL;
}
- TALER_EXCHANGE_fini (ctx);
+ GNUNET_CURL_fini (ctx);
+ ctx = NULL;
}
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
@@ -22,84 +22,9 @@
#define _TALER_MERCHANT_SERVICE_H
#include <taler/taler_util.h>
+#include <gnunet/gnunet_curl_lib.h>
#include <jansson.h>
-/* ********************* event loop *********************** */
-
-/**
- * @brief Handle to this library context. This is where the
- * main event loop logic lives.
- */
-struct TALER_MERCHANT_Context;
-
-
-/**
- * Initialise a context. A context should be used for each thread and should
- * not be shared among multiple threads.
- *
- * @return the context, NULL on error (failure to initialize)
- */
-struct TALER_MERCHANT_Context *
-TALER_MERCHANT_init (void);
-
-
-/**
- * Obtain the information for a select() call to wait until
- * #TALER_MERCHANT_perform() is ready again. Note that calling
- * any other TALER_MERCHANT-API may also imply that the library
- * is again ready for #TALER_MERCHANT_perform().
- *
- * Basically, a client should use this API to prepare for select(),
- * then block on select(), then call #TALER_MERCHANT_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_MERCHANT_perform().
- */
-void
-TALER_MERCHANT_get_select_info (struct TALER_MERCHANT_Context *ctx,
- fd_set *read_fd_set,
- fd_set *write_fd_set,
- fd_set *except_fd_set,
- int *max_fd,
- long *timeout);
-
-
-/**
- * Run the main event loop for the Taler interaction.
- *
- * @param ctx the library context
- */
-void
-TALER_MERCHANT_perform (struct TALER_MERCHANT_Context *ctx);
-
-
-/**
- * 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_MERCHANT_fini (struct TALER_MERCHANT_Context *ctx);
-
-
/* ********************* /pay *********************** */
@@ -132,7 +57,7 @@ typedef void
(*TALER_MERCHANT_PayCallback) (void *cls,
unsigned int http_status,
const char *redirect_uri,
- json_t *obj);
+ const json_t *obj);
/**
@@ -171,7 +96,7 @@ struct TALER_MERCHANT_PayCoin
/**
* Pay a merchant. API for wallets that have the coin's private keys.
*
- * @param merchant the merchant context
+ * @param ctx execution context
* @param merchant_uri URI of the merchant
* @param h_wire hash of the merchant’s account details
* @param h_contract hash of the contact of the merchant with the customer
@@ -191,7 +116,7 @@ struct TALER_MERCHANT_PayCoin
* @return a handle for this request
*/
struct TALER_MERCHANT_Pay *
-TALER_MERCHANT_pay_wallet (struct TALER_MERCHANT_Context *merchant,
+TALER_MERCHANT_pay_wallet (struct GNUNET_CURL_Context *ctx,
const char *merchant_uri,
const struct GNUNET_HashCode *h_contract,
uint64_t transaction_id,
@@ -254,7 +179,7 @@ struct TALER_MERCHANT_PaidCoin
* the public keys and signatures. Note the sublte difference
* in the type of @a coins compared to #TALER_MERCHANT_pay().
*
- * @param merchant the merchant context
+ * @param ctx execution context
* @param merchant_uri URI of the merchant
* @param h_contract hash of the contact of the merchant with the customer
* @param amount total value of the contract to be paid to the merchant
@@ -275,7 +200,7 @@ struct TALER_MERCHANT_PaidCoin
* @return a handle for this request
*/
struct TALER_MERCHANT_Pay *
-TALER_MERCHANT_pay_frontend (struct TALER_MERCHANT_Context *merchant,
+TALER_MERCHANT_pay_frontend (struct GNUNET_CURL_Context *ctx,
const char *merchant_uri,
const struct GNUNET_HashCode *h_contract,
const struct TALER_Amount *amount,
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
@@ -14,12 +14,12 @@ libtalermerchant_la_LDFLAGS = \
-no-undefined
libtalermerchant_la_SOURCES = \
- merchant_api_context.c merchant_api_context.h \
merchant_api_pay.c
libtalermerchant_la_LIBADD = \
-ltalerjson \
-ltalerutil \
+ -lgnunetcurl \
-lgnunetjson \
-lgnunetutil \
-ljansson \
@@ -45,7 +45,9 @@ test_merchant_api_LDADD = \
libtalermerchant.la \
$(LIBGCRYPT_LIBS) \
-ltalerexchange \
+ -ltalerjson \
-ltalerutil \
+ -lgnunetcurl \
-lgnunetutil \
-ljansson
diff --git a/src/lib/merchant_api_pay.c b/src/lib/merchant_api_pay.c
@@ -24,9 +24,9 @@
#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_merchant_service.h"
#include <taler/taler_json_lib.h>
-#include "merchant_api_context.h"
#include <taler/taler_signatures.h>
@@ -49,7 +49,7 @@ struct TALER_MERCHANT_Pay
/**
* Handle for the request.
*/
- struct MAC_Job *job;
+ struct GNUNET_CURL_Job *job;
/**
* Function to call with the result.
@@ -62,14 +62,9 @@ struct TALER_MERCHANT_Pay
void *cb_cls;
/**
- * Download buffer
+ * Reference to the execution context.
*/
- struct MAC_DownloadBuffer db;
-
- /**
- * Reference to the merchant.
- */
- struct TALER_MERCHANT_Context *merchant;
+ struct GNUNET_CURL_Context *ctx;
};
@@ -79,21 +74,17 @@ struct TALER_MERCHANT_Pay
* HTTP /pay request.
*
* @param cls the `struct TALER_MERCHANT_Pay`
- * @param eh the curl request handle
+ * @param response_code HTTP response code, 0 on error
+ * @param json response body, NULL if not in JSON
*/
static void
handle_pay_finished (void *cls,
- CURL *eh)
+ long response_code,
+ const json_t *json)
{
- /* FIXME: this function is not yet implemented!!! */
struct TALER_MERCHANT_Pay *ph = cls;
- long response_code;
- json_t *json;
ph->job = NULL;
- json = MAC_download_get_result (&ph->db,
- eh,
- &response_code);
switch (response_code)
{
case 0:
@@ -132,7 +123,6 @@ handle_pay_finished (void *cls,
response_code,
"FIXME-redirect-URI",
json);
- json_decref (json);
TALER_MERCHANT_pay_cancel (ph);
}
@@ -140,7 +130,7 @@ handle_pay_finished (void *cls,
/**
* Pay a merchant. API for wallets that have the coin's private keys.
*
- * @param merchant the merchant context
+ * @param ctx the execution loop context
* @param exchange_uri URI of the exchange that the coins belong to
* @param h_wire hash of the merchant’s account details
* @param h_contract hash of the contact of the merchant with the customer
@@ -158,7 +148,7 @@ handle_pay_finished (void *cls,
* @return a handle for this request
*/
struct TALER_MERCHANT_Pay *
-TALER_MERCHANT_pay_wallet (struct TALER_MERCHANT_Context *merchant,
+TALER_MERCHANT_pay_wallet (struct GNUNET_CURL_Context *ctx,
const char *merchant_uri,
const struct GNUNET_HashCode *h_contract,
uint64_t transaction_id,
@@ -219,7 +209,7 @@ TALER_MERCHANT_pay_wallet (struct TALER_MERCHANT_Context *merchant,
p->amount_with_fee = coin->amount_with_fee;
p->amount_without_fee = coin->amount_without_fee;
}
- return TALER_MERCHANT_pay_frontend (merchant,
+ return TALER_MERCHANT_pay_frontend (ctx,
merchant_uri,
h_contract,
amount,
@@ -245,7 +235,7 @@ TALER_MERCHANT_pay_wallet (struct TALER_MERCHANT_Context *merchant,
* the public keys and signatures. Note the sublte difference
* in the type of @a coins compared to #TALER_MERCHANT_pay().
*
- * @param merchant the merchant context
+ * @param ctx the execution loop context
* @param exchange_uri URI of the exchange that the coins belong to
* @param h_wire hash of the merchant’s account details
* @param h_contract hash of the contact of the merchant with the customer
@@ -264,7 +254,7 @@ TALER_MERCHANT_pay_wallet (struct TALER_MERCHANT_Context *merchant,
* @return a handle for this request
*/
struct TALER_MERCHANT_Pay *
-TALER_MERCHANT_pay_frontend (struct TALER_MERCHANT_Context *merchant,
+TALER_MERCHANT_pay_frontend (struct GNUNET_CURL_Context *ctx,
const char *merchant_uri,
const struct GNUNET_HashCode *h_contract,
const struct TALER_Amount *amount,
@@ -430,7 +420,7 @@ TALER_MERCHANT_pay_frontend (struct TALER_MERCHANT_Context *merchant,
}
ph = GNUNET_new (struct TALER_MERCHANT_Pay);
- ph->merchant = merchant;
+ ph->ctx = ctx;
ph->cb = pay_cb;
ph->cb_cls = pay_cb_cls;
ph->url = GNUNET_strdup (merchant_uri);
@@ -452,19 +442,11 @@ TALER_MERCHANT_pay_frontend (struct TALER_MERCHANT_Context *merchant,
curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE,
strlen (ph->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,
- &ph->db));
- ph->job = MAC_job_add (merchant,
- eh,
- GNUNET_YES,
- &handle_pay_finished,
- ph);
+ ph->job = GNUNET_CURL_job_add (ctx,
+ eh,
+ GNUNET_YES,
+ &handle_pay_finished,
+ ph);
return ph;
}
@@ -480,10 +462,9 @@ TALER_MERCHANT_pay_cancel (struct TALER_MERCHANT_Pay *pay)
{
if (NULL != pay->job)
{
- MAC_job_cancel (pay->job);
+ GNUNET_CURL_job_cancel (pay->job);
pay->job = NULL;
}
- GNUNET_free_non_null (pay->db.buf);
GNUNET_free (pay->url);
GNUNET_free (pay->json_enc);
GNUNET_free (pay);
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
@@ -22,8 +22,10 @@
#include <taler/taler_util.h>
#include <taler/taler_signatures.h>
#include <taler/taler_exchange_service.h>
+#include <taler/taler_json_lib.h>
#include "taler_merchant_service.h"
#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
#include <microhttpd.h>
/**
@@ -37,11 +39,6 @@
#define EXCHANGE_URI "http://localhost:8081/"
/**
- * Main execution context for the main loop of the exchange.
- */
-static struct TALER_EXCHANGE_Context *ctx;
-
-/**
* Handle to access the exchange.
*/
static struct TALER_EXCHANGE_Handle *exchange;
@@ -49,7 +46,7 @@ static struct TALER_EXCHANGE_Handle *exchange;
/**
* Main execution context for the main loop of the exchange.
*/
-static struct TALER_MERCHANT_Context *merchant;
+static struct GNUNET_CURL_Context *ctx;
/**
* Public key of the merchant, matches the private
@@ -398,11 +395,9 @@ struct InterpreterState
* Task that runs the context's event loop with the GNUnet scheduler.
*
* @param cls unused
- * @param tc scheduler context (unused)
*/
static void
-context_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+context_task (void *cls);
/**
@@ -466,11 +461,9 @@ find_command (const struct InterpreterState *is,
* Run the main interpreter loop that performs exchange operations.
*
* @param cls contains the `struct InterpreterState`
- * @param tc scheduler context
*/
static void
-interpreter_run (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+interpreter_run (void *cls);
/**
@@ -484,7 +477,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];
@@ -585,7 +578,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)
@@ -700,7 +693,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];
@@ -756,7 +749,7 @@ static void
pay_cb (void *cls,
unsigned int http_status,
const char *redirect_uri,
- json_t *obj)
+ const json_t *obj)
{
struct InterpreterState *is = cls;
struct Command *cmd = &is->commands[is->ip];
@@ -836,12 +829,11 @@ find_pk (const struct TALER_EXCHANGE_Keys *keys,
* Run the main interpreter loop that performs exchange operations.
*
* @param cls contains the `struct InterpreterState`
- * @param tc scheduler context
*/
static void
-interpreter_run (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+interpreter_run (void *cls)
{
+ const struct GNUNET_SCHEDULER_TaskContext *tc;
struct InterpreterState *is = cls;
struct Command *cmd = &is->commands[is->ip];
const struct Command *ref;
@@ -852,6 +844,7 @@ interpreter_run (void *cls,
json_t *wire;
is->task = NULL;
+ tc = GNUNET_SCHEDULER_get_task_context ();
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
fprintf (stderr,
@@ -915,7 +908,7 @@ interpreter_run (void *cls,
return;
}
execution_date = GNUNET_TIME_absolute_get ();
- TALER_round_abs_time (&execution_date);
+ GNUNET_TIME_round_abs (&execution_date);
cmd->details.admin_add_incoming.aih
= TALER_EXCHANGE_admin_add_incoming (exchange,
&reserve_pub,
@@ -1019,6 +1012,7 @@ interpreter_run (void *cls,
struct GNUNET_HashCode h_contract;
struct GNUNET_TIME_Absolute refund_deadline;
struct GNUNET_TIME_Absolute timestamp;
+ struct TALER_MerchantSignatureP merchant_sig;
/* get amount */
if (GNUNET_OK !=
@@ -1128,23 +1122,26 @@ interpreter_run (void *cls,
refund_deadline = GNUNET_TIME_UNIT_ZERO_ABS; /* no refunds */
else
refund_deadline = GNUNET_TIME_relative_to_absolute (cmd->details.pay.refund_deadline);
- TALER_round_abs_time (&refund_deadline);
+ GNUNET_TIME_round_abs (&refund_deadline);
timestamp = GNUNET_TIME_absolute_get ();
- TALER_round_abs_time (×tamp);
+ GNUNET_TIME_round_abs (×tamp);
+ memset (&merchant_sig, 0, sizeof (merchant_sig)); // FIXME: init properly!
+
cmd->details.pay.ph
- = TALER_MERCHANT_pay_wallet (merchant,
+ = TALER_MERCHANT_pay_wallet (ctx,
MERCHANT_URI "pay",
- EXCHANGE_URI,
- &h_wire,
&h_contract,
- timestamp,
cmd->details.pay.transaction_id,
+ &amount,
+ &max_fee,
&merchant_pub,
+ &merchant_sig,
+ timestamp,
refund_deadline,
+ &h_wire,
+ EXCHANGE_URI,
1 /* num_coins */,
&pc /* coins */,
- &max_fee,
- &amount,
&pay_cb,
is);
}
@@ -1175,11 +1172,9 @@ interpreter_run (void *cls,
* Cleans up our state.
*
* @param cls the interpreter state.
- * @param tc unused
*/
static void
-do_shutdown (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls)
{
struct InterpreterState *is = cls;
struct Command *cmd;
@@ -1274,14 +1269,9 @@ do_shutdown (void *cls,
TALER_EXCHANGE_disconnect (exchange);
exchange = NULL;
}
- if (NULL != merchant)
- {
- TALER_MERCHANT_fini (merchant);
- merchant = NULL;
- }
if (NULL != ctx)
{
- TALER_EXCHANGE_fini (ctx);
+ GNUNET_CURL_fini (ctx);
ctx = NULL;
}
}
@@ -1327,11 +1317,9 @@ cert_cb (void *cls,
* Task that runs the context's event loop with the GNUnet scheduler.
*
* @param cls unused
- * @param tc scheduler context (unused)
*/
static void
-context_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+context_task (void *cls)
{
long timeout;
int max_fd;
@@ -1345,25 +1333,18 @@ context_task (void *cls,
ctx_task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Event loop running\n");
- TALER_EXCHANGE_perform (ctx);
- TALER_MERCHANT_perform (merchant);
+ 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);
- TALER_MERCHANT_get_select_info (merchant,
- &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);
@@ -1392,13 +1373,9 @@ context_task (void *cls,
* Main function that will be run by the scheduler.
*
* @param cls closure
- * @param args remaining command-line arguments
- * @param cfgfile name of the configuration file used (for saving, can be NULL!)
- * @param config configuration
*/
static void
-run (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+run (void *cls)
{
struct InterpreterState *is;
static struct Command commands[] =
@@ -1482,16 +1459,14 @@ run (void *cls,
is = GNUNET_new (struct InterpreterState);
is->commands = commands;
- ctx = TALER_EXCHANGE_init ();
+ ctx = GNUNET_CURL_init ();
GNUNET_assert (NULL != ctx);
- merchant = TALER_MERCHANT_init ();
- GNUNET_assert (NULL != merchant);
ctx_task = GNUNET_SCHEDULER_add_now (&context_task,
ctx);
exchange = TALER_EXCHANGE_connect (ctx,
- EXCHANGE_URI,
- &cert_cb, is,
- TALER_EXCHANGE_OPTION_END);
+ EXCHANGE_URI,
+ &cert_cb, is,
+ TALER_EXCHANGE_OPTION_END);
GNUNET_assert (NULL != exchange);
shutdown_task
= GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply