implementing prepare data postgres functions for #4141

This commit is contained in:
Christian Grothoff 2016-01-27 18:28:52 +01:00
parent b7215299d8
commit 649879b0b6
3 changed files with 121 additions and 41 deletions

View File

@ -1383,7 +1383,7 @@ struct TALER_MINTDB_Plugin
*
* @param cls closure
* @param session database connection
* @param type type fo the wire transfer (i.e. "sepa")
* @param type type of the wire transfer (i.e. "sepa")
* @param buf buffer with wire transfer preparation data
* @param buf_size number of bytes in @a buf
* @return #GNUNET_OK on success, #GNUNET_SYSERR on DB errors
@ -1401,21 +1401,17 @@ struct TALER_MINTDB_Plugin
*
* @param cls closure
* @param session database connection
* @param type type fo the wire transfer (i.e. "sepa")
* @param buf buffer with wire transfer preparation data
* @param buf_size number of bytes in @a buf
* @param rowid which entry to mark as finished
* @return #GNUNET_OK on success, #GNUNET_SYSERR on DB errors
*/
int
(*wire_prepare_data_mark_finished)(void *cls,
struct TALER_MINTDB_Session *session,
const char *type,
const char *buf,
size_t buf_size);
unsigned long long rowid);
/**
* Function called to iterate over unfinished wire transfer
* Function called to get an unfinished wire transfer
* preparation data. Fetches at most one item.
*
* @param cls closure
@ -1428,11 +1424,11 @@ struct TALER_MINTDB_Plugin
* #GNUNET_SYSERR on DB errors
*/
int
(*wire_prepare_data_iterate)(void *cls,
struct TALER_MINTDB_Session *session,
const char *type,
TALER_MINTDB_WirePreparationCallback cb,
void *cb_cls);
(*wire_prepare_data_get)(void *cls,
struct TALER_MINTDB_Session *session,
const char *type,
TALER_MINTDB_WirePreparationCallback cb,
void *cb_cls);
};

View File

@ -156,7 +156,7 @@ struct TALER_PQ_QueryParam
* @param x pointer to the query parameter to pass
*/
struct TALER_PQ_QueryParam
TALER_PQ_query_param_amount_nbo(const struct TALER_AmountNBO *x);
TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x);
/**
@ -168,7 +168,7 @@ TALER_PQ_query_param_amount_nbo(const struct TALER_AmountNBO *x);
* @param x pointer to the query parameter to pass
*/
struct TALER_PQ_QueryParam
TALER_PQ_query_param_amount(const struct TALER_Amount *x);
TALER_PQ_query_param_amount (const struct TALER_Amount *x);
/**
@ -178,7 +178,7 @@ TALER_PQ_query_param_amount(const struct TALER_Amount *x);
* @param x the query parameter to pass.
*/
struct TALER_PQ_QueryParam
TALER_PQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_rsa_PublicKey *x);
TALER_PQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_rsa_PublicKey *x);
/**
@ -188,7 +188,7 @@ TALER_PQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_rsa_PublicKey *x)
* @param x the query parameter to pass
*/
struct TALER_PQ_QueryParam
TALER_PQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_rsa_Signature *x);
TALER_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_rsa_Signature *x);
/**
@ -198,7 +198,7 @@ TALER_PQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_rsa_Signature *x);
* @param x pointer to the query parameter to pass
*/
struct TALER_PQ_QueryParam
TALER_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x);
TALER_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
/**
@ -208,7 +208,7 @@ TALER_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x);
* @param x pointer to the query parameter to pass
*/
struct TALER_PQ_QueryParam
TALER_PQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x);
TALER_PQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x);
/**

View File

@ -1161,8 +1161,8 @@ postgres_prepare (PGconn *db_conn)
" WHERE serial_id=$1",
1, NULL);
/* Used in #postgres_wire_prepare_data_iterate() */
PREPARE ("wire_prepare_data_iterate",
/* Used in #postgres_wire_prepare_data_get() */
PREPARE ("wire_prepare_data_get",
"SELECT"
" serial_id"
",buf"
@ -4064,7 +4064,7 @@ postgres_insert_aggregation_tracking (void *cls,
*
* @param cls closure
* @param session database connection
* @param type type fo the wire transfer (i.e. "sepa")
* @param type type of the wire transfer (i.e. "sepa")
* @param buf buffer with wire transfer preparation data
* @param buf_size number of bytes in @a buf
* @return #GNUNET_OK on success, #GNUNET_SYSERR on DB errors
@ -4076,8 +4076,24 @@ postgres_wire_prepare_data_insert (void *cls,
const char *buf,
size_t buf_size)
{
GNUNET_break (0); // not implemented
return GNUNET_SYSERR;
PGresult *result;
struct TALER_PQ_QueryParam params[] = {
TALER_PQ_query_param_fixed_size (type, strlen (type) + 1),
TALER_PQ_query_param_fixed_size (buf, buf_size),
TALER_PQ_query_param_end
};
result = TALER_PQ_exec_prepared (session->conn,
"wire_prepare_data_insert",
params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
{
BREAK_DB_ERR (result);
PQclear (result);
return GNUNET_SYSERR;
}
PQclear (result);
return GNUNET_OK;
}
@ -4086,25 +4102,38 @@ postgres_wire_prepare_data_insert (void *cls,
*
* @param cls closure
* @param session database connection
* @param type type fo the wire transfer (i.e. "sepa")
* @param buf buffer with wire transfer preparation data
* @param buf_size number of bytes in @a buf
* @param rowid which entry to mark as finished
* @return #GNUNET_OK on success, #GNUNET_SYSERR on DB errors
*/
static int
postgres_wire_prepare_data_mark_finished (void *cls,
struct TALER_MINTDB_Session *session,
const char *type,
const char *buf,
size_t buf_size)
unsigned long long rowid)
{
GNUNET_break (0); // not implemented
return GNUNET_SYSERR;
uint64_t serial_id = rowid;
struct TALER_PQ_QueryParam params[] = {
TALER_PQ_query_param_uint64 (&serial_id),
TALER_PQ_query_param_end
};
PGresult *result;
result = TALER_PQ_exec_prepared (session->conn,
"wire_prepare_data_mark_done",
params);
if (PGRES_COMMAND_OK !=
PQresultStatus (result))
{
BREAK_DB_ERR (result);
PQclear (result);
return GNUNET_SYSERR;
}
PQclear (result);
return GNUNET_OK;
}
/**
* Function called to iterate over unfinished wire transfer
* Function called to get an unfinished wire transfer
* preparation data. Fetches at most one item.
*
* @param cls closure
@ -4117,14 +4146,69 @@ postgres_wire_prepare_data_mark_finished (void *cls,
* #GNUNET_SYSERR on DB errors
*/
static int
postgres_wire_prepare_data_iterate (void *cls,
struct TALER_MINTDB_Session *session,
const char *type,
TALER_MINTDB_WirePreparationCallback cb,
void *cb_cls)
postgres_wire_prepare_data_get (void *cls,
struct TALER_MINTDB_Session *session,
const char *type,
TALER_MINTDB_WirePreparationCallback cb,
void *cb_cls)
{
GNUNET_break (0); // not implemented
return GNUNET_SYSERR;
PGresult *result;
struct TALER_PQ_QueryParam params[] = {
TALER_PQ_query_param_fixed_size (type, strlen (type) + 1),
TALER_PQ_query_param_end
};
result = TALER_PQ_exec_prepared (session->conn,
"wire_prepare_data_get",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
{
QUERY_ERR (result);
PQclear (result);
return GNUNET_SYSERR;
}
if (0 == PQntuples (result))
{
PQclear (result);
return GNUNET_NO;
}
if (1 != PQntuples (result))
{
GNUNET_break (0);
PQclear (result);
return GNUNET_SYSERR;
}
{
uint64_t serial_id;
void *buf = NULL;
size_t buf_size;
struct TALER_PQ_ResultSpec rs[] = {
TALER_PQ_result_spec_uint64 ("serial_id",
&serial_id),
TALER_PQ_result_spec_variable_size ("buf",
&buf,
&buf_size),
TALER_PQ_result_spec_end
};
if (GNUNET_OK !=
TALER_PQ_extract_result (result,
rs,
0))
{
GNUNET_break (0);
PQclear (result);
return GNUNET_SYSERR;
}
cb (cb_cls,
serial_id,
buf,
buf_size);
TALER_PQ_cleanup_result (rs);
}
PQclear (result);
return GNUNET_OK;
}
@ -4207,7 +4291,7 @@ libtaler_plugin_mintdb_postgres_init (void *cls)
plugin->insert_aggregation_tracking = &postgres_insert_aggregation_tracking;
plugin->wire_prepare_data_insert = &postgres_wire_prepare_data_insert;
plugin->wire_prepare_data_mark_finished = &postgres_wire_prepare_data_mark_finished;
plugin->wire_prepare_data_iterate = &postgres_wire_prepare_data_iterate;
plugin->wire_prepare_data_get = &postgres_wire_prepare_data_get;
return plugin;
}