fix memory leak and style issues
This commit is contained in:
parent
fc19601efc
commit
8843d60e68
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
This file is part of TALER
|
This file is part of TALER
|
||||||
Copyright (C) 2014-2018 Taler Systems SA
|
Copyright (C) 2014--2019 Taler Systems SA
|
||||||
|
|
||||||
TALER is free software; you can redistribute it and/or modify
|
TALER is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as
|
it under the terms of the GNU General Public License as
|
||||||
@ -29,62 +29,67 @@
|
|||||||
#include "taler_wire_lib.h"
|
#include "taler_wire_lib.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If set to GNUNET_YES, then we'll ask the bank for a list
|
* If set to #GNUNET_YES, then we'll ask the bank for a list
|
||||||
* of transactions from the account mentioned in the config
|
* of transactions from the account mentioned in the config
|
||||||
* section.
|
* section.
|
||||||
*/
|
*/
|
||||||
int history;
|
static int history;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If set to GNUNET_YES, then we'll ask the bank to execute a
|
* If set to GNUNET_YES, then we'll ask the bank to execute a
|
||||||
* wire transfer.
|
* wire transfer.
|
||||||
*/
|
*/
|
||||||
int transfer;
|
static int transfer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the wire plugin to use with the bank.
|
* Name of the wire plugin to use with the bank.
|
||||||
*/
|
*/
|
||||||
char *plugin_name;
|
static char *plugin_name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global return code.
|
* Global return code.
|
||||||
*/
|
*/
|
||||||
unsigned int global_ret = 1;
|
static unsigned int global_ret = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When a wire transfer is being performed, this value
|
* When a wire transfer is being performed, this value
|
||||||
* specifies the amount to wire-transfer. It's given in
|
* specifies the amount to wire-transfer. It's given in
|
||||||
* the usual CURRENCY:X[.Y] format.
|
* the usual CURRENCY:X[.Y] format.
|
||||||
*/
|
*/
|
||||||
char *amount;
|
static char *amount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base32 encoding of a transaction ID. When asking the
|
* Base32 encoding of a transaction ID. When asking the
|
||||||
* bank for a transaction history, all the results will
|
* bank for a transaction history, all the results will
|
||||||
* have a transaction ID settled *after* this one.
|
* have a transaction ID settled *after* this one.
|
||||||
*/
|
*/
|
||||||
char *since_when;
|
static char *since_when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Which config section has the credentials to access the bank.
|
* Which config section has the credentials to access the bank.
|
||||||
*/
|
*/
|
||||||
char *account_section;
|
static char *account_section;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL identifying the account that is going to receive the
|
* URL identifying the account that is going to receive the
|
||||||
* wire transfer.
|
* wire transfer.
|
||||||
*/
|
*/
|
||||||
char *destination_account_url;
|
static char *destination_account_url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle for the wire transfer preparation task.
|
* Handle for the wire transfer preparation task.
|
||||||
*/
|
*/
|
||||||
struct TALER_WIRE_PrepareHandle *ph;
|
static struct TALER_WIRE_PrepareHandle *ph;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wire plugin handle.
|
* Wire plugin handle.
|
||||||
*/
|
*/
|
||||||
struct TALER_WIRE_Plugin *plugin_handle;
|
static struct TALER_WIRE_Plugin *plugin_handle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle to ongoing history operation.
|
||||||
|
*/
|
||||||
|
static struct TALER_WIRE_HistoryHandle *hh;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -274,15 +279,14 @@ execute_history ()
|
|||||||
bin_len));
|
bin_len));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == plugin_handle->get_history
|
if (NULL == (hh = plugin_handle->get_history (plugin_handle->cls,
|
||||||
(plugin_handle->cls,
|
account_section,
|
||||||
account_section,
|
TALER_BANK_DIRECTION_BOTH,
|
||||||
TALER_BANK_DIRECTION_BOTH,
|
since_when_bin,
|
||||||
since_when_bin,
|
bin_len,
|
||||||
bin_len,
|
-10,
|
||||||
-10,
|
&history_cb,
|
||||||
history_cb,
|
NULL)))
|
||||||
NULL))
|
|
||||||
{
|
{
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"Could not request the transaction history.\n");
|
"Could not request the transaction history.\n");
|
||||||
@ -297,9 +301,21 @@ execute_history ()
|
|||||||
*
|
*
|
||||||
* @param cls closure.
|
* @param cls closure.
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
do_shutdown (void *cls)
|
do_shutdown (void *cls)
|
||||||
{
|
{
|
||||||
|
if (NULL != hh)
|
||||||
|
{
|
||||||
|
plugin_handle->get_history_cancel (plugin_handle->cls,
|
||||||
|
hh);
|
||||||
|
hh = NULL;
|
||||||
|
}
|
||||||
|
if (NULL != ph)
|
||||||
|
{
|
||||||
|
plugin_handle->prepare_wire_transfer_cancel (plugin_handle->cls,
|
||||||
|
ph);
|
||||||
|
ph = NULL;
|
||||||
|
}
|
||||||
TALER_WIRE_plugin_unload (plugin_handle);
|
TALER_WIRE_plugin_unload (plugin_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,8 +393,7 @@ main (int argc,
|
|||||||
struct GNUNET_GETOPT_CommandLineOption options[] = {
|
struct GNUNET_GETOPT_CommandLineOption options[] = {
|
||||||
GNUNET_GETOPT_option_flag ('H',
|
GNUNET_GETOPT_option_flag ('H',
|
||||||
"history",
|
"history",
|
||||||
"Ask to get a list of 10"
|
"Ask to get a list of 10 transactions.",
|
||||||
" transactions.",
|
|
||||||
&history),
|
&history),
|
||||||
GNUNET_GETOPT_option_flag ('t',
|
GNUNET_GETOPT_option_flag ('t',
|
||||||
"transfer",
|
"transfer",
|
||||||
@ -398,9 +413,7 @@ main (int argc,
|
|||||||
GNUNET_GETOPT_option_string ('s',
|
GNUNET_GETOPT_option_string ('s',
|
||||||
"section",
|
"section",
|
||||||
"ACCOUNT-SECTION",
|
"ACCOUNT-SECTION",
|
||||||
"Which config section has the"
|
"Which config section has the credentials to access the bank. Mandatory.\n",
|
||||||
" credentials to access the"
|
|
||||||
" bank. Mandatory.\n",
|
|
||||||
&account_section),
|
&account_section),
|
||||||
GNUNET_GETOPT_option_string ('a',
|
GNUNET_GETOPT_option_string ('a',
|
||||||
"amount",
|
"amount",
|
||||||
@ -410,8 +423,7 @@ main (int argc,
|
|||||||
GNUNET_GETOPT_option_string ('d',
|
GNUNET_GETOPT_option_string ('d',
|
||||||
"destination",
|
"destination",
|
||||||
"PAYTO-URL",
|
"PAYTO-URL",
|
||||||
"Destination account for the"
|
"Destination account for the wire transfer.",
|
||||||
" wire transfer.",
|
|
||||||
&destination_account_url),
|
&destination_account_url),
|
||||||
GNUNET_GETOPT_OPTION_END
|
GNUNET_GETOPT_OPTION_END
|
||||||
};
|
};
|
||||||
|
@ -96,7 +96,8 @@ struct TALER_WIRE_TransferDetails
|
|||||||
*
|
*
|
||||||
* @param cls closure
|
* @param cls closure
|
||||||
* @param ec taler error code
|
* @param ec taler error code
|
||||||
* @param dir direction of the transfer
|
* @param dir direction of the transfer, #TALER_BANK_DIRECTION_NONE when
|
||||||
|
* the iteration is complete
|
||||||
* @param row_off identification of the position at which we are querying
|
* @param row_off identification of the position at which we are querying
|
||||||
* @param row_off_size number of bytes in @a row_off
|
* @param row_off_size number of bytes in @a row_off
|
||||||
* @param details details about the wire transfer
|
* @param details details about the wire transfer
|
||||||
@ -368,53 +369,6 @@ struct TALER_WIRE_Plugin
|
|||||||
(*reject_transfer_cancel)(void *cls,
|
(*reject_transfer_cancel)(void *cls,
|
||||||
struct TALER_WIRE_RejectHandle *rh);
|
struct TALER_WIRE_RejectHandle *rh);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ask the plugin which data is needed to register the merchant
|
|
||||||
* into the banking institution.
|
|
||||||
*
|
|
||||||
* @param enc[out] where to store the JSON formatted list of
|
|
||||||
* needed values. The merchant will use this list to
|
|
||||||
* show a HTML form to the business in order to collect that data.
|
|
||||||
* This value will have to be freed by the caller.
|
|
||||||
* @param private_person GNUNET_OK if the merchant to be registered
|
|
||||||
* has a legal status of "person", for example they are freelance
|
|
||||||
* journalists.
|
|
||||||
* @param business GNUNET_OK if the merchant has the legal status
|
|
||||||
* of "business", so to say a "ordinary" shop. Cannot be
|
|
||||||
* both private and business though.
|
|
||||||
* @return GNUNET_OK upon successful `enc' allocation and definition,
|
|
||||||
* GNUNET_NO if _no_ data is needed at all, GNUNET_SYSERR
|
|
||||||
* for all the other cases.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
(*merchant_data)(char **out,
|
|
||||||
unsigned int private_person,
|
|
||||||
unsigned int business);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send data to the banking institution in order to get the
|
|
||||||
* merchant registered.
|
|
||||||
*
|
|
||||||
* @param cls closure
|
|
||||||
* @param body subset of information to be sent to the bank.
|
|
||||||
* The plugin implementation is free to modify this value.
|
|
||||||
* @param mrcb Callback to process the outcome.
|
|
||||||
*/
|
|
||||||
struct TALER_WIRE_MerchantRegisterHandle *
|
|
||||||
(*merchant_register)(void *cls,
|
|
||||||
const char *body,
|
|
||||||
TALER_WIRE_MerchantRegisterCallback mrcb);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancel pending operation of merchant registering.
|
|
||||||
*
|
|
||||||
* @param cls closure
|
|
||||||
* @param mrh handle to the pending operation to be cancelled.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
(*merchant_register_cancel)(void *cls,
|
|
||||||
struct TALER_WIRE_MerchantRegisterHandle *mrh);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -765,7 +765,8 @@ struct TALER_WIRE_HistoryHandle
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to call with results.
|
* Function to call with results, can become NULL if the
|
||||||
|
* application cancels the iteration.
|
||||||
*/
|
*/
|
||||||
TALER_WIRE_HistoryResultCallback hres_cb;
|
TALER_WIRE_HistoryResultCallback hres_cb;
|
||||||
|
|
||||||
@ -797,6 +798,7 @@ static void
|
|||||||
taler_bank_get_history_cancel (void *cls,
|
taler_bank_get_history_cancel (void *cls,
|
||||||
struct TALER_WIRE_HistoryHandle *whh)
|
struct TALER_WIRE_HistoryHandle *whh)
|
||||||
{
|
{
|
||||||
|
(void) cls;
|
||||||
if (NULL != whh->hh)
|
if (NULL != whh->hh)
|
||||||
{
|
{
|
||||||
TALER_BANK_history_cancel (whh->hh);
|
TALER_BANK_history_cancel (whh->hh);
|
||||||
@ -893,7 +895,11 @@ bhist_cb (void *cls,
|
|||||||
GNUNET_break (NULL != whh->hh);
|
GNUNET_break (NULL != whh->hh);
|
||||||
/* Once we get the sentinel element, the handle becomes invalid. */
|
/* Once we get the sentinel element, the handle becomes invalid. */
|
||||||
if (TALER_BANK_DIRECTION_NONE == dir)
|
if (TALER_BANK_DIRECTION_NONE == dir)
|
||||||
|
{
|
||||||
whh->hh = NULL;
|
whh->hh = NULL;
|
||||||
|
taler_bank_get_history_cancel (NULL,
|
||||||
|
whh);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case MHD_HTTP_NO_CONTENT:
|
case MHD_HTTP_NO_CONTENT:
|
||||||
@ -904,6 +910,9 @@ bhist_cb (void *cls,
|
|||||||
NULL,
|
NULL,
|
||||||
0,
|
0,
|
||||||
NULL);
|
NULL);
|
||||||
|
whh->hh = NULL;
|
||||||
|
taler_bank_get_history_cancel (NULL,
|
||||||
|
whh);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||||
@ -917,6 +926,9 @@ bhist_cb (void *cls,
|
|||||||
NULL,
|
NULL,
|
||||||
0,
|
0,
|
||||||
NULL);
|
NULL);
|
||||||
|
whh->hh = NULL;
|
||||||
|
taler_bank_get_history_cancel (NULL,
|
||||||
|
whh);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
whh->hh = NULL;
|
whh->hh = NULL;
|
||||||
@ -962,6 +974,7 @@ taler_bank_get_history (void *cls,
|
|||||||
uint64_t start_row;
|
uint64_t start_row;
|
||||||
struct TALER_Account account;
|
struct TALER_Account account;
|
||||||
|
|
||||||
|
GNUNET_assert (NULL != hres_cb);
|
||||||
if (0 == num_results)
|
if (0 == num_results)
|
||||||
{
|
{
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
@ -1019,13 +1032,12 @@ taler_bank_get_history (void *cls,
|
|||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||||
"Could not parse the auth values from '%s'\n",
|
"Could not parse the auth values from '%s'\n",
|
||||||
account_section);
|
account_section);
|
||||||
|
TALER_WIRE_account_free (&account);
|
||||||
GNUNET_free (whh);
|
GNUNET_free (whh);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
whh->hres_cb = hres_cb;
|
whh->hres_cb = hres_cb;
|
||||||
whh->hres_cb_cls = hres_cb_cls;
|
whh->hres_cb_cls = hres_cb_cls;
|
||||||
|
|
||||||
whh->hh = TALER_BANK_history (tc->ctx,
|
whh->hh = TALER_BANK_history (tc->ctx,
|
||||||
account.details.x_taler_bank.bank_base_url,
|
account.details.x_taler_bank.bank_base_url,
|
||||||
&whh->auth,
|
&whh->auth,
|
||||||
@ -1040,16 +1052,16 @@ taler_bank_get_history (void *cls,
|
|||||||
if (NULL == whh->hh)
|
if (NULL == whh->hh)
|
||||||
{
|
{
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
taler_bank_get_history_cancel (NULL,
|
taler_bank_get_history_cancel (tc,
|
||||||
whh);
|
whh);
|
||||||
TALER_WIRE_account_free (&account);
|
TALER_WIRE_account_free (&account);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
TALER_WIRE_account_free (&account);
|
TALER_WIRE_account_free (&account);
|
||||||
GNUNET_assert (NULL != whh);
|
|
||||||
return whh;
|
return whh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Context for a rejection operation.
|
* Context for a rejection operation.
|
||||||
*/
|
*/
|
||||||
|
@ -107,6 +107,7 @@ static struct TALER_WireTransferIdentifierRawP wtid;
|
|||||||
static void
|
static void
|
||||||
do_shutdown (void *cls)
|
do_shutdown (void *cls)
|
||||||
{
|
{
|
||||||
|
(void) cls;
|
||||||
TALER_FAKEBANK_stop (fb);
|
TALER_FAKEBANK_stop (fb);
|
||||||
fb = NULL;
|
fb = NULL;
|
||||||
if (NULL != eh)
|
if (NULL != eh)
|
||||||
@ -186,11 +187,11 @@ history_result_cb
|
|||||||
uint64_t serialh;
|
uint64_t serialh;
|
||||||
struct TALER_Amount amount;
|
struct TALER_Amount amount;
|
||||||
|
|
||||||
hh = NULL;
|
|
||||||
if ( (TALER_BANK_DIRECTION_NONE == dir) &&
|
if ( (TALER_BANK_DIRECTION_NONE == dir) &&
|
||||||
(GNUNET_OK == global_ret) )
|
(GNUNET_OK == global_ret) )
|
||||||
{
|
{
|
||||||
GNUNET_SCHEDULER_shutdown ();
|
GNUNET_SCHEDULER_shutdown ();
|
||||||
|
hh = NULL;
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
}
|
}
|
||||||
if (sizeof (uint64_t) != row_off_size)
|
if (sizeof (uint64_t) != row_off_size)
|
||||||
@ -251,6 +252,7 @@ confirmation_cb (void *cls,
|
|||||||
const char *emsg)
|
const char *emsg)
|
||||||
{
|
{
|
||||||
uint64_t tmp;
|
uint64_t tmp;
|
||||||
|
|
||||||
eh = NULL;
|
eh = NULL;
|
||||||
if (GNUNET_OK != success)
|
if (GNUNET_OK != success)
|
||||||
{
|
{
|
||||||
@ -259,13 +261,10 @@ confirmation_cb (void *cls,
|
|||||||
GNUNET_SCHEDULER_shutdown ();
|
GNUNET_SCHEDULER_shutdown ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy (&tmp,
|
memcpy (&tmp,
|
||||||
row_id,
|
row_id,
|
||||||
row_id_size);
|
row_id_size);
|
||||||
|
|
||||||
serial_target = GNUNET_ntohll (tmp);
|
serial_target = GNUNET_ntohll (tmp);
|
||||||
|
|
||||||
hh = plugin->get_history (plugin->cls,
|
hh = plugin->get_history (plugin->cls,
|
||||||
my_account,
|
my_account,
|
||||||
TALER_BANK_DIRECTION_BOTH,
|
TALER_BANK_DIRECTION_BOTH,
|
||||||
|
Loading…
Reference in New Issue
Block a user