aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-03-22 13:02:11 +0100
committerChristian Grothoff <christian@grothoff.org>2015-03-22 13:02:11 +0100
commit0d3ec509d7192e973123de1ab390826fff4df230 (patch)
tree30a5b91bc255c0f164a52bd17a9b42aa9ecee8c4
parent53876904c590aa9b1e7bd48395cb049f109adbd4 (diff)
move free functions into plugin
-rw-r--r--src/mint/Makefile.am2
-rw-r--r--src/mint/plugin.c65
-rw-r--r--src/mint/plugin.h27
-rw-r--r--src/mint/plugin_mintdb_postgres.c28
-rw-r--r--src/mint/taler-mint-httpd_db.c39
-rw-r--r--src/mint/taler_mintdb_plugin.h40
6 files changed, 82 insertions, 119 deletions
diff --git a/src/mint/Makefile.am b/src/mint/Makefile.am
index c4f99af63..1eba7d61d 100644
--- a/src/mint/Makefile.am
+++ b/src/mint/Makefile.am
@@ -6,6 +6,8 @@ plugindir = $(libdir)/taler
plugin_LTLIBRARIES = \
libtaler_plugin_mintdb_postgres.la
+EXTRA_DIST = plugin_mintdb_common.c
+
libtaler_plugin_mintdb_postgres_la_SOURCES = \
plugin_mintdb_postgres.c
libtaler_plugin_mintdb_postgres_la_LIBADD = \
diff --git a/src/mint/plugin.c b/src/mint/plugin.c
index 67cabd815..4fb75f87a 100644
--- a/src/mint/plugin.c
+++ b/src/mint/plugin.c
@@ -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 */
diff --git a/src/mint/plugin.h b/src/mint/plugin.h
index bb1f0ecbc..0dfb866da 100644
--- a/src/mint/plugin.h
+++ b/src/mint/plugin.h
@@ -47,31 +47,4 @@ 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
diff --git a/src/mint/plugin_mintdb_postgres.c b/src/mint/plugin_mintdb_postgres.c
index c49ea1399..adc85251c 100644
--- a/src/mint/plugin_mintdb_postgres.c
+++ b/src/mint/plugin_mintdb_postgres.c
@@ -28,6 +28,7 @@
#include <pthread.h>
#include <libpq-fe.h>
+#include "plugin_mintdb_common.c"
#define TALER_TEMP_SCHEMA_NAME "taler_temporary"
@@ -1313,7 +1314,8 @@ postgres_get_reserve_history (void *cls,
PQclear (result);
if (GNUNET_SYSERR == ret)
{
- TALER_MINT_DB_free_reserve_history (rh);
+ common_free_reserve_history (cls,
+ rh);
rh = NULL;
}
return rh;
@@ -2064,9 +2066,9 @@ postgres_insert_refresh_collectable (void *cls,
* @return all known link data for the coin
*/
static struct LinkDataList *
-postgres_get_link (void *cls,
- struct TALER_MINTDB_Session *session,
- const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub)
+postgres_get_link_data_list (void *cls,
+ struct TALER_MINTDB_Session *session,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub)
{
// FIXME: check logic!
struct LinkDataList *ldl;
@@ -2116,7 +2118,8 @@ postgres_get_link (void *cls,
{
PQclear (result);
GNUNET_break (0);
- TALER_db_link_data_list_free (ldl);
+ common_free_link_data_list (cls,
+ ldl);
return NULL;
}
if (ld_buf_size < sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))
@@ -2125,7 +2128,8 @@ postgres_get_link (void *cls,
GNUNET_free (pk_buf);
GNUNET_free (sig_buf);
GNUNET_free (ld_buf);
- TALER_db_link_data_list_free (ldl);
+ common_free_link_data_list (cls,
+ ldl);
return NULL;
}
// FIXME: use util API for this!
@@ -2154,7 +2158,8 @@ postgres_get_link (void *cls,
GNUNET_free (link_enc);
GNUNET_break (0);
PQclear (result);
- TALER_db_link_data_list_free (ldl);
+ common_free_link_data_list (cls,
+ ldl);
return NULL;
}
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
* the coin. This information and the link information returned by
- * #TALER_db_get_link() enable the owner of an old coin to determine
- * the private keys of the new coins after the melt.
+ * #postgres_get_link_data_list() enable the owner of an old coin to
+ * determine the private keys of the new coins after the melt.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
* @param session database connection
@@ -2304,6 +2309,7 @@ libtaler_plugin_mintdb_postgres_init (void *cls)
plugin->get_collectable_blindcoin = &postgres_get_collectable_blindcoin;
plugin->insert_collectable_blindcoin = &postgres_insert_collectable_blindcoin;
plugin->get_reserve_history = &postgres_get_reserve_history;
+ plugin->free_reserve_history = &common_free_reserve_history;
plugin->have_deposit = &postgres_have_deposit;
plugin->insert_deposit = &postgres_insert_deposit;
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->get_refresh_commit_link = &postgres_get_refresh_commit_link;
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->have_lock = &postgres_have_lock;
// plugin->insert_lock = &postgres_insert_lock;
plugin->get_coin_transactions = &postgres_get_coin_transactions;
+ plugin->free_coin_transaction_list = &common_free_coin_transaction_list;
return plugin;
}
diff --git a/src/mint/taler-mint-httpd_db.c b/src/mint/taler-mint-httpd_db.c
index 292ef68fa..35c6dfb95 100644
--- a/src/mint/taler-mint-httpd_db.c
+++ b/src/mint/taler-mint-httpd_db.c
@@ -106,7 +106,8 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
&deposit->amount))
{
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);
}
@@ -125,7 +126,8 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
&fee_deposit)) )
{
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);
}
break;
@@ -140,7 +142,8 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
&fee_refresh)) )
{
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);
}
break;
@@ -163,10 +166,12 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
session);
ret = TALER_MINT_reply_deposit_insufficient_funds (connection,
tl);
- TALER_MINT_DB_free_coin_transaction_list (tl);
+ plugin->free_coin_transaction_list (plugin->cls,
+ tl);
return ret;
}
- TALER_MINT_DB_free_coin_transaction_list (tl);
+ plugin->free_coin_transaction_list (plugin->cls,
+ tl);
if (GNUNET_OK !=
plugin->insert_deposit (plugin->cls,
@@ -228,7 +233,8 @@ TALER_MINT_db_execute_withdraw_status (struct MHD_Connection *connection,
"error", "Reserve not found");
res = TALER_MINT_reply_withdraw_status_success (connection,
rh);
- TALER_MINT_DB_free_reserve_history (rh);
+ plugin->free_reserve_history (plugin->cls,
+ rh);
return res;
}
@@ -414,10 +420,12 @@ TALER_MINT_db_execute_withdraw_sign (struct MHD_Connection *connection,
session);
res = TALER_MINT_reply_withdraw_sign_insufficient_funds (connection,
rh);
- TALER_MINT_DB_free_reserve_history (rh);
+ plugin->free_reserve_history (plugin->cls,
+ rh);
return res;
}
- TALER_MINT_DB_free_reserve_history (rh);
+ plugin->free_reserve_history (plugin->cls,
+ rh);
/* Balance is good, sign the coin! */
sig = GNUNET_CRYPTO_rsa_sign (dki->denom_priv,
@@ -532,10 +540,12 @@ refresh_accept_melts (struct MHD_Connection *connection,
coin_details->melt_amount,
coin_residual))
? GNUNET_NO : GNUNET_SYSERR;
- TALER_MINT_DB_free_coin_transaction_list (tl);
+ plugin->free_coin_transaction_list (plugin->cls,
+ tl);
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_sig = coin_details->melt_sig;
@@ -1242,9 +1252,9 @@ TALER_MINT_db_execute_refresh_link (struct MHD_Connection *connection,
}
GNUNET_assert (GNUNET_OK == res);
- ldl = plugin->get_link (plugin->cls,
- session,
- coin_pub);
+ ldl = plugin->get_link_data_list (plugin->cls,
+ session,
+ coin_pub);
if (NULL == ldl)
{
return TALER_MINT_reply_json_pack (connection,
@@ -1257,7 +1267,8 @@ TALER_MINT_db_execute_refresh_link (struct MHD_Connection *connection,
&transfer_pub,
&shared_secret_enc,
ldl);
- TALER_db_link_data_list_free (ldl);
+ plugin->free_link_data_list (plugin->cls,
+ ldl);
return res;
}
diff --git a/src/mint/taler_mintdb_plugin.h b/src/mint/taler_mintdb_plugin.h
index d330b817b..eabb00d9a 100644
--- a/src/mint/taler_mintdb_plugin.h
+++ b/src/mint/taler_mintdb_plugin.h
@@ -659,6 +659,17 @@ struct TALER_MINTDB_Plugin
/**
+ * 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.
*
* @param cls the @e cls of this struct with the plugin-specific state
@@ -922,9 +933,20 @@ struct TALER_MINTDB_Plugin
* @return all known link data for the coin
*/
struct LinkDataList *
- (*get_link) (void *cls,
- struct TALER_MINTDB_Session *db_conn,
- const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub);
+ (*get_link_data_list) (void *cls,
+ struct TALER_MINTDB_Session *db_conn,
+ 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,
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);
+
+
};