summaryrefslogtreecommitdiff
path: root/src/pq
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/pq
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/pq')
-rw-r--r--src/pq/pq.c122
-rw-r--r--src/pq/pq_connect.c72
-rw-r--r--src/pq/pq_eval.c267
-rw-r--r--src/pq/pq_exec.c60
-rw-r--r--src/pq/pq_prepare.c58
-rw-r--r--src/pq/pq_query_helper.c220
-rw-r--r--src/pq/pq_result_helper.c714
-rw-r--r--src/pq/test_pq.c354
8 files changed, 935 insertions, 932 deletions
diff --git a/src/pq/pq.c b/src/pq/pq.c
index a581b4277..7e97c8f72 100644
--- a/src/pq/pq.c
+++ b/src/pq/pq.c
@@ -38,17 +38,17 @@
* @return postgres result
*/
PGresult *
-GNUNET_PQ_exec_prepared(PGconn *db_conn,
- const char *name,
- const struct GNUNET_PQ_QueryParam *params)
+GNUNET_PQ_exec_prepared (PGconn *db_conn,
+ const char *name,
+ const struct GNUNET_PQ_QueryParam *params)
{
unsigned int len;
unsigned int i;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Running prepared statement `%s' on %p\n",
- name,
- db_conn);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Running prepared statement `%s' on %p\n",
+ name,
+ db_conn);
/* count the number of parameters */
len = 0;
for (i = 0; 0 != params[i].num_params; i++)
@@ -71,41 +71,41 @@ GNUNET_PQ_exec_prepared(PGconn *db_conn,
off = 0;
soff = 0;
for (i = 0; 0 != params[i].num_params; i++)
+ {
+ const struct GNUNET_PQ_QueryParam *x = &params[i];
+
+ ret = x->conv (x->conv_cls,
+ x->data,
+ x->size,
+ &param_values[off],
+ &param_lengths[off],
+ &param_formats[off],
+ x->num_params,
+ &scratch[soff],
+ len - soff);
+ if (ret < 0)
{
- const struct GNUNET_PQ_QueryParam *x = &params[i];
-
- ret = x->conv(x->conv_cls,
- x->data,
- x->size,
- &param_values[off],
- &param_lengths[off],
- &param_formats[off],
- x->num_params,
- &scratch[soff],
- len - soff);
- if (ret < 0)
- {
- for (off = 0; off < soff; off++)
- GNUNET_free(scratch[off]);
- return NULL;
- }
- soff += ret;
- off += x->num_params;
+ for (off = 0; off < soff; off++)
+ GNUNET_free (scratch[off]);
+ return NULL;
}
- GNUNET_assert(off == len);
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,
- "pq",
- "Executing prepared SQL statement `%s'\n",
- name);
- res = PQexecPrepared(db_conn,
- name,
- len,
- (const char **)param_values,
- param_lengths,
- param_formats,
- 1);
+ soff += ret;
+ off += x->num_params;
+ }
+ GNUNET_assert (off == len);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "pq",
+ "Executing prepared SQL statement `%s'\n",
+ name);
+ res = PQexecPrepared (db_conn,
+ name,
+ len,
+ (const char **) param_values,
+ param_lengths,
+ param_formats,
+ 1);
for (off = 0; off < soff; off++)
- GNUNET_free(scratch[off]);
+ GNUNET_free (scratch[off]);
return res;
}
}
@@ -118,14 +118,14 @@ GNUNET_PQ_exec_prepared(PGconn *db_conn,
* @param rs reult specification to clean up
*/
void
-GNUNET_PQ_cleanup_result(struct GNUNET_PQ_ResultSpec *rs)
+GNUNET_PQ_cleanup_result (struct GNUNET_PQ_ResultSpec *rs)
{
unsigned int i;
for (i = 0; NULL != rs[i].conv; i++)
if (NULL != rs[i].cleaner)
- rs[i].cleaner(rs[i].cls,
- rs[i].dst);
+ rs[i].cleaner (rs[i].cls,
+ rs[i].dst);
}
@@ -141,32 +141,32 @@ GNUNET_PQ_cleanup_result(struct GNUNET_PQ_ResultSpec *rs)
* #GNUNET_SYSERR if a result was invalid (non-existing field)
*/
int
-GNUNET_PQ_extract_result(PGresult *result,
- struct GNUNET_PQ_ResultSpec *rs,
- int row)
+GNUNET_PQ_extract_result (PGresult *result,
+ struct GNUNET_PQ_ResultSpec *rs,
+ int row)
{
unsigned int i;
int ret;
for (i = 0; NULL != rs[i].conv; i++)
+ {
+ struct GNUNET_PQ_ResultSpec *spec;
+
+ spec = &rs[i];
+ ret = spec->conv (spec->cls,
+ result,
+ row,
+ spec->fname,
+ &spec->dst_size,
+ spec->dst);
+ if (GNUNET_OK != ret)
{
- struct GNUNET_PQ_ResultSpec *spec;
-
- spec = &rs[i];
- ret = spec->conv(spec->cls,
- result,
- row,
- spec->fname,
- &spec->dst_size,
- spec->dst);
- if (GNUNET_OK != ret)
- {
- GNUNET_PQ_cleanup_result(rs);
- return GNUNET_SYSERR;
- }
- if (NULL != spec->result_size)
- *spec->result_size = spec->dst_size;
+ GNUNET_PQ_cleanup_result (rs);
+ return GNUNET_SYSERR;
}
+ if (NULL != spec->result_size)
+ *spec->result_size = spec->dst_size;
+ }
return GNUNET_OK;
}
diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c
index 2ab049724..79b9d6107 100644
--- a/src/pq/pq_connect.c
+++ b/src/pq/pq_connect.c
@@ -36,8 +36,8 @@
* @param res information about some libpq event
*/
static void
-pq_notice_receiver_cb(void *arg,
- const PGresult *res)
+pq_notice_receiver_cb (void *arg,
+ const PGresult *res)
{
/* do nothing, intentionally */
}
@@ -51,13 +51,13 @@ pq_notice_receiver_cb(void *arg,
* @param message information about some libpq event
*/
static void
-pq_notice_processor_cb(void *arg,
- const char *message)
+pq_notice_processor_cb (void *arg,
+ const char *message)
{
- GNUNET_log_from(GNUNET_ERROR_TYPE_INFO,
- "pq",
- "%s",
- message);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
+ "pq",
+ "%s",
+ message);
}
@@ -70,32 +70,32 @@ pq_notice_processor_cb(void *arg,
* @return NULL on error
*/
PGconn *
-GNUNET_PQ_connect(const char *config_str)
+GNUNET_PQ_connect (const char *config_str)
{
PGconn *conn;
- conn = PQconnectdb(config_str);
+ conn = PQconnectdb (config_str);
if ((NULL == conn) ||
(CONNECTION_OK !=
- PQstatus(conn)))
- {
- GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR,
- "pq",
- "Database connection to '%s' failed: %s\n",
- config_str,
- (NULL != conn) ?
- PQerrorMessage(conn)
- : "PQconnectdb returned NULL");
- if (NULL != conn)
- PQfinish(conn);
- return NULL;
- }
- PQsetNoticeReceiver(conn,
- &pq_notice_receiver_cb,
- conn);
- PQsetNoticeProcessor(conn,
- &pq_notice_processor_cb,
+ PQstatus (conn)))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "pq",
+ "Database connection to '%s' failed: %s\n",
+ config_str,
+ (NULL != conn) ?
+ PQerrorMessage (conn)
+ : "PQconnectdb returned NULL");
+ if (NULL != conn)
+ PQfinish (conn);
+ return NULL;
+ }
+ PQsetNoticeReceiver (conn,
+ &pq_notice_receiver_cb,
conn);
+ PQsetNoticeProcessor (conn,
+ &pq_notice_processor_cb,
+ conn);
return conn;
}
@@ -109,21 +109,21 @@ GNUNET_PQ_connect(const char *config_str)
* @return the postgres handle, NULL on error
*/
PGconn *
-GNUNET_PQ_connect_with_cfg(const struct GNUNET_CONFIGURATION_Handle * cfg,
- const char *section)
+GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section)
{
PGconn *dbh;
char *conninfo;
/* Open database and precompile statements */
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string(cfg,
- section,
- "CONFIG",
- &conninfo))
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ section,
+ "CONFIG",
+ &conninfo))
conninfo = NULL;
- dbh = GNUNET_PQ_connect(conninfo == NULL ? "" : conninfo);
- GNUNET_free_non_null(conninfo);
+ dbh = GNUNET_PQ_connect (conninfo == NULL ? "" : conninfo);
+ GNUNET_free_non_null (conninfo);
return dbh;
}
diff --git a/src/pq/pq_eval.c b/src/pq/pq_eval.c
index 0df71e672..1d041f226 100644
--- a/src/pq/pq_eval.c
+++ b/src/pq/pq_eval.c
@@ -57,76 +57,76 @@
* @deprecated (low level, let's see if we can do with just the high-level functions)
*/
enum GNUNET_DB_QueryStatus
-GNUNET_PQ_eval_result(PGconn *connection,
- const char *statement_name,
- PGresult *result)
+GNUNET_PQ_eval_result (PGconn *connection,
+ const char *statement_name,
+ PGresult *result)
{
ExecStatusType est;
- est = PQresultStatus(result);
+ est = PQresultStatus (result);
if ((PGRES_COMMAND_OK != est) &&
(PGRES_TUPLES_OK != est))
- {
- const char *sqlstate;
+ {
+ const char *sqlstate;
- sqlstate = PQresultErrorField(result,
- PG_DIAG_SQLSTATE);
- if (NULL == sqlstate)
- {
- /* very unexpected... */
- GNUNET_break(0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if ((0 == strcmp(sqlstate,
- PQ_DIAG_SQLSTATE_DEADLOCK)) ||
- (0 == strcmp(sqlstate,
- PQ_DIAG_SQLSTATE_SERIALIZATION_FAILURE)))
- {
- /* These two can be retried and have a fair chance of working
- the next time */
- GNUNET_log_from(GNUNET_ERROR_TYPE_INFO,
- "pq",
- "Query `%s' failed with result: %s/%s/%s/%s/%s\n",
- statement_name,
- PQresultErrorField(result,
- PG_DIAG_MESSAGE_PRIMARY),
- PQresultErrorField(result,
- PG_DIAG_MESSAGE_DETAIL),
- PQresultErrorMessage(result),
- PQresStatus(PQresultStatus(result)),
- PQerrorMessage(connection));
- return GNUNET_DB_STATUS_SOFT_ERROR;
- }
- if (0 == strcmp(sqlstate,
- PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION))
- {
- /* Likely no need to retry, INSERT of "same" data. */
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,
- "pq",
- "Query `%s' failed with unique violation: %s/%s/%s/%s/%s\n",
- statement_name,
- PQresultErrorField(result,
- PG_DIAG_MESSAGE_PRIMARY),
- PQresultErrorField(result,
- PG_DIAG_MESSAGE_DETAIL),
- PQresultErrorMessage(result),
- PQresStatus(PQresultStatus(result)),
- PQerrorMessage(connection));
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- }
- GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR,
- "pq",
- "Query `%s' failed with result: %s/%s/%s/%s/%s\n",
- statement_name,
- PQresultErrorField(result,
- PG_DIAG_MESSAGE_PRIMARY),
- PQresultErrorField(result,
- PG_DIAG_MESSAGE_DETAIL),
- PQresultErrorMessage(result),
- PQresStatus(PQresultStatus(result)),
- PQerrorMessage(connection));
+ sqlstate = PQresultErrorField (result,
+ PG_DIAG_SQLSTATE);
+ if (NULL == sqlstate)
+ {
+ /* very unexpected... */
+ GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR;
}
+ if ((0 == strcmp (sqlstate,
+ PQ_DIAG_SQLSTATE_DEADLOCK)) ||
+ (0 == strcmp (sqlstate,
+ PQ_DIAG_SQLSTATE_SERIALIZATION_FAILURE)))
+ {
+ /* These two can be retried and have a fair chance of working
+ the next time */
+ GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
+ "pq",
+ "Query `%s' failed with result: %s/%s/%s/%s/%s\n",
+ statement_name,
+ PQresultErrorField (result,
+ PG_DIAG_MESSAGE_PRIMARY),
+ PQresultErrorField (result,
+ PG_DIAG_MESSAGE_DETAIL),
+ PQresultErrorMessage (result),
+ PQresStatus (PQresultStatus (result)),
+ PQerrorMessage (connection));
+ return GNUNET_DB_STATUS_SOFT_ERROR;
+ }
+ if (0 == strcmp (sqlstate,
+ PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION))
+ {
+ /* Likely no need to retry, INSERT of "same" data. */
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "pq",
+ "Query `%s' failed with unique violation: %s/%s/%s/%s/%s\n",
+ statement_name,
+ PQresultErrorField (result,
+ PG_DIAG_MESSAGE_PRIMARY),
+ PQresultErrorField (result,
+ PG_DIAG_MESSAGE_DETAIL),
+ PQresultErrorMessage (result),
+ PQresStatus (PQresultStatus (result)),
+ PQerrorMessage (connection));
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "pq",
+ "Query `%s' failed with result: %s/%s/%s/%s/%s\n",
+ statement_name,
+ PQresultErrorField (result,
+ PG_DIAG_MESSAGE_PRIMARY),
+ PQresultErrorField (result,
+ PG_DIAG_MESSAGE_DETAIL),
+ PQresultErrorMessage (result),
+ PQresStatus (PQresultStatus (result)),
+ PQerrorMessage (connection));
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
}
@@ -148,29 +148,29 @@ GNUNET_PQ_eval_result(PGconn *connection,
* zero; if INSERT was successful, we return one.
*/
enum GNUNET_DB_QueryStatus
-GNUNET_PQ_eval_prepared_non_select(PGconn *connection,
- const char *statement_name,
- const struct GNUNET_PQ_QueryParam *params)
+GNUNET_PQ_eval_prepared_non_select (PGconn *connection,
+ const char *statement_name,
+ const struct GNUNET_PQ_QueryParam *params)
{
PGresult *result;
enum GNUNET_DB_QueryStatus qs;
- result = GNUNET_PQ_exec_prepared(connection,
- statement_name,
- params);
- qs = GNUNET_PQ_eval_result(connection,
- statement_name,
- result);
+ result = GNUNET_PQ_exec_prepared (connection,
+ statement_name,
+ params);
+ qs = GNUNET_PQ_eval_result (connection,
+ statement_name,
+ result);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
- {
- const char *tuples;
+ {
+ const char *tuples;
- /* What an awful API, this function really does return a string */
- tuples = PQcmdTuples(result);
- if (NULL != tuples)
- qs = strtol(tuples, NULL, 10);
- }
- PQclear(result);
+ /* What an awful API, this function really does return a string */
+ tuples = PQcmdTuples (result);
+ if (NULL != tuples)
+ qs = strtol (tuples, NULL, 10);
+ }
+ PQclear (result);
return qs;
}
@@ -191,33 +191,33 @@ GNUNET_PQ_eval_prepared_non_select(PGconn *connection,
* codes to `enum GNUNET_DB_QueryStatus`.
*/
enum GNUNET_DB_QueryStatus
-GNUNET_PQ_eval_prepared_multi_select(PGconn *connection,
- const char *statement_name,
- const struct GNUNET_PQ_QueryParam *params,
- GNUNET_PQ_PostgresResultHandler rh,
- void *rh_cls)
+GNUNET_PQ_eval_prepared_multi_select (PGconn *connection,
+ const char *statement_name,
+ const struct GNUNET_PQ_QueryParam *params,
+ GNUNET_PQ_PostgresResultHandler rh,
+ void *rh_cls)
{
PGresult *result;
enum GNUNET_DB_QueryStatus qs;
unsigned int ret;
- result = GNUNET_PQ_exec_prepared(connection,
- statement_name,
- params);
- qs = GNUNET_PQ_eval_result(connection,
- statement_name,
- result);
+ result = GNUNET_PQ_exec_prepared (connection,
+ statement_name,
+ params);
+ qs = GNUNET_PQ_eval_result (connection,
+ statement_name,
+ result);
if (qs < 0)
- {
- PQclear(result);
- return qs;
- }
- ret = PQntuples(result);
+ {
+ PQclear (result);
+ return qs;
+ }
+ ret = PQntuples (result);
if (NULL != rh)
- rh(rh_cls,
- result,
- ret);
- PQclear(result);
+ rh (rh_cls,
+ result,
+ ret);
+ PQclear (result);
return ret;
}
@@ -238,46 +238,47 @@ GNUNET_PQ_eval_prepared_multi_select(PGconn *connection,
* codes to `enum GNUNET_DB_QueryStatus`.
*/
enum GNUNET_DB_QueryStatus
-GNUNET_PQ_eval_prepared_singleton_select(PGconn *connection,
- const char *statement_name,
- const struct GNUNET_PQ_QueryParam *params,
- struct GNUNET_PQ_ResultSpec *rs)
+GNUNET_PQ_eval_prepared_singleton_select (PGconn *connection,
+ const char *statement_name,
+ const struct
+ GNUNET_PQ_QueryParam *params,
+ struct GNUNET_PQ_ResultSpec *rs)
{
PGresult *result;
enum GNUNET_DB_QueryStatus qs;
- result = GNUNET_PQ_exec_prepared(connection,
- statement_name,
- params);
- qs = GNUNET_PQ_eval_result(connection,
- statement_name,
- result);
+ result = GNUNET_PQ_exec_prepared (connection,
+ statement_name,
+ params);
+ qs = GNUNET_PQ_eval_result (connection,
+ statement_name,
+ result);
if (qs < 0)
- {
- PQclear(result);
- return qs;
- }
- if (0 == PQntuples(result))
- {
- PQclear(result);
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- }
- if (1 != PQntuples(result))
- {
- /* more than one result, but there must be at most one */
- GNUNET_break(0);
- PQclear(result);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
+ {
+ PQclear (result);
+ return qs;
+ }
+ if (0 == PQntuples (result))
+ {
+ PQclear (result);
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ if (1 != PQntuples (result))
+ {
+ /* more than one result, but there must be at most one */
+ GNUNET_break (0);
+ PQclear (result);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
if (GNUNET_OK !=
- GNUNET_PQ_extract_result(result,
- rs,
- 0))
- {
- PQclear(result);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- PQclear(result);
+ GNUNET_PQ_extract_result (result,
+ rs,
+ 0))
+ {
+ PQclear (result);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ PQclear (result);
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
}
diff --git a/src/pq/pq_exec.c b/src/pq/pq_exec.c
index 6c8002aff..00527151a 100644
--- a/src/pq/pq_exec.c
+++ b/src/pq/pq_exec.c
@@ -34,7 +34,7 @@
* @return initialized struct
*/
struct GNUNET_PQ_ExecuteStatement
-GNUNET_PQ_make_execute(const char *sql)
+GNUNET_PQ_make_execute (const char *sql)
{
struct GNUNET_PQ_ExecuteStatement es = {
.sql = sql,
@@ -53,7 +53,7 @@ GNUNET_PQ_make_execute(const char *sql)
* @return initialized struct
*/
struct GNUNET_PQ_ExecuteStatement
-GNUNET_PQ_make_try_execute(const char *sql)
+GNUNET_PQ_make_try_execute (const char *sql)
{
struct GNUNET_PQ_ExecuteStatement es = {
.sql = sql,
@@ -74,38 +74,38 @@ GNUNET_PQ_make_try_execute(const char *sql)
* #GNUNET_SYSERR on error
*/
int
-GNUNET_PQ_exec_statements(PGconn *connection,
- const struct GNUNET_PQ_ExecuteStatement *es)
+GNUNET_PQ_exec_statements (PGconn *connection,
+ const struct GNUNET_PQ_ExecuteStatement *es)
{
for (unsigned int i = 0; NULL != es[i].sql; i++)
- {
- PGresult *result;
+ {
+ PGresult *result;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Running statement `%s' on %p\n",
- es[i].sql,
- connection);
- result = PQexec(connection,
- es[i].sql);
- if ((GNUNET_NO == es[i].ignore_errors) &&
- (PGRES_COMMAND_OK != PQresultStatus(result)))
- {
- GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR,
- "pq",
- "Failed to execute `%s': %s/%s/%s/%s/%s",
- es[i].sql,
- PQresultErrorField(result,
- PG_DIAG_MESSAGE_PRIMARY),
- PQresultErrorField(result,
- PG_DIAG_MESSAGE_DETAIL),
- PQresultErrorMessage(result),
- PQresStatus(PQresultStatus(result)),
- PQerrorMessage(connection));
- PQclear(result);
- return GNUNET_SYSERR;
- }
- PQclear(result);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Running statement `%s' on %p\n",
+ es[i].sql,
+ connection);
+ result = PQexec (connection,
+ es[i].sql);
+ if ((GNUNET_NO == es[i].ignore_errors) &&
+ (PGRES_COMMAND_OK != PQresultStatus (result)))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "pq",
+ "Failed to execute `%s': %s/%s/%s/%s/%s",
+ es[i].sql,
+ PQresultErrorField (result,
+ PG_DIAG_MESSAGE_PRIMARY),
+ PQresultErrorField (result,
+ PG_DIAG_MESSAGE_DETAIL),
+ PQresultErrorMessage (result),
+ PQresStatus (PQresultStatus (result)),
+ PQerrorMessage (connection));
+ PQclear (result);
+ return GNUNET_SYSERR;
}
+ PQclear (result);
+ }
return GNUNET_OK;
}
diff --git a/src/pq/pq_prepare.c b/src/pq/pq_prepare.c
index 9899b65bb..0facf100f 100644
--- a/src/pq/pq_prepare.c
+++ b/src/pq/pq_prepare.c
@@ -36,9 +36,9 @@
* @return initialized struct
*/
struct GNUNET_PQ_PreparedStatement
-GNUNET_PQ_make_prepare(const char *name,
- const char *sql,
- unsigned int num_args)
+GNUNET_PQ_make_prepare (const char *name,
+ const char *sql,
+ unsigned int num_args)
{
struct GNUNET_PQ_PreparedStatement ps = {
.name = name,
@@ -60,36 +60,36 @@ GNUNET_PQ_make_prepare(const char *name,
* #GNUNET_SYSERR on error
*/
int
-GNUNET_PQ_prepare_statements(PGconn *connection,
- const struct GNUNET_PQ_PreparedStatement *ps)
+GNUNET_PQ_prepare_statements (PGconn *connection,
+ const struct GNUNET_PQ_PreparedStatement *ps)
{
for (unsigned int i = 0; NULL != ps[i].name; i++)
- {
- PGresult *ret;
+ {
+ PGresult *ret;
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,
- "pq",
- "Preparing SQL statement `%s' as `%s'\n",
- ps[i].sql,
- ps[i].name);
- ret = PQprepare(connection,
- ps[i].name,
- ps[i].sql,
- ps[i].num_arguments,
- NULL);
- if (PGRES_COMMAND_OK != PQresultStatus(ret))
- {
- GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "pq",
- _("PQprepare (`%s' as `%s') failed with error: %s\n"),
- ps[i].sql,
- ps[i].name,
- PQerrorMessage(connection));
- PQclear(ret);
- return GNUNET_SYSERR;
- }
- PQclear(ret);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "pq",
+ "Preparing SQL statement `%s' as `%s'\n",
+ ps[i].sql,
+ ps[i].name);
+ ret = PQprepare (connection,
+ ps[i].name,
+ ps[i].sql,
+ ps[i].num_arguments,
+ NULL);
+ if (PGRES_COMMAND_OK != PQresultStatus (ret))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "pq",
+ _ ("PQprepare (`%s' as `%s') failed with error: %s\n"),
+ ps[i].sql,
+ ps[i].name,
+ PQerrorMessage (connection));
+ PQclear (ret);
+ return GNUNET_SYSERR;
}
+ PQclear (ret);
+ }
return GNUNET_OK;
}
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index c3b86ee3d..3bc84082d 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -42,22 +42,22 @@
* @return -1 on error, number of offsets used in @a scratch otherwise
*/
static int
-qconv_fixed(void *cls,
- const void *data,
- size_t data_len,
- void *param_values[],
- int param_lengths[],
- int param_formats[],
- unsigned int param_length,
- void *scratch[],
- unsigned int scratch_length)
+qconv_fixed (void *cls,
+ const void *data,
+ size_t data_len,
+ void *param_values[],
+ int param_lengths[],
+ int param_formats[],
+ unsigned int param_length,
+ void *scratch[],
+ unsigned int scratch_length)
{
- (void)scratch;
- (void)scratch_length;
- GNUNET_break(NULL == cls);
+ (void) scratch;
+ (void) scratch_length;
+ GNUNET_break (NULL == cls);
if (1 != param_length)
return -1;
- param_values[0] = (void *)data;
+ param_values[0] = (void *) data;
param_lengths[0] = data_len;
param_formats[0] = 1;
return 0;
@@ -72,8 +72,8 @@ qconv_fixed(void *cls,
* @oaran ptr_size number of bytes in @a ptr
*/
struct GNUNET_PQ_QueryParam
-GNUNET_PQ_query_param_fixed_size(const void *ptr,
- size_t ptr_size)
+GNUNET_PQ_query_param_fixed_size (const void *ptr,
+ size_t ptr_size)
{
struct GNUNET_PQ_QueryParam res =
{ &qconv_fixed, NULL, ptr, ptr_size, 1 };
@@ -88,9 +88,9 @@ GNUNET_PQ_query_param_fixed_size(const void *ptr,
* @param ptr pointer to the string query parameter to pass
*/
struct GNUNET_PQ_QueryParam
-GNUNET_PQ_query_param_string(const char *ptr)
+GNUNET_PQ_query_param_string (const char *ptr)
{
- return GNUNET_PQ_query_param_fixed_size(ptr, strlen(ptr));
+ return GNUNET_PQ_query_param_fixed_size (ptr, strlen (ptr));
}
@@ -109,28 +109,28 @@ GNUNET_PQ_query_param_string(const char *ptr)
* @return -1 on error, number of offsets used in @a scratch otherwise
*/
static int
-qconv_uint16(void *cls,
- const void *data,
- size_t data_len,
- void *param_values[],
- int param_lengths[],
- int param_formats[],
- unsigned int param_length,
- void *scratch[],
- unsigned int scratch_length)
+qconv_uint16 (void *cls,
+ const void *data,
+ size_t data_len,
+ void *param_values[],
+ int param_lengths[],
+ int param_formats[],
+ unsigned int param_length,
+ void *scratch[],
+ unsigned int scratch_length)
{
const uint16_t *u_hbo = data;
uint16_t *u_nbo;
- (void)scratch;
- (void)scratch_length;
- GNUNET_break(NULL == cls);
+ (void) scratch;
+ (void) scratch_length;
+ GNUNET_break (NULL == cls);
if (1 != param_length)
return -1;
- u_nbo = GNUNET_new(uint16_t);
+ u_nbo = GNUNET_new (uint16_t);
scratch[0] = u_nbo;
- *u_nbo = htons(*u_hbo);
- param_values[0] = (void *)u_nbo;
+ *u_nbo = htons (*u_hbo);
+ param_values[0] = (void *) u_nbo;
param_lengths[0] = sizeof(uint16_t);
param_formats[0] = 1;
return 1;
@@ -143,7 +143,7 @@ qconv_uint16(void *cls,
* @param x pointer to the query parameter to pass
*/
struct GNUNET_PQ_QueryParam
-GNUNET_PQ_query_param_uint16(const uint16_t *x)
+GNUNET_PQ_query_param_uint16 (const uint16_t *x)
{
struct GNUNET_PQ_QueryParam res =
{ &qconv_uint16, NULL, x, sizeof(*x), 1 };
@@ -167,28 +167,28 @@ GNUNET_PQ_query_param_uint16(const uint16_t *x)
* @return -1 on error, number of offsets used in @a scratch otherwise
*/
static int
-qconv_uint32(void *cls,
- const void *data,
- size_t data_len,
- void *param_values[],
- int param_lengths[],
- int param_formats[],
- unsigned int param_length,
- void *scratch[],
- unsigned int scratch_length)
+qconv_uint32 (void *cls,
+ const void *data,
+ size_t data_len,
+ void *param_values[],
+ int param_lengths[],
+ int param_formats[],
+ unsigned int param_length,
+ void *scratch[],
+ unsigned int scratch_length)
{
const uint32_t *u_hbo = data;
uint32_t *u_nbo;
- (void)scratch;
- (void)scratch_length;
- GNUNET_break(NULL == cls);
+ (void) scratch;
+ (void) scratch_length;
+ GNUNET_break (NULL == cls);
if (1 != param_length)
return -1;
- u_nbo = GNUNET_new(uint32_t);
+ u_nbo = GNUNET_new (uint32_t);
scratch[0] = u_nbo;
- *u_nbo = htonl(*u_hbo);
- param_values[0] = (void *)u_nbo;
+ *u_nbo = htonl (*u_hbo);
+ param_values[0] = (void *) u_nbo;
param_lengths[0] = sizeof(uint32_t);
param_formats[0] = 1;
return 1;
@@ -201,7 +201,7 @@ qconv_uint32(void *cls,
* @param x pointer to the query parameter to pass
*/
struct GNUNET_PQ_QueryParam
-GNUNET_PQ_query_param_uint32(const uint32_t *x)
+GNUNET_PQ_query_param_uint32 (const uint32_t *x)
{
struct GNUNET_PQ_QueryParam res =
{ &qconv_uint32, NULL, x, sizeof(*x), 1 };
@@ -225,28 +225,28 @@ GNUNET_PQ_query_param_uint32(const uint32_t *x)
* @return -1 on error, number of offsets used in @a scratch otherwise
*/
static int
-qconv_uint64(void *cls,
- const void *data,
- size_t data_len,
- void *param_values[],
- int param_lengths[],
- int param_formats[],
- unsigned int param_length,
- void *scratch[],
- unsigned int scratch_length)
+qconv_uint64 (void *cls,
+ const void *data,
+ size_t data_len,
+ void *param_values[],
+ int param_lengths[],
+ int param_formats[],
+ unsigned int param_length,
+ void *scratch[],
+ unsigned int scratch_length)
{
const uint64_t *u_hbo = data;
uint64_t *u_nbo;
- (void)scratch;
- (void)scratch_length;
- GNUNET_break(NULL == cls);
+ (void) scratch;
+ (void) scratch_length;
+ GNUNET_break (NULL == cls);
if (1 != param_length)
return -1;
- u_nbo = GNUNET_new(uint64_t);
+ u_nbo = GNUNET_new (uint64_t);
scratch[0] = u_nbo;
- *u_nbo = GNUNET_htonll(*u_hbo);
- param_values[0] = (void *)u_nbo;
+ *u_nbo = GNUNET_htonll (*u_hbo);
+ param_values[0] = (void *) u_nbo;
param_lengths[0] = sizeof(uint64_t);
param_formats[0] = 1;
return 1;
@@ -259,7 +259,7 @@ qconv_uint64(void *cls,
* @param x pointer to the query parameter to pass
*/
struct GNUNET_PQ_QueryParam
-GNUNET_PQ_query_param_uint64(const uint64_t *x)
+GNUNET_PQ_query_param_uint64 (const uint64_t *x)
{
struct GNUNET_PQ_QueryParam res =
{ &qconv_uint64, NULL, x, sizeof(*x), 1 };
@@ -283,27 +283,27 @@ GNUNET_PQ_query_param_uint64(const uint64_t *x)
* @return -1 on error, number of offsets used in @a scratch otherwise
*/
static int
-qconv_rsa_public_key(void *cls,
- const void *data,
- size_t data_len,
- void *param_values[],
- int param_lengths[],
- int param_formats[],
- unsigned int param_length,
- void *scratch[],
- unsigned int scratch_length)
+qconv_rsa_public_key (void *cls,
+ const void *data,
+ size_t data_len,
+ void *param_values[],
+ int param_lengths[],
+ int param_formats[],
+ unsigned int param_length,
+ void *scratch[],
+ unsigned int scratch_length)
{
const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data;
char *buf;
size_t buf_size;
- GNUNET_break(NULL == cls);
+ GNUNET_break (NULL == cls);
if (1 != param_length)
return -1;
- buf_size = GNUNET_CRYPTO_rsa_public_key_encode(rsa,
- &buf);
+ buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa,
+ &buf);
scratch[0] = buf;
- param_values[0] = (void *)buf;
+ param_values[0] = (void *) buf;
param_lengths[0] = buf_size - 1; /* DB doesn't like the trailing \0 */
param_formats[0] = 1;
return 1;
@@ -318,7 +318,8 @@ qconv_rsa_public_key(void *cls,
* @return array entry for the query parameters to use
*/
struct GNUNET_PQ_QueryParam
-GNUNET_PQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x)
+GNUNET_PQ_query_param_rsa_public_key (const struct
+ GNUNET_CRYPTO_RsaPublicKey *x)
{
struct GNUNET_PQ_QueryParam res =
{ &qconv_rsa_public_key, NULL, (x), 0, 1 };
@@ -342,27 +343,27 @@ GNUNET_PQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x)
* @return -1 on error, number of offsets used in @a scratch otherwise
*/
static int
-qconv_rsa_signature(void *cls,
- const void *data,
- size_t data_len,
- void *param_values[],
- int param_lengths[],
- int param_formats[],
- unsigned int param_length,
- void *scratch[],
- unsigned int scratch_length)
+qconv_rsa_signature (void *cls,
+ const void *data,
+ size_t data_len,
+ void *param_values[],
+ int param_lengths[],
+ int param_formats[],
+ unsigned int param_length,
+ void *scratch[],
+ unsigned int scratch_length)
{
const struct GNUNET_CRYPTO_RsaSignature *sig = data;
char *buf;
size_t buf_size;
- GNUNET_break(NULL == cls);
+ GNUNET_break (NULL == cls);
if (1 != param_length)
return -1;
- buf_size = GNUNET_CRYPTO_rsa_signature_encode(sig,
- &buf);
+ buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig,
+ &buf);
scratch[0] = buf;
- param_values[0] = (void *)buf;
+ param_values[0] = (void *) buf;
param_lengths[0] = buf_size - 1; /* DB doesn't like the trailing \0 */
param_formats[0] = 1;
return 1;
@@ -377,7 +378,7 @@ qconv_rsa_signature(void *cls,
* @return array entry for the query parameters to use
*/
struct GNUNET_PQ_QueryParam
-GNUNET_PQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x)
+GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
{
struct GNUNET_PQ_QueryParam res =
{ &qconv_rsa_signature, NULL, (x), 0, 1 };
@@ -401,30 +402,30 @@ GNUNET_PQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x)
* @return -1 on error, number of offsets used in @a scratch otherwise
*/
static int
-qconv_abs_time(void *cls,
- const void *data,
- size_t data_len,
- void *param_values[],
- int param_lengths[],
- int param_formats[],
- unsigned int param_length,
- void *scratch[],
- unsigned int scratch_length)
+qconv_abs_time (void *cls,
+ const void *data,
+ size_t data_len,
+ void *param_values[],
+ int param_lengths[],
+ int param_formats[],
+ unsigned int param_length,
+ void *scratch[],
+ unsigned int scratch_length)
{
const struct GNUNET_TIME_Absolute *u = data;
struct GNUNET_TIME_Absolute abs;
uint64_t *u_nbo;
- GNUNET_break(NULL == cls);
+ GNUNET_break (NULL == cls);
if (1 != param_length)
return -1;
abs = *u;
if (abs.abs_value_us > INT64_MAX)
abs.abs_value_us = INT64_MAX;
- u_nbo = GNUNET_new(uint64_t);
+ u_nbo = GNUNET_new (uint64_t);
scratch[0] = u_nbo;
- *u_nbo = GNUNET_htonll(abs.abs_value_us);
- param_values[0] = (void *)u_nbo;
+ *u_nbo = GNUNET_htonll (abs.abs_value_us);
+ param_values[0] = (void *) u_nbo;
param_lengths[0] = sizeof(uint64_t);
param_formats[0] = 1;
return 1;
@@ -439,7 +440,7 @@ qconv_abs_time(void *cls,
* @return array entry for the query parameters to use
*/
struct GNUNET_PQ_QueryParam
-GNUNET_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
+GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
{
struct GNUNET_PQ_QueryParam res =
{ &qconv_abs_time, NULL, x, sizeof(*x), 1 };
@@ -455,9 +456,10 @@ GNUNET_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
* @param x pointer to the query parameter to pass
*/
struct GNUNET_PQ_QueryParam
-GNUNET_PQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x)
+GNUNET_PQ_query_param_absolute_time_nbo (const struct
+ GNUNET_TIME_AbsoluteNBO *x)
{
- return GNUNET_PQ_query_param_auto_from_type(&x->abs_value_us__);
+ return GNUNET_PQ_query_param_auto_from_type (&x->abs_value_us__);
}
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c
index 89c0207f7..cfb16ac12 100644
--- a/src/pq/pq_result_helper.c
+++ b/src/pq/pq_result_helper.c
@@ -35,17 +35,17 @@
* @param rd result data to clean up
*/
static void
-clean_varsize_blob(void *cls,
- void *rd)
+clean_varsize_blob (void *cls,
+ void *rd)
{
void **dst = rd;
- (void)cls;
+ (void) cls;
if (NULL != *dst)
- {
- GNUNET_free(*dst);
- *dst = NULL;
- }
+ {
+ GNUNET_free (*dst);
+ *dst = NULL;
+ }
}
@@ -63,51 +63,51 @@ clean_varsize_blob(void *cls,
* #GNUNET_SYSERR if a result was invalid (non-existing field)
*/
static int
-extract_varsize_blob(void *cls,
- PGresult *result,
- int row,
- const char *fname,
- size_t *dst_size,
- void *dst)
+extract_varsize_blob (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
{
size_t len;
const char *res;
void *idst;
int fnum;
- (void)cls;
+ (void) cls;
*dst_size = 0;
- *((void **)dst) = NULL;
+ *((void **) dst) = NULL;
- fnum = PQfnumber(result,
- fname);
+ fnum = PQfnumber (result,
+ fname);
if (fnum < 0)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull(result,
- row,
- fnum))
- {
- /* Let's allow this for varsize */
- return GNUNET_OK;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ fnum))
+ {
+ /* Let's allow this for varsize */
+ return GNUNET_OK;
+ }
/* if a field is null, continue but
* remember that we now return a different result */
- len = PQgetlength(result,
+ len = PQgetlength (result,
+ row,
+ fnum);
+ res = PQgetvalue (result,
row,
fnum);
- res = PQgetvalue(result,
- row,
- fnum);
- GNUNET_assert(NULL != res);
+ GNUNET_assert (NULL != res);
*dst_size = len;
- idst = GNUNET_malloc(len);
- *((void **)dst) = idst;
- GNUNET_memcpy(idst,
- res,
- len);
+ idst = GNUNET_malloc (len);
+ *((void **) dst) = idst;
+ GNUNET_memcpy (idst,
+ res,
+ len);
return GNUNET_OK;
}
@@ -121,14 +121,14 @@ extract_varsize_blob(void *cls,
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
-GNUNET_PQ_result_spec_variable_size(const char *name,
- void **dst,
- size_t *sptr)
+GNUNET_PQ_result_spec_variable_size (const char *name,
+ void **dst,
+ size_t *sptr)
{
struct GNUNET_PQ_ResultSpec res =
{ &extract_varsize_blob,
&clean_varsize_blob, NULL,
- (void *)(dst), 0, name, sptr };
+ (void *) (dst), 0, name, sptr };
return res;
}
@@ -148,50 +148,50 @@ GNUNET_PQ_result_spec_variable_size(const char *name,
* #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
*/
static int
-extract_fixed_blob(void *cls,
- PGresult *result,
- int row,
- const char *fname,
- size_t *dst_size,
- void *dst)
+extract_fixed_blob (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
{
size_t len;
const char *res;
int fnum;
- (void)cls;
- fnum = PQfnumber(result,
- fname);
+ (void) cls;
+ fnum = PQfnumber (result,
+ fname);
if (fnum < 0)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull(result,
- row,
- fnum))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ fnum))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
/* if a field is null, continue but
* remember that we now return a different result */
- len = PQgetlength(result,
+ len = PQgetlength (result,
+ row,
+ fnum);
+ if (*dst_size != len)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ res = PQgetvalue (result,
row,
fnum);
- if (*dst_size != len)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- res = PQgetvalue(result,
- row,
- fnum);
- GNUNET_assert(NULL != res);
- GNUNET_memcpy(dst,
- res,
- len);
+ GNUNET_assert (NULL != res);
+ GNUNET_memcpy (dst,
+ res,
+ len);
return GNUNET_OK;
}
@@ -205,9 +205,9 @@ extract_fixed_blob(void *cls,
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
-GNUNET_PQ_result_spec_fixed_size(const char *name,
- void *dst,
- size_t dst_size)
+GNUNET_PQ_result_spec_fixed_size (const char *name,
+ void *dst,
+ size_t dst_size)
{
struct GNUNET_PQ_ResultSpec res =
{ &extract_fixed_blob,
@@ -232,49 +232,49 @@ GNUNET_PQ_result_spec_fixed_size(const char *name,
* #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
*/
static int
-extract_rsa_public_key(void *cls,
- PGresult *result,
- int row,
- const char *fname,
- size_t *dst_size,
- void *dst)
+extract_rsa_public_key (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
{
struct GNUNET_CRYPTO_RsaPublicKey **pk = dst;
size_t len;
const char *res;
int fnum;
- (void)cls;
+ (void) cls;
*pk = NULL;
- fnum = PQfnumber(result,
- fname);
+ fnum = PQfnumber (result,
+ fname);
if (fnum < 0)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull(result,
- row,
- fnum))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ fnum))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
/* if a field is null, continue but
* remember that we now return a different result */
- len = PQgetlength(result,
+ len = PQgetlength (result,
+ row,
+ fnum);
+ res = PQgetvalue (result,
row,
fnum);
- res = PQgetvalue(result,
- row,
- fnum);
- *pk = GNUNET_CRYPTO_rsa_public_key_decode(res,
- len);
+ *pk = GNUNET_CRYPTO_rsa_public_key_decode (res,
+ len);
if (NULL == *pk)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -287,17 +287,17 @@ extract_rsa_public_key(void *cls,
* @param rd result data to clean up
*/
static void
-clean_rsa_public_key(void *cls,
- void *rd)
+clean_rsa_public_key (void *cls,
+ void *rd)
{
struct GNUNET_CRYPTO_RsaPublicKey **pk = rd;
- (void)cls;
+ (void) cls;
if (NULL != *pk)
- {
- GNUNET_CRYPTO_rsa_public_key_free(*pk);
- *pk = NULL;
- }
+ {
+ GNUNET_CRYPTO_rsa_public_key_free (*pk);
+ *pk = NULL;
+ }
}
@@ -309,14 +309,14 @@ clean_rsa_public_key(void *cls,
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
-GNUNET_PQ_result_spec_rsa_public_key(const char *name,
- struct GNUNET_CRYPTO_RsaPublicKey **rsa)
+GNUNET_PQ_result_spec_rsa_public_key (const char *name,
+ struct GNUNET_CRYPTO_RsaPublicKey **rsa)
{
struct GNUNET_PQ_ResultSpec res =
{ &extract_rsa_public_key,
&clean_rsa_public_key,
NULL,
- (void *)rsa, 0, name, NULL };
+ (void *) rsa, 0, name, NULL };
return res;
}
@@ -336,49 +336,49 @@ GNUNET_PQ_result_spec_rsa_public_key(const char *name,
* #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
*/
static int
-extract_rsa_signature(void *cls,
- PGresult *result,
- int row,
- const char *fname,
- size_t *dst_size,
- void *dst)
+extract_rsa_signature (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
{
struct GNUNET_CRYPTO_RsaSignature **sig = dst;
size_t len;
const char *res;
int fnum;
- (void)cls;
+ (void) cls;
*sig = NULL;
- fnum = PQfnumber(result,
- fname);
+ fnum = PQfnumber (result,
+ fname);
if (fnum < 0)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull(result,
- row,
- fnum))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ fnum))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
/* if a field is null, continue but
* remember that we now return a different result */
- len = PQgetlength(result,
+ len = PQgetlength (result,
+ row,
+ fnum);
+ res = PQgetvalue (result,
row,
fnum);
- res = PQgetvalue(result,
- row,
- fnum);
- *sig = GNUNET_CRYPTO_rsa_signature_decode(res,
- len);
+ *sig = GNUNET_CRYPTO_rsa_signature_decode (res,
+ len);
if (NULL == *sig)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -391,17 +391,17 @@ extract_rsa_signature(void *cls,
* @param rd result data to clean up
*/
static void
-clean_rsa_signature(void *cls,
- void *rd)
+clean_rsa_signature (void *cls,
+ void *rd)
{
struct GNUNET_CRYPTO_RsaSignature **sig = rd;
- (void)cls;
+ (void) cls;
if (NULL != *sig)
- {
- GNUNET_CRYPTO_rsa_signature_free(*sig);
- *sig = NULL;
- }
+ {
+ GNUNET_CRYPTO_rsa_signature_free (*sig);
+ *sig = NULL;
+ }
}
@@ -413,14 +413,14 @@ clean_rsa_signature(void *cls,
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
-GNUNET_PQ_result_spec_rsa_signature(const char *name,
- struct GNUNET_CRYPTO_RsaSignature **sig)
+GNUNET_PQ_result_spec_rsa_signature (const char *name,
+ struct GNUNET_CRYPTO_RsaSignature **sig)
{
struct GNUNET_PQ_ResultSpec res =
{ &extract_rsa_signature,
&clean_rsa_signature,
NULL,
- (void *)sig, 0, (name), NULL };
+ (void *) sig, 0, (name), NULL };
return res;
}
@@ -440,49 +440,49 @@ GNUNET_PQ_result_spec_rsa_signature(const char *name,
* #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
*/
static int
-extract_string(void *cls,
- PGresult *result,
- int row,
- const char *fname,
- size_t *dst_size,
- void *dst)
+extract_string (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
{
char **str = dst;
size_t len;
const char *res;
int fnum;
- (void)cls;
+ (void) cls;
*str = NULL;
- fnum = PQfnumber(result,
- fname);
+ fnum = PQfnumber (result,
+ fname);
if (fnum < 0)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull(result,
- row,
- fnum))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ fnum))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
/* if a field is null, continue but
* remember that we now return a different result */
- len = PQgetlength(result,
+ len = PQgetlength (result,
+ row,
+ fnum);
+ res = PQgetvalue (result,
row,
fnum);
- res = PQgetvalue(result,
- row,
- fnum);
- *str = GNUNET_strndup(res,
- len);
+ *str = GNUNET_strndup (res,
+ len);
if (NULL == *str)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -495,17 +495,17 @@ extract_string(void *cls,
* @param rd result data to clean up
*/
static void
-clean_string(void *cls,
- void *rd)
+clean_string (void *cls,
+ void *rd)
{
char **str = rd;
- (void)cls;
+ (void) cls;
if (NULL != *str)
- {
- GNUNET_free(*str);
- *str = NULL;
- }
+ {
+ GNUNET_free (*str);
+ *str = NULL;
+ }
}
@@ -517,14 +517,14 @@ clean_string(void *cls,
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
-GNUNET_PQ_result_spec_string(const char *name,
- char **dst)
+GNUNET_PQ_result_spec_string (const char *name,
+ char **dst)
{
struct GNUNET_PQ_ResultSpec res =
{ &extract_string,
&clean_string,
NULL,
- (void *)dst, 0, (name), NULL };
+ (void *) dst, 0, (name), NULL };
return res;
}
@@ -544,53 +544,53 @@ GNUNET_PQ_result_spec_string(const char *name,
* #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
*/
static int
-extract_abs_time(void *cls,
- PGresult *result,
- int row,
- const char *fname,
- size_t *dst_size,
- void *dst)
+extract_abs_time (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
{
struct GNUNET_TIME_Absolute *udst = dst;
const int64_t *res;
int fnum;
- (void)cls;
- fnum = PQfnumber(result,
- fname);
+ (void) cls;
+ fnum = PQfnumber (result,
+ fname);
if (fnum < 0)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull(result,
- row,
- fnum))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- GNUNET_assert(NULL != dst);
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ fnum))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_assert (NULL != dst);
if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (sizeof(int64_t) !=
- PQgetlength(result,
- row,
- fnum))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- res = (int64_t *)PQgetvalue(result,
- row,
- fnum);
+ PQgetlength (result,
+ row,
+ fnum))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ res = (int64_t *) PQgetvalue (result,
+ row,
+ fnum);
if (INT64_MAX == *res)
*udst = GNUNET_TIME_UNIT_FOREVER_ABS;
else
- udst->abs_value_us = GNUNET_ntohll((uint64_t)*res);
+ udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res);
return GNUNET_OK;
}
@@ -603,14 +603,14 @@ extract_abs_time(void *cls,
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
-GNUNET_PQ_result_spec_absolute_time(const char *name,
- struct GNUNET_TIME_Absolute *at)
+GNUNET_PQ_result_spec_absolute_time (const char *name,
+ struct GNUNET_TIME_Absolute *at)
{
struct GNUNET_PQ_ResultSpec res =
{ &extract_abs_time,
NULL,
NULL,
- (void *)at, sizeof(*at), (name), NULL };
+ (void *) at, sizeof(*at), (name), NULL };
return res;
}
@@ -624,11 +624,11 @@ GNUNET_PQ_result_spec_absolute_time(const char *name,
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
-GNUNET_PQ_result_spec_absolute_time_nbo(const char *name,
- struct GNUNET_TIME_AbsoluteNBO *at)
+GNUNET_PQ_result_spec_absolute_time_nbo (const char *name,
+ struct GNUNET_TIME_AbsoluteNBO *at)
{
struct GNUNET_PQ_ResultSpec res =
- GNUNET_PQ_result_spec_auto_from_type(name, &at->abs_value_us__);
+ GNUNET_PQ_result_spec_auto_from_type (name, &at->abs_value_us__);
return res;
}
@@ -648,50 +648,50 @@ GNUNET_PQ_result_spec_absolute_time_nbo(const char *name,
* #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
*/
static int
-extract_uint16(void *cls,
- PGresult *result,
- int row,
- const char *fname,
- size_t *dst_size,
- void *dst)
+extract_uint16 (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
{
uint16_t *udst = dst;
const uint16_t *res;
int fnum;
- (void)cls;
- fnum = PQfnumber(result,
- fname);
+ (void) cls;
+ fnum = PQfnumber (result,
+ fname);
if (fnum < 0)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull(result,
- row,
- fnum))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- GNUNET_assert(NULL != dst);
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ fnum))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_assert (NULL != dst);
if (sizeof(uint16_t) != *dst_size)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (sizeof(uint16_t) !=
- PQgetlength(result,
- row,
- fnum))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- res = (uint16_t *)PQgetvalue(result,
- row,
- fnum);
- *udst = ntohs(*res);
+ PQgetlength (result,
+ row,
+ fnum))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ res = (uint16_t *) PQgetvalue (result,
+ row,
+ fnum);
+ *udst = ntohs (*res);
return GNUNET_OK;
}
@@ -704,14 +704,14 @@ extract_uint16(void *cls,
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
-GNUNET_PQ_result_spec_uint16(const char *name,
- uint16_t *u16)
+GNUNET_PQ_result_spec_uint16 (const char *name,
+ uint16_t *u16)
{
struct GNUNET_PQ_ResultSpec res =
{ &extract_uint16,
NULL,
NULL,
- (void *)u16, sizeof(*u16), (name), NULL };
+ (void *) u16, sizeof(*u16), (name), NULL };
return res;
}
@@ -731,50 +731,50 @@ GNUNET_PQ_result_spec_uint16(const char *name,
* #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
*/
static int
-extract_uint32(void *cls,
- PGresult *result,
- int row,
- const char *fname,
- size_t *dst_size,
- void *dst)
+extract_uint32 (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
{
uint32_t *udst = dst;
const uint32_t *res;
int fnum;
- (void)cls;
- fnum = PQfnumber(result,
- fname);
+ (void) cls;
+ fnum = PQfnumber (result,
+ fname);
if (fnum < 0)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull(result,
- row,
- fnum))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- GNUNET_assert(NULL != dst);
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ fnum))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_assert (NULL != dst);
if (sizeof(uint32_t) != *dst_size)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (sizeof(uint32_t) !=
- PQgetlength(result,
- row,
- fnum))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- res = (uint32_t *)PQgetvalue(result,
- row,
- fnum);
- *udst = ntohl(*res);
+ PQgetlength (result,
+ row,
+ fnum))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ res = (uint32_t *) PQgetvalue (result,
+ row,
+ fnum);
+ *udst = ntohl (*res);
return GNUNET_OK;
}
@@ -787,14 +787,14 @@ extract_uint32(void *cls,
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
-GNUNET_PQ_result_spec_uint32(const char *name,
- uint32_t *u32)
+GNUNET_PQ_result_spec_uint32 (const char *name,
+ uint32_t *u32)
{
struct GNUNET_PQ_ResultSpec res =
{ &extract_uint32,
NULL,
NULL,
- (void *)u32, sizeof(*u32), (name), NULL };
+ (void *) u32, sizeof(*u32), (name), NULL };
return res;
}
@@ -814,50 +814,50 @@ GNUNET_PQ_result_spec_uint32(const char *name,
* #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
*/
static int
-extract_uint64(void *cls,
- PGresult *result,
- int row,
- const char *fname,
- size_t *dst_size,
- void *dst)
+extract_uint64 (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
{
uint64_t *udst = dst;
const uint64_t *res;
int fnum;
- (void)cls;
- fnum = PQfnumber(result,
- fname);
+ (void) cls;
+ fnum = PQfnumber (result,
+ fname);
if (fnum < 0)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull(result,
- row,
- fnum))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- GNUNET_assert(NULL != dst);
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ fnum))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_assert (NULL != dst);
if (sizeof(uint64_t) != *dst_size)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (sizeof(uint64_t) !=
- PQgetlength(result,
- row,
- fnum))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- res = (uint64_t *)PQgetvalue(result,
- row,
- fnum);
- *udst = GNUNET_ntohll(*res);
+ PQgetlength (result,
+ row,
+ fnum))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ res = (uint64_t *) PQgetvalue (result,
+ row,
+ fnum);
+ *udst = GNUNET_ntohll (*res);
return GNUNET_OK;
}
@@ -870,14 +870,14 @@ extract_uint64(void *cls,
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
-GNUNET_PQ_result_spec_uint64(const char *name,
- uint64_t *u64)
+GNUNET_PQ_result_spec_uint64 (const char *name,
+ uint64_t *u64)
{
struct GNUNET_PQ_ResultSpec res =
{ &extract_uint64,
NULL,
NULL,
- (void *)u64, sizeof(*u64), (name), NULL };
+ (void *) u64, sizeof(*u64), (name), NULL };
return res;
}
diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c
index df54580d2..697d8e580 100644
--- a/src/pq/test_pq.c
+++ b/src/pq/test_pq.c
@@ -34,52 +34,52 @@
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
static int
-postgres_prepare(PGconn *db_conn)
+postgres_prepare (PGconn *db_conn)
{
PGresult *result;
#define PREPARE(name, sql, ...) \
do { \
- result = PQprepare(db_conn, name, sql, __VA_ARGS__); \
- if (PGRES_COMMAND_OK != PQresultStatus(result)) \
- { \
- GNUNET_break(0); \
- PQclear(result); result = NULL; \
- return GNUNET_SYSERR; \
- } \
- PQclear(result); result = NULL; \
- } while (0);
+ result = PQprepare (db_conn, name, sql, __VA_ARGS__); \
+ if (PGRES_COMMAND_OK != PQresultStatus (result)) \
+ { \
+ GNUNET_break (0); \
+ PQclear (result); result = NULL; \
+ return GNUNET_SYSERR; \
+ } \
+ PQclear (result); result = NULL; \
+ } while (0);
- PREPARE("test_insert",
- "INSERT INTO test_pq ("
- " pub"
- ",sig"
- ",abs_time"
- ",forever"
- ",hash"
- ",vsize"
- ",u16"
- ",u32"
- ",u64"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6,"
- "$7, $8, $9);",
- 9, NULL);
- PREPARE("test_select",
- "SELECT"
- " pub"
- ",sig"
- ",abs_time"
- ",forever"
- ",hash"
- ",vsize"
- ",u16"
- ",u32"
- ",u64"
- " FROM test_pq"
- " ORDER BY abs_time DESC "
- " LIMIT 1;",
- 0, NULL);
+ PREPARE ("test_insert",
+ "INSERT INTO test_pq ("
+ " pub"
+ ",sig"
+ ",abs_time"
+ ",forever"
+ ",hash"
+ ",vsize"
+ ",u16"
+ ",u32"
+ ",u64"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6,"
+ "$7, $8, $9);",
+ 9, NULL);
+ PREPARE ("test_select",
+ "SELECT"
+ " pub"
+ ",sig"
+ ",abs_time"
+ ",forever"
+ ",hash"
+ ",vsize"
+ ",u16"
+ ",u32"
+ ",u64"
+ " FROM test_pq"
+ " ORDER BY abs_time DESC "
+ " LIMIT 1;",
+ 0, NULL);
return GNUNET_OK;
#undef PREPARE
}
@@ -91,13 +91,13 @@ postgres_prepare(PGconn *db_conn)
* @return 0 on success
*/
static int
-run_queries(PGconn *conn)
+run_queries (PGconn *conn)
{
struct GNUNET_CRYPTO_RsaPublicKey *pub;
struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL;
struct GNUNET_CRYPTO_RsaSignature *sig;
struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL;
- struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get();
+ struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get ();
struct GNUNET_TIME_Absolute abs_time2;
struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS;
struct GNUNET_TIME_Absolute forever2;
@@ -117,102 +117,102 @@ run_queries(PGconn *conn)
uint64_t u64;
uint64_t u642;
- priv = GNUNET_CRYPTO_rsa_private_key_create(1024);
- pub = GNUNET_CRYPTO_rsa_private_key_get_public(priv);
- memset(&hmsg, 42, sizeof(hmsg));
- sig = GNUNET_CRYPTO_rsa_sign_fdh(priv,
- &hmsg);
+ priv = GNUNET_CRYPTO_rsa_private_key_create (1024);
+ pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv);
+ memset (&hmsg, 42, sizeof(hmsg));
+ sig = GNUNET_CRYPTO_rsa_sign_fdh (priv,
+ &hmsg);
u16 = 16;
u32 = 32;
u64 = 64;
/* FIXME: test GNUNET_PQ_result_spec_variable_size */
{
struct GNUNET_PQ_QueryParam params_insert[] = {
- GNUNET_PQ_query_param_rsa_public_key(pub),
- GNUNET_PQ_query_param_rsa_signature(sig),
- GNUNET_PQ_query_param_absolute_time(&abs_time),
- GNUNET_PQ_query_param_absolute_time(&forever),
- GNUNET_PQ_query_param_auto_from_type(&hc),
- GNUNET_PQ_query_param_fixed_size(msg, strlen(msg)),
- GNUNET_PQ_query_param_uint16(&u16),
- GNUNET_PQ_query_param_uint32(&u32),
- GNUNET_PQ_query_param_uint64(&u64),
+ GNUNET_PQ_query_param_rsa_public_key (pub),
+ GNUNET_PQ_query_param_rsa_signature (sig),
+ GNUNET_PQ_query_param_absolute_time (&abs_time),
+ GNUNET_PQ_query_param_absolute_time (&forever),
+ GNUNET_PQ_query_param_auto_from_type (&hc),
+ GNUNET_PQ_query_param_fixed_size (msg, strlen (msg)),
+ GNUNET_PQ_query_param_uint16 (&u16),
+ GNUNET_PQ_query_param_uint32 (&u32),
+ GNUNET_PQ_query_param_uint64 (&u64),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_QueryParam params_select[] = {
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec results_select[] = {
- GNUNET_PQ_result_spec_rsa_public_key("pub", &pub2),
- GNUNET_PQ_result_spec_rsa_signature("sig", &sig2),
- GNUNET_PQ_result_spec_absolute_time("abs_time", &abs_time2),
- GNUNET_PQ_result_spec_absolute_time("forever", &forever2),
- GNUNET_PQ_result_spec_auto_from_type("hash", &hc2),
- GNUNET_PQ_result_spec_variable_size("vsize", &msg2, &msg2_len),
- GNUNET_PQ_result_spec_uint16("u16", &u162),
- GNUNET_PQ_result_spec_uint32("u32", &u322),
- GNUNET_PQ_result_spec_uint64("u64", &u642),
+ GNUNET_PQ_result_spec_rsa_public_key ("pub", &pub2),
+ GNUNET_PQ_result_spec_rsa_signature ("sig", &sig2),
+ GNUNET_PQ_result_spec_absolute_time ("abs_time", &abs_time2),
+ GNUNET_PQ_result_spec_absolute_time ("forever", &forever2),
+ GNUNET_PQ_result_spec_auto_from_type ("hash", &hc2),
+ GNUNET_PQ_result_spec_variable_size ("vsize", &msg2, &msg2_len),
+ GNUNET_PQ_result_spec_uint16 ("u16", &u162),
+ GNUNET_PQ_result_spec_uint32 ("u32", &u322),
+ GNUNET_PQ_result_spec_uint64 ("u64", &u642),
GNUNET_PQ_result_spec_end
};
- result = GNUNET_PQ_exec_prepared(conn,
- "test_insert",
- params_insert);
- if (PGRES_COMMAND_OK != PQresultStatus(result))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Database failure: %s\n",
- PQresultErrorMessage(result));
- PQclear(result);
- GNUNET_CRYPTO_rsa_signature_free(sig);
- GNUNET_CRYPTO_rsa_private_key_free(priv);
- GNUNET_CRYPTO_rsa_public_key_free(pub);
- return 1;
- }
+ result = GNUNET_PQ_exec_prepared (conn,
+ "test_insert",
+ params_insert);
+ if (PGRES_COMMAND_OK != PQresultStatus (result))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Database failure: %s\n",
+ PQresultErrorMessage (result));
+ PQclear (result);
+ GNUNET_CRYPTO_rsa_signature_free (sig);
+ GNUNET_CRYPTO_rsa_private_key_free (priv);
+ GNUNET_CRYPTO_rsa_public_key_free (pub);
+ return 1;
+ }
- PQclear(result);
- result = GNUNET_PQ_exec_prepared(conn,
- "test_select",
- params_select);
+ PQclear (result);
+ result = GNUNET_PQ_exec_prepared (conn,
+ "test_select",
+ params_select);
if (1 !=
- PQntuples(result))
- {
- GNUNET_break(0);
- PQclear(result);
- GNUNET_CRYPTO_rsa_signature_free(sig);
- GNUNET_CRYPTO_rsa_private_key_free(priv);
- GNUNET_CRYPTO_rsa_public_key_free(pub);
- return 1;
- }
- ret = GNUNET_PQ_extract_result(result,
- results_select,
- 0);
- GNUNET_break(GNUNET_YES == ret);
- GNUNET_break(abs_time.abs_value_us == abs_time2.abs_value_us);
- GNUNET_break(forever.abs_value_us == forever2.abs_value_us);
- GNUNET_break(0 ==
- GNUNET_memcmp(&hc,
- &hc2));
- GNUNET_break(0 ==
- GNUNET_CRYPTO_rsa_signature_cmp(sig,
- sig2));
- GNUNET_break(0 ==
- GNUNET_CRYPTO_rsa_public_key_cmp(pub,
- pub2));
- GNUNET_break(strlen(msg) == msg2_len);
- GNUNET_break(0 ==
- strncmp(msg,
- msg2,
- msg2_len));
- GNUNET_break(16 == u162);
- GNUNET_break(32 == u322);
- GNUNET_break(64 == u642);
- GNUNET_PQ_cleanup_result(results_select);
- PQclear(result);
+ PQntuples (result))
+ {
+ GNUNET_break (0);
+ PQclear (result);
+ GNUNET_CRYPTO_rsa_signature_free (sig);
+ GNUNET_CRYPTO_rsa_private_key_free (priv);
+ GNUNET_CRYPTO_rsa_public_key_free (pub);
+ return 1;
+ }
+ ret = GNUNET_PQ_extract_result (result,
+ results_select,
+ 0);
+ GNUNET_break (GNUNET_YES == ret);
+ GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us);
+ GNUNET_break (forever.abs_value_us == forever2.abs_value_us);
+ GNUNET_break (0 ==
+ GNUNET_memcmp (&hc,
+ &hc2));
+ GNUNET_break (0 ==
+ GNUNET_CRYPTO_rsa_signature_cmp (sig,
+ sig2));
+ GNUNET_break (0 ==
+ GNUNET_CRYPTO_rsa_public_key_cmp (pub,
+ pub2));
+ GNUNET_break (strlen (msg) == msg2_len);
+ GNUNET_break (0 ==
+ strncmp (msg,
+ msg2,
+ msg2_len));
+ GNUNET_break (16 == u162);
+ GNUNET_break (32 == u322);
+ GNUNET_break (64 == u642);
+ GNUNET_PQ_cleanup_result (results_select);
+ PQclear (result);
}
- GNUNET_CRYPTO_rsa_signature_free(sig);
- GNUNET_CRYPTO_rsa_private_key_free(priv);
- GNUNET_CRYPTO_rsa_public_key_free(pub);
+ GNUNET_CRYPTO_rsa_signature_free (sig);
+ GNUNET_CRYPTO_rsa_private_key_free (priv);
+ GNUNET_CRYPTO_rsa_public_key_free (pub);
if (GNUNET_OK != ret)
return 1;
@@ -221,70 +221,70 @@ run_queries(PGconn *conn)
int
-main(int argc,
- const char *const argv[])
+main (int argc,
+ const char *const argv[])
{
PGconn *conn;
PGresult *result;
int ret;
- GNUNET_log_setup("test-pq",
- "WARNING",
- NULL);
- conn = PQconnectdb("postgres:///gnunetcheck");
- if (CONNECTION_OK != PQstatus(conn))
- {
- fprintf(stderr,
- "Cannot run test, database connection failed: %s\n",
- PQerrorMessage(conn));
- GNUNET_break(0);
- PQfinish(conn);
- return 77; /* signal test was skipped */
- }
+ GNUNET_log_setup ("test-pq",
+ "WARNING",
+ NULL);
+ conn = PQconnectdb ("postgres:///gnunetcheck");
+ if (CONNECTION_OK != PQstatus (conn))
+ {
+ fprintf (stderr,
+ "Cannot run test, database connection failed: %s\n",
+ PQerrorMessage (conn));
+ GNUNET_break (0);
+ PQfinish (conn);
+ return 77; /* signal test was skipped */
+ }
- result = PQexec(conn,
- "CREATE TEMPORARY TABLE IF NOT EXISTS test_pq ("
- " pub BYTEA NOT NULL"
- ",sig BYTEA NOT NULL"
- ",abs_time INT8 NOT NULL"
- ",forever INT8 NOT NULL"
- ",hash BYTEA NOT NULL CHECK(LENGTH(hash)=64)"
- ",vsize VARCHAR NOT NULL"
- ",u16 INT2 NOT NULL"
- ",u32 INT4 NOT NULL"
- ",u64 INT8 NOT NULL"
- ")");
- if (PGRES_COMMAND_OK != PQresultStatus(result))
- {
- fprintf(stderr,
- "Failed to create table: %s\n",
- PQerrorMessage(conn));
- PQclear(result);
- PQfinish(conn);
- return 1;
- }
- PQclear(result);
+ result = PQexec (conn,
+ "CREATE TEMPORARY TABLE IF NOT EXISTS test_pq ("
+ " pub BYTEA NOT NULL"
+ ",sig BYTEA NOT NULL"
+ ",abs_time INT8 NOT NULL"
+ ",forever INT8 NOT NULL"
+ ",hash BYTEA NOT NULL CHECK(LENGTH(hash)=64)"
+ ",vsize VARCHAR NOT NULL"
+ ",u16 INT2 NOT NULL"
+ ",u32 INT4 NOT NULL"
+ ",u64 INT8 NOT NULL"
+ ")");
+ if (PGRES_COMMAND_OK != PQresultStatus (result))
+ {
+ fprintf (stderr,
+ "Failed to create table: %s\n",
+ PQerrorMessage (conn));
+ PQclear (result);
+ PQfinish (conn);
+ return 1;
+ }
+ PQclear (result);
if (GNUNET_OK !=
- postgres_prepare(conn))
- {
- GNUNET_break(0);
- PQfinish(conn);
- return 1;
- }
- ret = run_queries(conn);
- result = PQexec(conn,
- "DROP TABLE test_pq");
- if (PGRES_COMMAND_OK != PQresultStatus(result))
- {
- fprintf(stderr,
- "Failed to create table: %s\n",
- PQerrorMessage(conn));
- PQclear(result);
- PQfinish(conn);
- return 1;
- }
- PQclear(result);
- PQfinish(conn);
+ postgres_prepare (conn))
+ {
+ GNUNET_break (0);
+ PQfinish (conn);
+ return 1;
+ }
+ ret = run_queries (conn);
+ result = PQexec (conn,
+ "DROP TABLE test_pq");
+ if (PGRES_COMMAND_OK != PQresultStatus (result))
+ {
+ fprintf (stderr,
+ "Failed to create table: %s\n",
+ PQerrorMessage (conn));
+ PQclear (result);
+ PQfinish (conn);
+ return 1;
+ }
+ PQclear (result);
+ PQfinish (conn);
return ret;
}