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

View File

@ -2095,36 +2095,62 @@ 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;
PGresult *result;
for (i=0;i<(unsigned int) num_newcoins;i++)
{ {
struct TALER_PQ_QueryParam params[] = { uint16_t newcoin_off = (uint16_t) i;
TALER_PQ_query_param_uint16 (&num_newcoins), PGresult *result;
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_end struct TALER_PQ_QueryParam params[] = {
}; TALER_PQ_query_param_uint16 (&newcoin_off),
result = TALER_PQ_exec_prepared (session->conn, TALER_PQ_query_param_auto_from_type (session_hash),
"insert_refresh_order", TALER_PQ_query_param_rsa_public_key (denom_pubs->rsa_public_key),
params); TALER_PQ_query_param_end
} };
if (PGRES_COMMAND_OK != PQresultStatus (result)) result = TALER_PQ_exec_prepared (session->conn,
{ "insert_refresh_order",
BREAK_DB_ERR (result); params);
}
if (PGRES_COMMAND_OK != PQresultStatus (result))
{
BREAK_DB_ERR (result);
PQclear (result);
return GNUNET_SYSERR;
}
if (0 != strcmp ("1", PQcmdTuples (result)))
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
PQclear (result); PQclear (result);
return GNUNET_SYSERR;
} }
if (0 != strcmp ("1", PQcmdTuples (result)))
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
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;
struct TALER_PQ_QueryParam params[] = {
TALER_PQ_query_param_auto_from_type (session_hash),
TALER_PQ_query_param_uint16 (&num_newcoins),
TALER_PQ_query_param_end
};
PGresult *result = TALER_PQ_exec_prepared (session->conn, for (i=0;i<(unsigned int) num_newcoins;i++)
"get_refresh_order", params); {
uint16_t newcoin_off = (uint16_t) i;
PGresult *result;
if (PGRES_TUPLES_OK != PQresultStatus (result)) {
{ struct TALER_PQ_QueryParam params[] = {
BREAK_DB_ERR (result); TALER_PQ_query_param_auto_from_type (session_hash),
PQclear (result); TALER_PQ_query_param_uint16 (&newcoin_off),
return GNUNET_SYSERR; TALER_PQ_query_param_end
} };
if (0 == PQntuples (result)) result = TALER_PQ_exec_prepared (session->conn,
{ "get_refresh_order",
PQclear (result); params);
/* FIXME: may want to distinguish between different error cases! */ }
return GNUNET_SYSERR; if (PGRES_TUPLES_OK != PQresultStatus (result))
{
BREAK_DB_ERR (result);
PQclear (result);
free_dpk_result (denom_pubs, i);
return GNUNET_SYSERR;
}
if (0 == PQntuples (result))
{
PQclear (result);
/* FIXME: may want to distinguish between different error cases! */
free_dpk_result (denom_pubs, i);
return GNUNET_SYSERR;
}
GNUNET_assert (1 == PQntuples (result));
{
struct TALER_PQ_ResultSpec rs[] = {
TALER_PQ_result_spec_rsa_public_key ("denom_pub",
&denom_pubs[i].rsa_public_key),
TALER_PQ_result_spec_end
};
if (GNUNET_OK !=
TALER_PQ_extract_result (result, rs, 0))
{
PQclear (result);
GNUNET_break (0);
free_dpk_result (denom_pubs, i);
return GNUNET_SYSERR;
}
PQclear (result);
}
} }
GNUNET_assert (1 == PQntuples (result));
struct TALER_PQ_ResultSpec rs[] = {
TALER_PQ_result_spec_rsa_public_key ("denom_pub", &denom_pubs->rsa_public_key),
TALER_PQ_result_spec_end
};
if (GNUNET_OK != TALER_PQ_extract_result (result, rs, 0))
{
PQclear (result);
GNUNET_break (0);
return GNUNET_SYSERR;
}
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.