From 0d3ec509d7192e973123de1ab390826fff4df230 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 22 Mar 2015 13:02:11 +0100 Subject: move free functions into plugin --- src/mint/Makefile.am | 2 ++ src/mint/plugin.c | 65 --------------------------------------- src/mint/plugin.h | 27 ---------------- src/mint/plugin_mintdb_postgres.c | 28 +++++++++++------ src/mint/taler-mint-httpd_db.c | 39 ++++++++++++++--------- src/mint/taler_mintdb_plugin.h | 40 ++++++++++++++++++++++-- 6 files changed, 82 insertions(+), 119 deletions(-) (limited to 'src/mint') 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 #include +#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 @@ -658,6 +658,17 @@ struct TALER_MINTDB_Plugin 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. * @@ -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); + + }; -- cgit v1.2.3