This commit is contained in:
Christian Grothoff 2015-06-11 14:46:03 +02:00
parent 65c19ccbdb
commit eedfc04850

View File

@ -2095,12 +2095,16 @@ postgres_insert_refresh_order (void *cls,
uint16_t num_newcoins, uint16_t num_newcoins,
const struct TALER_DenominationPublicKey *denom_pubs) const struct TALER_DenominationPublicKey *denom_pubs)
{ {
// FIXME: check logic: was written for just one COIN! (#3830) unsigned int i;
for (i=0;i<(unsigned int) num_newcoins;i++)
{
uint16_t newcoin_off = (uint16_t) i;
PGresult *result; PGresult *result;
{ {
struct TALER_PQ_QueryParam params[] = { struct TALER_PQ_QueryParam params[] = {
TALER_PQ_query_param_uint16 (&num_newcoins), TALER_PQ_query_param_uint16 (&newcoin_off),
TALER_PQ_query_param_auto_from_type (session_hash), TALER_PQ_query_param_auto_from_type (session_hash),
TALER_PQ_query_param_rsa_public_key (denom_pubs->rsa_public_key), TALER_PQ_query_param_rsa_public_key (denom_pubs->rsa_public_key),
TALER_PQ_query_param_end TALER_PQ_query_param_end
@ -2121,10 +2125,32 @@ postgres_insert_refresh_order (void *cls,
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
PQclear (result); PQclear (result);
}
return GNUNET_OK; return GNUNET_OK;
} }
/**
* We allocated some @a denom_pubs information, but now need
* to abort. Free allocated memory.
*
* @param denom_pubs data to free (but not the array itself)
* @param denom_pubs_len length of @a denom_pubs array
*/
static void
free_dpk_result (struct TALER_DenominationPublicKey *denom_pubs,
unsigned int denom_pubs_len)
{
unsigned int i;
for (i=0;i<denom_pubs_len;i++)
{
GNUNET_CRYPTO_rsa_public_key_free (denom_pubs[i].rsa_public_key);
denom_pubs[i].rsa_public_key = NULL;
}
}
/** /**
* Lookup in the database the coins that we want to * Lookup in the database the coins that we want to
* create in the given refresh operation. * create in the given refresh operation.
@ -2144,46 +2170,60 @@ postgres_get_refresh_order (void *cls,
uint16_t num_newcoins, uint16_t num_newcoins,
struct TALER_DenominationPublicKey *denom_pubs) struct TALER_DenominationPublicKey *denom_pubs)
{ {
// FIXME: check logic -- was written for just one coin! (#3830) unsigned int i;
for (i=0;i<(unsigned int) num_newcoins;i++)
{
uint16_t newcoin_off = (uint16_t) i;
PGresult *result;
{
struct TALER_PQ_QueryParam params[] = { struct TALER_PQ_QueryParam params[] = {
TALER_PQ_query_param_auto_from_type (session_hash), TALER_PQ_query_param_auto_from_type (session_hash),
TALER_PQ_query_param_uint16 (&num_newcoins), TALER_PQ_query_param_uint16 (&newcoin_off),
TALER_PQ_query_param_end TALER_PQ_query_param_end
}; };
PGresult *result = TALER_PQ_exec_prepared (session->conn, result = TALER_PQ_exec_prepared (session->conn,
"get_refresh_order", params); "get_refresh_order",
params);
}
if (PGRES_TUPLES_OK != PQresultStatus (result)) if (PGRES_TUPLES_OK != PQresultStatus (result))
{ {
BREAK_DB_ERR (result); BREAK_DB_ERR (result);
PQclear (result); PQclear (result);
free_dpk_result (denom_pubs, i);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (0 == PQntuples (result)) if (0 == PQntuples (result))
{ {
PQclear (result); PQclear (result);
/* FIXME: may want to distinguish between different error cases! */ /* FIXME: may want to distinguish between different error cases! */
free_dpk_result (denom_pubs, i);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
GNUNET_assert (1 == PQntuples (result)); GNUNET_assert (1 == PQntuples (result));
{
struct TALER_PQ_ResultSpec rs[] = { struct TALER_PQ_ResultSpec rs[] = {
TALER_PQ_result_spec_rsa_public_key ("denom_pub", &denom_pubs->rsa_public_key), TALER_PQ_result_spec_rsa_public_key ("denom_pub",
&denom_pubs[i].rsa_public_key),
TALER_PQ_result_spec_end TALER_PQ_result_spec_end
}; };
if (GNUNET_OK != TALER_PQ_extract_result (result, rs, 0)) if (GNUNET_OK !=
TALER_PQ_extract_result (result, rs, 0))
{ {
PQclear (result); PQclear (result);
GNUNET_break (0); GNUNET_break (0);
free_dpk_result (denom_pubs, i);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
PQclear (result); PQclear (result);
}
}
return GNUNET_OK; return GNUNET_OK;
} }
/** /**
* Store information about the commitment of the * Store information about the commitment of the
* given coin for the given refresh session in the database. * given coin for the given refresh session in the database.