move free functions into plugin
This commit is contained in:
parent
53876904c5
commit
0d3ec509d7
@ -6,6 +6,8 @@ plugindir = $(libdir)/taler
|
|||||||
plugin_LTLIBRARIES = \
|
plugin_LTLIBRARIES = \
|
||||||
libtaler_plugin_mintdb_postgres.la
|
libtaler_plugin_mintdb_postgres.la
|
||||||
|
|
||||||
|
EXTRA_DIST = plugin_mintdb_common.c
|
||||||
|
|
||||||
libtaler_plugin_mintdb_postgres_la_SOURCES = \
|
libtaler_plugin_mintdb_postgres_la_SOURCES = \
|
||||||
plugin_mintdb_postgres.c
|
plugin_mintdb_postgres.c
|
||||||
libtaler_plugin_mintdb_postgres_la_LIBADD = \
|
libtaler_plugin_mintdb_postgres_la_LIBADD = \
|
||||||
|
@ -115,69 +115,4 @@ plugin_fini ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FIXME: decide if we should keep these in each plugin, here
|
|
||||||
// or yet again somewhere else entirely (plugin_common.c?)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Free memory associated with the given reserve history.
|
|
||||||
*
|
|
||||||
* @param rh history to free.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
TALER_MINT_DB_free_reserve_history (struct ReserveHistory *rh)
|
|
||||||
{
|
|
||||||
struct BankTransfer *bt;
|
|
||||||
struct CollectableBlindcoin *cbc;
|
|
||||||
struct ReserveHistory *backref;
|
|
||||||
|
|
||||||
while (NULL != rh)
|
|
||||||
{
|
|
||||||
switch(rh->type)
|
|
||||||
{
|
|
||||||
case TALER_MINT_DB_RO_BANK_TO_MINT:
|
|
||||||
bt = rh->details.bank;
|
|
||||||
if (NULL != bt->wire)
|
|
||||||
json_decref ((json_t *) bt->wire); /* FIXME: avoid cast? */
|
|
||||||
GNUNET_free (bt);
|
|
||||||
break;
|
|
||||||
case TALER_MINT_DB_RO_WITHDRAW_COIN:
|
|
||||||
cbc = rh->details.withdraw;
|
|
||||||
GNUNET_CRYPTO_rsa_signature_free (cbc->sig);
|
|
||||||
GNUNET_CRYPTO_rsa_public_key_free (cbc->denom_pub);
|
|
||||||
GNUNET_free (cbc);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
backref = rh;
|
|
||||||
rh = rh->next;
|
|
||||||
GNUNET_free (backref);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Free memory of the link data list.
|
|
||||||
*
|
|
||||||
* @param ldl link data list to release
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
TALER_db_link_data_list_free (struct LinkDataList *ldl)
|
|
||||||
{
|
|
||||||
GNUNET_break (0); // FIXME
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Free linked list of transactions.
|
|
||||||
*
|
|
||||||
* @param list list to free
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
TALER_MINT_DB_free_coin_transaction_list (struct TALER_MINT_DB_TransactionList *list)
|
|
||||||
{
|
|
||||||
// FIXME: check logic!
|
|
||||||
GNUNET_break (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* end of plugin.c */
|
/* end of plugin.c */
|
||||||
|
@ -47,31 +47,4 @@ void
|
|||||||
TALER_MINT_plugin_unload (void);
|
TALER_MINT_plugin_unload (void);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Free memory associated with the given reserve history.
|
|
||||||
*
|
|
||||||
* @param rh history to free.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
TALER_MINT_DB_free_reserve_history (struct ReserveHistory *rh);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Free memory of the link data list.
|
|
||||||
*
|
|
||||||
* @param ldl link data list to release
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
TALER_db_link_data_list_free (struct LinkDataList *ldl);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Free linked list of transactions.
|
|
||||||
*
|
|
||||||
* @param list list to free
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
TALER_MINT_DB_free_coin_transaction_list (struct TALER_MINT_DB_TransactionList *list);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <libpq-fe.h>
|
#include <libpq-fe.h>
|
||||||
|
|
||||||
|
#include "plugin_mintdb_common.c"
|
||||||
|
|
||||||
#define TALER_TEMP_SCHEMA_NAME "taler_temporary"
|
#define TALER_TEMP_SCHEMA_NAME "taler_temporary"
|
||||||
|
|
||||||
@ -1313,7 +1314,8 @@ postgres_get_reserve_history (void *cls,
|
|||||||
PQclear (result);
|
PQclear (result);
|
||||||
if (GNUNET_SYSERR == ret)
|
if (GNUNET_SYSERR == ret)
|
||||||
{
|
{
|
||||||
TALER_MINT_DB_free_reserve_history (rh);
|
common_free_reserve_history (cls,
|
||||||
|
rh);
|
||||||
rh = NULL;
|
rh = NULL;
|
||||||
}
|
}
|
||||||
return rh;
|
return rh;
|
||||||
@ -2064,9 +2066,9 @@ postgres_insert_refresh_collectable (void *cls,
|
|||||||
* @return all known link data for the coin
|
* @return all known link data for the coin
|
||||||
*/
|
*/
|
||||||
static struct LinkDataList *
|
static struct LinkDataList *
|
||||||
postgres_get_link (void *cls,
|
postgres_get_link_data_list (void *cls,
|
||||||
struct TALER_MINTDB_Session *session,
|
struct TALER_MINTDB_Session *session,
|
||||||
const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub)
|
const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub)
|
||||||
{
|
{
|
||||||
// FIXME: check logic!
|
// FIXME: check logic!
|
||||||
struct LinkDataList *ldl;
|
struct LinkDataList *ldl;
|
||||||
@ -2116,7 +2118,8 @@ postgres_get_link (void *cls,
|
|||||||
{
|
{
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
TALER_db_link_data_list_free (ldl);
|
common_free_link_data_list (cls,
|
||||||
|
ldl);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (ld_buf_size < sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))
|
if (ld_buf_size < sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))
|
||||||
@ -2125,7 +2128,8 @@ postgres_get_link (void *cls,
|
|||||||
GNUNET_free (pk_buf);
|
GNUNET_free (pk_buf);
|
||||||
GNUNET_free (sig_buf);
|
GNUNET_free (sig_buf);
|
||||||
GNUNET_free (ld_buf);
|
GNUNET_free (ld_buf);
|
||||||
TALER_db_link_data_list_free (ldl);
|
common_free_link_data_list (cls,
|
||||||
|
ldl);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// FIXME: use util API for this!
|
// FIXME: use util API for this!
|
||||||
@ -2154,7 +2158,8 @@ postgres_get_link (void *cls,
|
|||||||
GNUNET_free (link_enc);
|
GNUNET_free (link_enc);
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
TALER_db_link_data_list_free (ldl);
|
common_free_link_data_list (cls,
|
||||||
|
ldl);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pos = GNUNET_new (struct LinkDataList);
|
pos = GNUNET_new (struct LinkDataList);
|
||||||
@ -2171,8 +2176,8 @@ postgres_get_link (void *cls,
|
|||||||
/**
|
/**
|
||||||
* Obtain shared secret and transfer public key from the public key of
|
* Obtain shared secret and transfer public key from the public key of
|
||||||
* the coin. This information and the link information returned by
|
* the coin. This information and the link information returned by
|
||||||
* #TALER_db_get_link() enable the owner of an old coin to determine
|
* #postgres_get_link_data_list() enable the owner of an old coin to
|
||||||
* the private keys of the new coins after the melt.
|
* determine the private keys of the new coins after the melt.
|
||||||
*
|
*
|
||||||
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
* @param cls the `struct PostgresClosure` with the plugin-specific state
|
||||||
* @param session database connection
|
* @param session database connection
|
||||||
@ -2304,6 +2309,7 @@ libtaler_plugin_mintdb_postgres_init (void *cls)
|
|||||||
plugin->get_collectable_blindcoin = &postgres_get_collectable_blindcoin;
|
plugin->get_collectable_blindcoin = &postgres_get_collectable_blindcoin;
|
||||||
plugin->insert_collectable_blindcoin = &postgres_insert_collectable_blindcoin;
|
plugin->insert_collectable_blindcoin = &postgres_insert_collectable_blindcoin;
|
||||||
plugin->get_reserve_history = &postgres_get_reserve_history;
|
plugin->get_reserve_history = &postgres_get_reserve_history;
|
||||||
|
plugin->free_reserve_history = &common_free_reserve_history;
|
||||||
plugin->have_deposit = &postgres_have_deposit;
|
plugin->have_deposit = &postgres_have_deposit;
|
||||||
plugin->insert_deposit = &postgres_insert_deposit;
|
plugin->insert_deposit = &postgres_insert_deposit;
|
||||||
plugin->get_refresh_session = &postgres_get_refresh_session;
|
plugin->get_refresh_session = &postgres_get_refresh_session;
|
||||||
@ -2317,11 +2323,13 @@ libtaler_plugin_mintdb_postgres_init (void *cls)
|
|||||||
plugin->insert_refresh_commit_link = &postgres_insert_refresh_commit_link;
|
plugin->insert_refresh_commit_link = &postgres_insert_refresh_commit_link;
|
||||||
plugin->get_refresh_commit_link = &postgres_get_refresh_commit_link;
|
plugin->get_refresh_commit_link = &postgres_get_refresh_commit_link;
|
||||||
plugin->insert_refresh_collectable = &postgres_insert_refresh_collectable;
|
plugin->insert_refresh_collectable = &postgres_insert_refresh_collectable;
|
||||||
plugin->get_link = &postgres_get_link;
|
plugin->get_link_data_list = &postgres_get_link_data_list;
|
||||||
|
plugin->free_link_data_list = &common_free_link_data_list;
|
||||||
plugin->get_transfer = &postgres_get_transfer;
|
plugin->get_transfer = &postgres_get_transfer;
|
||||||
// plugin->have_lock = &postgres_have_lock;
|
// plugin->have_lock = &postgres_have_lock;
|
||||||
// plugin->insert_lock = &postgres_insert_lock;
|
// plugin->insert_lock = &postgres_insert_lock;
|
||||||
plugin->get_coin_transactions = &postgres_get_coin_transactions;
|
plugin->get_coin_transactions = &postgres_get_coin_transactions;
|
||||||
|
plugin->free_coin_transaction_list = &common_free_coin_transaction_list;
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,8 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
|
|||||||
&deposit->amount))
|
&deposit->amount))
|
||||||
{
|
{
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
TALER_MINT_DB_free_coin_transaction_list (tl);
|
plugin->free_coin_transaction_list (plugin->cls,
|
||||||
|
tl);
|
||||||
return TALER_MINT_reply_internal_db_error (connection);
|
return TALER_MINT_reply_internal_db_error (connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +126,8 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
|
|||||||
&fee_deposit)) )
|
&fee_deposit)) )
|
||||||
{
|
{
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
TALER_MINT_DB_free_coin_transaction_list (tl);
|
plugin->free_coin_transaction_list (plugin->cls,
|
||||||
|
tl);
|
||||||
return TALER_MINT_reply_internal_db_error (connection);
|
return TALER_MINT_reply_internal_db_error (connection);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -140,7 +142,8 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
|
|||||||
&fee_refresh)) )
|
&fee_refresh)) )
|
||||||
{
|
{
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
TALER_MINT_DB_free_coin_transaction_list (tl);
|
plugin->free_coin_transaction_list (plugin->cls,
|
||||||
|
tl);
|
||||||
return TALER_MINT_reply_internal_db_error (connection);
|
return TALER_MINT_reply_internal_db_error (connection);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -163,10 +166,12 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
|
|||||||
session);
|
session);
|
||||||
ret = TALER_MINT_reply_deposit_insufficient_funds (connection,
|
ret = TALER_MINT_reply_deposit_insufficient_funds (connection,
|
||||||
tl);
|
tl);
|
||||||
TALER_MINT_DB_free_coin_transaction_list (tl);
|
plugin->free_coin_transaction_list (plugin->cls,
|
||||||
|
tl);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
TALER_MINT_DB_free_coin_transaction_list (tl);
|
plugin->free_coin_transaction_list (plugin->cls,
|
||||||
|
tl);
|
||||||
|
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
plugin->insert_deposit (plugin->cls,
|
plugin->insert_deposit (plugin->cls,
|
||||||
@ -228,7 +233,8 @@ TALER_MINT_db_execute_withdraw_status (struct MHD_Connection *connection,
|
|||||||
"error", "Reserve not found");
|
"error", "Reserve not found");
|
||||||
res = TALER_MINT_reply_withdraw_status_success (connection,
|
res = TALER_MINT_reply_withdraw_status_success (connection,
|
||||||
rh);
|
rh);
|
||||||
TALER_MINT_DB_free_reserve_history (rh);
|
plugin->free_reserve_history (plugin->cls,
|
||||||
|
rh);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,10 +420,12 @@ TALER_MINT_db_execute_withdraw_sign (struct MHD_Connection *connection,
|
|||||||
session);
|
session);
|
||||||
res = TALER_MINT_reply_withdraw_sign_insufficient_funds (connection,
|
res = TALER_MINT_reply_withdraw_sign_insufficient_funds (connection,
|
||||||
rh);
|
rh);
|
||||||
TALER_MINT_DB_free_reserve_history (rh);
|
plugin->free_reserve_history (plugin->cls,
|
||||||
|
rh);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
TALER_MINT_DB_free_reserve_history (rh);
|
plugin->free_reserve_history (plugin->cls,
|
||||||
|
rh);
|
||||||
|
|
||||||
/* Balance is good, sign the coin! */
|
/* Balance is good, sign the coin! */
|
||||||
sig = GNUNET_CRYPTO_rsa_sign (dki->denom_priv,
|
sig = GNUNET_CRYPTO_rsa_sign (dki->denom_priv,
|
||||||
@ -532,10 +540,12 @@ refresh_accept_melts (struct MHD_Connection *connection,
|
|||||||
coin_details->melt_amount,
|
coin_details->melt_amount,
|
||||||
coin_residual))
|
coin_residual))
|
||||||
? GNUNET_NO : GNUNET_SYSERR;
|
? GNUNET_NO : GNUNET_SYSERR;
|
||||||
TALER_MINT_DB_free_coin_transaction_list (tl);
|
plugin->free_coin_transaction_list (plugin->cls,
|
||||||
|
tl);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
TALER_MINT_DB_free_coin_transaction_list (tl);
|
plugin->free_coin_transaction_list (plugin->cls,
|
||||||
|
tl);
|
||||||
|
|
||||||
melt.coin = *coin_public_info;
|
melt.coin = *coin_public_info;
|
||||||
melt.coin_sig = coin_details->melt_sig;
|
melt.coin_sig = coin_details->melt_sig;
|
||||||
@ -1242,9 +1252,9 @@ TALER_MINT_db_execute_refresh_link (struct MHD_Connection *connection,
|
|||||||
}
|
}
|
||||||
GNUNET_assert (GNUNET_OK == res);
|
GNUNET_assert (GNUNET_OK == res);
|
||||||
|
|
||||||
ldl = plugin->get_link (plugin->cls,
|
ldl = plugin->get_link_data_list (plugin->cls,
|
||||||
session,
|
session,
|
||||||
coin_pub);
|
coin_pub);
|
||||||
if (NULL == ldl)
|
if (NULL == ldl)
|
||||||
{
|
{
|
||||||
return TALER_MINT_reply_json_pack (connection,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
@ -1257,7 +1267,8 @@ TALER_MINT_db_execute_refresh_link (struct MHD_Connection *connection,
|
|||||||
&transfer_pub,
|
&transfer_pub,
|
||||||
&shared_secret_enc,
|
&shared_secret_enc,
|
||||||
ldl);
|
ldl);
|
||||||
TALER_db_link_data_list_free (ldl);
|
plugin->free_link_data_list (plugin->cls,
|
||||||
|
ldl);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,6 +658,17 @@ struct TALER_MINTDB_Plugin
|
|||||||
const struct GNUNET_CRYPTO_EddsaPublicKey *reserve_pub);
|
const struct GNUNET_CRYPTO_EddsaPublicKey *reserve_pub);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free memory associated with the given reserve history.
|
||||||
|
*
|
||||||
|
* @param cls the @e cls of this struct with the plugin-specific state
|
||||||
|
* @param rh history to free.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
(*free_reserve_history) (void *cls,
|
||||||
|
struct ReserveHistory *rh);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if we have the specified deposit already in the database.
|
* Check if we have the specified deposit already in the database.
|
||||||
*
|
*
|
||||||
@ -922,9 +933,20 @@ struct TALER_MINTDB_Plugin
|
|||||||
* @return all known link data for the coin
|
* @return all known link data for the coin
|
||||||
*/
|
*/
|
||||||
struct LinkDataList *
|
struct LinkDataList *
|
||||||
(*get_link) (void *cls,
|
(*get_link_data_list) (void *cls,
|
||||||
struct TALER_MINTDB_Session *db_conn,
|
struct TALER_MINTDB_Session *db_conn,
|
||||||
const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub);
|
const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free memory of the link data list.
|
||||||
|
*
|
||||||
|
* @param cls the @e cls of this struct with the plugin-specific state
|
||||||
|
* @param ldl link data list to release
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
(*free_link_data_list) (void *cls,
|
||||||
|
struct LinkDataList *ldl);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -996,6 +1018,18 @@ struct TALER_MINTDB_Plugin
|
|||||||
struct TALER_MINTDB_Session *db_conn,
|
struct TALER_MINTDB_Session *db_conn,
|
||||||
const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub);
|
const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free linked list of transactions.
|
||||||
|
*
|
||||||
|
* @param cls the @e cls of this struct with the plugin-specific state
|
||||||
|
* @param list list to free
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
(*free_coin_transaction_list) (void *cls,
|
||||||
|
struct TALER_MINT_DB_TransactionList *list);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user