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

View File

@ -156,7 +156,7 @@ struct TALER_PQ_QueryParam
* @param x pointer to the query parameter to pass * @param x pointer to the query parameter to pass
*/ */
struct TALER_PQ_QueryParam 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 * @param x pointer to the query parameter to pass
*/ */
struct TALER_PQ_QueryParam 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. * @param x the query parameter to pass.
*/ */
struct TALER_PQ_QueryParam 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 * @param x the query parameter to pass
*/ */
struct TALER_PQ_QueryParam 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 * @param x pointer to the query parameter to pass
*/ */
struct TALER_PQ_QueryParam 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 * @param x pointer to the query parameter to pass
*/ */
struct TALER_PQ_QueryParam 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", " WHERE serial_id=$1",
1, NULL); 1, NULL);
/* Used in #postgres_wire_prepare_data_iterate() */ /* Used in #postgres_wire_prepare_data_get() */
PREPARE ("wire_prepare_data_iterate", PREPARE ("wire_prepare_data_get",
"SELECT" "SELECT"
" serial_id" " serial_id"
",buf" ",buf"
@ -4064,7 +4064,7 @@ postgres_insert_aggregation_tracking (void *cls,
* *
* @param cls closure * @param cls closure
* @param session database connection * @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 buffer with wire transfer preparation data
* @param buf_size number of bytes in @a buf * @param buf_size number of bytes in @a buf
* @return #GNUNET_OK on success, #GNUNET_SYSERR on DB errors * @return #GNUNET_OK on success, #GNUNET_SYSERR on DB errors
@ -4076,8 +4076,24 @@ postgres_wire_prepare_data_insert (void *cls,
const char *buf, const char *buf,
size_t buf_size) size_t buf_size)
{ {
GNUNET_break (0); // not implemented PGresult *result;
return GNUNET_SYSERR; 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 cls closure
* @param session database connection * @param session database connection
* @param type type fo the wire transfer (i.e. "sepa") * @param rowid which entry to mark as finished
* @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 * @return #GNUNET_OK on success, #GNUNET_SYSERR on DB errors
*/ */
static int static int
postgres_wire_prepare_data_mark_finished (void *cls, postgres_wire_prepare_data_mark_finished (void *cls,
struct TALER_MINTDB_Session *session, struct TALER_MINTDB_Session *session,
const char *type, unsigned long long rowid)
const char *buf,
size_t buf_size)
{ {
GNUNET_break (0); // not implemented uint64_t serial_id = rowid;
return GNUNET_SYSERR; 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. * preparation data. Fetches at most one item.
* *
* @param cls closure * @param cls closure
@ -4117,14 +4146,69 @@ postgres_wire_prepare_data_mark_finished (void *cls,
* #GNUNET_SYSERR on DB errors * #GNUNET_SYSERR on DB errors
*/ */
static int static int
postgres_wire_prepare_data_iterate (void *cls, postgres_wire_prepare_data_get (void *cls,
struct TALER_MINTDB_Session *session, struct TALER_MINTDB_Session *session,
const char *type, const char *type,
TALER_MINTDB_WirePreparationCallback cb, TALER_MINTDB_WirePreparationCallback cb,
void *cb_cls) void *cb_cls)
{ {
GNUNET_break (0); // not implemented PGresult *result;
return GNUNET_SYSERR; 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->insert_aggregation_tracking = &postgres_insert_aggregation_tracking;
plugin->wire_prepare_data_insert = &postgres_wire_prepare_data_insert; 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_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; return plugin;
} }