From c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 5 Oct 2019 15:09:28 +0200 Subject: global reindent, now with uncrustify hook enabled --- src/sq/sq.c | 102 +++++----- src/sq/sq_exec.c | 62 +++--- src/sq/sq_prepare.c | 42 ++-- src/sq/sq_query_helper.c | 240 +++++++++++----------- src/sq/sq_result_helper.c | 505 +++++++++++++++++++++++----------------------- src/sq/test_sq.c | 340 +++++++++++++++---------------- 6 files changed, 646 insertions(+), 645 deletions(-) (limited to 'src/sq') diff --git a/src/sq/sq.c b/src/sq/sq.c index 6fce01322..7641cbacd 100644 --- a/src/sq/sq.c +++ b/src/sq/sq.c @@ -34,37 +34,37 @@ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int -GNUNET_SQ_bind(sqlite3_stmt *stmt, - const struct GNUNET_SQ_QueryParam *params) +GNUNET_SQ_bind (sqlite3_stmt *stmt, + const struct GNUNET_SQ_QueryParam *params) { unsigned int j; j = 1; for (unsigned int i = 0; NULL != params[i].conv; i++) + { + if (GNUNET_OK != + params[i].conv (params[i].conv_cls, + params[i].data, + params[i].size, + stmt, + j)) { - if (GNUNET_OK != - params[i].conv(params[i].conv_cls, - params[i].data, - params[i].size, - stmt, - j)) - { - GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, - "sq", - _("Failure to bind %u-th SQL parameter\n"), - i); - if (SQLITE_OK != - sqlite3_reset(stmt)) - { - GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, - "sq", - _("Failure in sqlite3_reset (!)\n")); - return GNUNET_SYSERR; - } - } - GNUNET_assert(0 != params[i].num_params); - j += params[i].num_params; + GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, + "sq", + _ ("Failure to bind %u-th SQL parameter\n"), + i); + if (SQLITE_OK != + sqlite3_reset (stmt)) + { + GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, + "sq", + _ ("Failure in sqlite3_reset (!)\n")); + return GNUNET_SYSERR; + } } + GNUNET_assert (0 != params[i].num_params); + j += params[i].num_params; + } return GNUNET_OK; } @@ -79,30 +79,30 @@ GNUNET_SQ_bind(sqlite3_stmt *stmt, * #GNUNET_SYSERR if a result was invalid (non-existing field) */ int -GNUNET_SQ_extract_result(sqlite3_stmt *result, - struct GNUNET_SQ_ResultSpec *rs) +GNUNET_SQ_extract_result (sqlite3_stmt *result, + struct GNUNET_SQ_ResultSpec *rs) { unsigned int j = 0; for (unsigned int i = 0; NULL != rs[i].conv; i++) + { + if (NULL == rs[i].result_size) + rs[i].result_size = &rs[i].dst_size; + if (GNUNET_OK != + rs[i].conv (rs[i].cls, + result, + j, + rs[i].result_size, + rs[i].dst)) { - if (NULL == rs[i].result_size) - rs[i].result_size = &rs[i].dst_size; - if (GNUNET_OK != - rs[i].conv(rs[i].cls, - result, - j, - rs[i].result_size, - rs[i].dst)) - { - for (unsigned int k = 0; k < i; k++) - if (NULL != rs[k].cleaner) - rs[k].cleaner(rs[k].cls); - return GNUNET_SYSERR; - } - GNUNET_assert(0 != rs[i].num_params); - j += rs[i].num_params; + for (unsigned int k = 0; k < i; k++) + if (NULL != rs[k].cleaner) + rs[k].cleaner (rs[k].cls); + return GNUNET_SYSERR; } + GNUNET_assert (0 != rs[i].num_params); + j += rs[i].num_params; + } return GNUNET_OK; } @@ -114,11 +114,11 @@ GNUNET_SQ_extract_result(sqlite3_stmt *result, * @param rs reult specification to clean up */ void -GNUNET_SQ_cleanup_result(struct GNUNET_SQ_ResultSpec *rs) +GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs) { for (unsigned int i = 0; NULL != rs[i].conv; i++) if (NULL != rs[i].cleaner) - rs[i].cleaner(rs[i].cls); + rs[i].cleaner (rs[i].cls); } @@ -129,15 +129,15 @@ GNUNET_SQ_cleanup_result(struct GNUNET_SQ_ResultSpec *rs) * @param stmt statement to reset */ void -GNUNET_SQ_reset(sqlite3 *dbh, - sqlite3_stmt *stmt) +GNUNET_SQ_reset (sqlite3 *dbh, + sqlite3_stmt *stmt) { if (SQLITE_OK != - sqlite3_reset(stmt)) - GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "sqlite", - _("Failed to reset sqlite statement with error: %s\n"), - sqlite3_errmsg(dbh)); + sqlite3_reset (stmt)) + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite", + _ ("Failed to reset sqlite statement with error: %s\n"), + sqlite3_errmsg (dbh)); } diff --git a/src/sq/sq_exec.c b/src/sq/sq_exec.c index ebc159421..1dfa535d9 100644 --- a/src/sq/sq_exec.c +++ b/src/sq/sq_exec.c @@ -33,7 +33,7 @@ * @return initialized struct */ struct GNUNET_SQ_ExecuteStatement -GNUNET_SQ_make_execute(const char *sql) +GNUNET_SQ_make_execute (const char *sql) { struct GNUNET_SQ_ExecuteStatement es = { .sql = sql, @@ -53,7 +53,7 @@ GNUNET_SQ_make_execute(const char *sql) * @return initialized struct */ struct GNUNET_SQ_ExecuteStatement -GNUNET_SQ_make_try_execute(const char *sql) +GNUNET_SQ_make_try_execute (const char *sql) { struct GNUNET_SQ_ExecuteStatement es = { .sql = sql, @@ -74,39 +74,39 @@ GNUNET_SQ_make_try_execute(const char *sql) * #GNUNET_SYSERR on error */ int -GNUNET_SQ_exec_statements(sqlite3 *dbh, - const struct GNUNET_SQ_ExecuteStatement *es) +GNUNET_SQ_exec_statements (sqlite3 *dbh, + const struct GNUNET_SQ_ExecuteStatement *es) { for (unsigned int i = 0; NULL != es[i].sql; i++) - { - char *emsg = NULL; + { + char *emsg = NULL; - if (SQLITE_OK != - sqlite3_exec(dbh, - es[i].sql, - NULL, - NULL, - &emsg)) - { - if (es[i].ignore_errors) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Failed to run SQL `%s': %s\n", - es[i].sql, - emsg); - } - else - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to run SQL `%s': %s\n", - es[i].sql, - emsg); - sqlite3_free(emsg); - return GNUNET_SYSERR; - } - sqlite3_free(emsg); - } + if (SQLITE_OK != + sqlite3_exec (dbh, + es[i].sql, + NULL, + NULL, + &emsg)) + { + if (es[i].ignore_errors) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Failed to run SQL `%s': %s\n", + es[i].sql, + emsg); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to run SQL `%s': %s\n", + es[i].sql, + emsg); + sqlite3_free (emsg); + return GNUNET_SYSERR; + } + sqlite3_free (emsg); } + } return GNUNET_OK; } diff --git a/src/sq/sq_prepare.c b/src/sq/sq_prepare.c index 3df4b80bc..5d232fd17 100644 --- a/src/sq/sq_prepare.c +++ b/src/sq/sq_prepare.c @@ -34,8 +34,8 @@ * @return initialized struct */ struct GNUNET_SQ_PrepareStatement -GNUNET_SQ_make_prepare(const char *sql, - sqlite3_stmt **pstmt) +GNUNET_SQ_make_prepare (const char *sql, + sqlite3_stmt **pstmt) { struct GNUNET_SQ_PrepareStatement ps = { .sql = sql, @@ -56,29 +56,29 @@ GNUNET_SQ_make_prepare(const char *sql, * @return #GNUNET_OK on success */ int -GNUNET_SQ_prepare(sqlite3 *dbh, - const struct GNUNET_SQ_PrepareStatement *ps) +GNUNET_SQ_prepare (sqlite3 *dbh, + const struct GNUNET_SQ_PrepareStatement *ps) { for (unsigned int i = 0; NULL != ps[i].sql; i++) - { - const char *epos = NULL; - int ret; + { + const char *epos = NULL; + int ret; - if (SQLITE_OK != - (ret = sqlite3_prepare_v2(dbh, - ps[i].sql, - strlen(ps[i].sql), - ps[i].pstmt, - &epos))) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to prepare SQL `%s': error %d at %s\n", - ps[i].sql, - ret, - epos); - return GNUNET_SYSERR; - } + if (SQLITE_OK != + (ret = sqlite3_prepare_v2 (dbh, + ps[i].sql, + strlen (ps[i].sql), + ps[i].pstmt, + &epos))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to prepare SQL `%s': error %d at %s\n", + ps[i].sql, + ret, + epos); + return GNUNET_SYSERR; } + } return GNUNET_OK; } diff --git a/src/sq/sq_query_helper.c b/src/sq/sq_query_helper.c index 1addef499..ce317a656 100644 --- a/src/sq/sq_query_helper.c +++ b/src/sq/sq_query_helper.c @@ -38,18 +38,18 @@ * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ static int -bind_fixed_blob(void *cls, - const void *data, - size_t data_len, - sqlite3_stmt *stmt, - unsigned int off) +bind_fixed_blob (void *cls, + const void *data, + size_t data_len, + sqlite3_stmt *stmt, + unsigned int off) { if (SQLITE_OK != - sqlite3_bind_blob64(stmt, - (int)off, - data, - (sqlite3_uint64)data_len, - SQLITE_TRANSIENT)) + sqlite3_bind_blob64 (stmt, + (int) off, + data, + (sqlite3_uint64) data_len, + SQLITE_TRANSIENT)) return GNUNET_SYSERR; return GNUNET_OK; } @@ -63,8 +63,8 @@ bind_fixed_blob(void *cls, * @oaran ptr_size number of bytes in @a ptr */ struct GNUNET_SQ_QueryParam -GNUNET_SQ_query_param_fixed_size(const void *ptr, - size_t ptr_size) +GNUNET_SQ_query_param_fixed_size (const void *ptr, + size_t ptr_size) { struct GNUNET_SQ_QueryParam qp = { .conv = &bind_fixed_blob, @@ -89,26 +89,26 @@ GNUNET_SQ_query_param_fixed_size(const void *ptr, * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ static int -bind_string(void *cls, - const void *data, - size_t data_len, - sqlite3_stmt *stmt, - unsigned int off) +bind_string (void *cls, + const void *data, + size_t data_len, + sqlite3_stmt *stmt, + unsigned int off) { if (NULL == data) - { - if (SQLITE_OK != - sqlite3_bind_null(stmt, - (int)off)) - return GNUNET_SYSERR; - return GNUNET_OK; - } + { + if (SQLITE_OK != + sqlite3_bind_null (stmt, + (int) off)) + return GNUNET_SYSERR; + return GNUNET_OK; + } if (SQLITE_OK != - sqlite3_bind_text(stmt, - (int)off, - (const char *)data, - -1, - SQLITE_TRANSIENT)) + sqlite3_bind_text (stmt, + (int) off, + (const char *) data, + -1, + SQLITE_TRANSIENT)) return GNUNET_SYSERR; return GNUNET_OK; } @@ -120,7 +120,7 @@ bind_string(void *cls, * @param ptr pointer to the string query parameter to pass */ struct GNUNET_SQ_QueryParam -GNUNET_SQ_query_param_string(const char *ptr) +GNUNET_SQ_query_param_string (const char *ptr) { struct GNUNET_SQ_QueryParam qp = { .conv = &bind_string, @@ -144,30 +144,30 @@ GNUNET_SQ_query_param_string(const char *ptr) * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ static int -bind_rsa_pub(void *cls, - const void *data, - size_t data_len, - sqlite3_stmt *stmt, - unsigned int off) +bind_rsa_pub (void *cls, + const void *data, + size_t data_len, + sqlite3_stmt *stmt, + unsigned int off) { const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data; char *buf; size_t buf_size; - GNUNET_break(NULL == cls); - buf_size = GNUNET_CRYPTO_rsa_public_key_encode(rsa, - &buf); + GNUNET_break (NULL == cls); + buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, + &buf); if (SQLITE_OK != - sqlite3_bind_blob64(stmt, - (int)off, - buf, - (sqlite3_uint64)buf_size, - SQLITE_TRANSIENT)) - { - GNUNET_free(buf); - return GNUNET_SYSERR; - } - GNUNET_free(buf); + sqlite3_bind_blob64 (stmt, + (int) off, + buf, + (sqlite3_uint64) buf_size, + SQLITE_TRANSIENT)) + { + GNUNET_free (buf); + return GNUNET_SYSERR; + } + GNUNET_free (buf); return GNUNET_OK; } @@ -179,7 +179,8 @@ bind_rsa_pub(void *cls, * @param x the query parameter to pass. */ struct GNUNET_SQ_QueryParam -GNUNET_SQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x) +GNUNET_SQ_query_param_rsa_public_key (const struct + GNUNET_CRYPTO_RsaPublicKey *x) { struct GNUNET_SQ_QueryParam qp = { .conv = &bind_rsa_pub, @@ -203,30 +204,30 @@ GNUNET_SQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x) * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ static int -bind_rsa_sig(void *cls, - const void *data, - size_t data_len, - sqlite3_stmt *stmt, - unsigned int off) +bind_rsa_sig (void *cls, + const void *data, + size_t data_len, + sqlite3_stmt *stmt, + unsigned int off) { const struct GNUNET_CRYPTO_RsaSignature *sig = data; char *buf; size_t buf_size; - GNUNET_break(NULL == cls); - buf_size = GNUNET_CRYPTO_rsa_signature_encode(sig, - &buf); + GNUNET_break (NULL == cls); + buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig, + &buf); if (SQLITE_OK != - sqlite3_bind_blob64(stmt, - (int)off, - buf, - (sqlite3_uint64)buf_size, - SQLITE_TRANSIENT)) - { - GNUNET_free(buf); - return GNUNET_SYSERR; - } - GNUNET_free(buf); + sqlite3_bind_blob64 (stmt, + (int) off, + buf, + (sqlite3_uint64) buf_size, + SQLITE_TRANSIENT)) + { + GNUNET_free (buf); + return GNUNET_SYSERR; + } + GNUNET_free (buf); return GNUNET_OK; } @@ -238,7 +239,7 @@ bind_rsa_sig(void *cls, * @param x the query parameter to pass */ struct GNUNET_SQ_QueryParam -GNUNET_SQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x) +GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) { struct GNUNET_SQ_QueryParam qp = { .conv = &bind_rsa_sig, @@ -262,11 +263,11 @@ GNUNET_SQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x) * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ static int -bind_abstime(void *cls, - const void *data, - size_t data_len, - sqlite3_stmt *stmt, - unsigned int off) +bind_abstime (void *cls, + const void *data, + size_t data_len, + sqlite3_stmt *stmt, + unsigned int off) { const struct GNUNET_TIME_Absolute *u = data; struct GNUNET_TIME_Absolute abs; @@ -274,11 +275,11 @@ bind_abstime(void *cls, abs = *u; if (abs.abs_value_us > INT64_MAX) abs.abs_value_us = INT64_MAX; - GNUNET_assert(sizeof(uint64_t) == data_len); + GNUNET_assert (sizeof(uint64_t) == data_len); if (SQLITE_OK != - sqlite3_bind_int64(stmt, - (int)off, - (sqlite3_int64)abs.abs_value_us)) + sqlite3_bind_int64 (stmt, + (int) off, + (sqlite3_int64) abs.abs_value_us)) return GNUNET_SYSERR; return GNUNET_OK; } @@ -291,7 +292,7 @@ bind_abstime(void *cls, * @param x pointer to the query parameter to pass */ struct GNUNET_SQ_QueryParam -GNUNET_SQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x) +GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) { struct GNUNET_SQ_QueryParam qp = { .conv = &bind_abstime, @@ -316,23 +317,23 @@ GNUNET_SQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x) * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ static int -bind_nbotime(void *cls, - const void *data, - size_t data_len, - sqlite3_stmt *stmt, - unsigned int off) +bind_nbotime (void *cls, + const void *data, + size_t data_len, + sqlite3_stmt *stmt, + unsigned int off) { const struct GNUNET_TIME_AbsoluteNBO *u = data; struct GNUNET_TIME_Absolute abs; - abs = GNUNET_TIME_absolute_ntoh(*u); + abs = GNUNET_TIME_absolute_ntoh (*u); if (abs.abs_value_us > INT64_MAX) abs.abs_value_us = INT64_MAX; - GNUNET_assert(sizeof(uint64_t) == data_len); + GNUNET_assert (sizeof(uint64_t) == data_len); if (SQLITE_OK != - sqlite3_bind_int64(stmt, - (int)off, - (sqlite3_int64)abs.abs_value_us)) + sqlite3_bind_int64 (stmt, + (int) off, + (sqlite3_int64) abs.abs_value_us)) return GNUNET_SYSERR; return GNUNET_OK; } @@ -345,7 +346,8 @@ bind_nbotime(void *cls, * @param x pointer to the query parameter to pass */ struct GNUNET_SQ_QueryParam -GNUNET_SQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x) +GNUNET_SQ_query_param_absolute_time_nbo (const struct + GNUNET_TIME_AbsoluteNBO *x) { struct GNUNET_SQ_QueryParam qp = { .conv = &bind_nbotime, @@ -370,19 +372,19 @@ GNUNET_SQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x) * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ static int -bind_u16(void *cls, - const void *data, - size_t data_len, - sqlite3_stmt *stmt, - unsigned int off) +bind_u16 (void *cls, + const void *data, + size_t data_len, + sqlite3_stmt *stmt, + unsigned int off) { const uint16_t *u = data; - GNUNET_assert(sizeof(uint16_t) == data_len); + GNUNET_assert (sizeof(uint16_t) == data_len); if (SQLITE_OK != - sqlite3_bind_int(stmt, - (int)off, - (int)*u)) + sqlite3_bind_int (stmt, + (int) off, + (int) *u)) return GNUNET_SYSERR; return GNUNET_OK; } @@ -394,7 +396,7 @@ bind_u16(void *cls, * @param x pointer to the query parameter to pass */ struct GNUNET_SQ_QueryParam -GNUNET_SQ_query_param_uint16(const uint16_t *x) +GNUNET_SQ_query_param_uint16 (const uint16_t *x) { struct GNUNET_SQ_QueryParam qp = { .conv = &bind_u16, @@ -419,19 +421,19 @@ GNUNET_SQ_query_param_uint16(const uint16_t *x) * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ static int -bind_u32(void *cls, - const void *data, - size_t data_len, - sqlite3_stmt *stmt, - unsigned int off) +bind_u32 (void *cls, + const void *data, + size_t data_len, + sqlite3_stmt *stmt, + unsigned int off) { const uint32_t *u = data; - GNUNET_assert(sizeof(uint32_t) == data_len); + GNUNET_assert (sizeof(uint32_t) == data_len); if (SQLITE_OK != - sqlite3_bind_int64(stmt, - (int)off, - (sqlite3_int64) * u)) + sqlite3_bind_int64 (stmt, + (int) off, + (sqlite3_int64) * u)) return GNUNET_SYSERR; return GNUNET_OK; } @@ -442,7 +444,7 @@ bind_u32(void *cls, * @param x pointer to the query parameter to pass */ struct GNUNET_SQ_QueryParam -GNUNET_SQ_query_param_uint32(const uint32_t *x) +GNUNET_SQ_query_param_uint32 (const uint32_t *x) { struct GNUNET_SQ_QueryParam qp = { .conv = &bind_u32, @@ -467,19 +469,19 @@ GNUNET_SQ_query_param_uint32(const uint32_t *x) * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ static int -bind_u64(void *cls, - const void *data, - size_t data_len, - sqlite3_stmt *stmt, - unsigned int off) +bind_u64 (void *cls, + const void *data, + size_t data_len, + sqlite3_stmt *stmt, + unsigned int off) { const uint64_t *u = data; - GNUNET_assert(sizeof(uint64_t) == data_len); + GNUNET_assert (sizeof(uint64_t) == data_len); if (SQLITE_OK != - sqlite3_bind_int64(stmt, - (int)off, - (sqlite3_int64) * u)) + sqlite3_bind_int64 (stmt, + (int) off, + (sqlite3_int64) * u)) return GNUNET_SYSERR; return GNUNET_OK; } @@ -491,7 +493,7 @@ bind_u64(void *cls, * @param x pointer to the query parameter to pass */ struct GNUNET_SQ_QueryParam -GNUNET_SQ_query_param_uint64(const uint64_t *x) +GNUNET_SQ_query_param_uint64 (const uint64_t *x) { struct GNUNET_SQ_QueryParam qp = { .conv = &bind_u64, diff --git a/src/sq/sq_result_helper.c b/src/sq/sq_result_helper.c index 6cef94326..5ea3f1e56 100644 --- a/src/sq/sq_result_helper.c +++ b/src/sq/sq_result_helper.c @@ -1,4 +1,3 @@ - /* This file is part of GNUnet Copyright (C) 2017 GNUnet e.V. @@ -40,53 +39,53 @@ * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) */ static int -extract_var_blob(void *cls, - sqlite3_stmt *result, - unsigned int column, - size_t *dst_size, - void *dst) +extract_var_blob (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) { int have; const void *ret; - void **rdst = (void **)dst; + void **rdst = (void **) dst; if (SQLITE_NULL == - sqlite3_column_type(result, - column)) - { - *rdst = NULL; - *dst_size = 0; - return GNUNET_YES; - } + sqlite3_column_type (result, + column)) + { + *rdst = NULL; + *dst_size = 0; + return GNUNET_YES; + } if (SQLITE_BLOB != - sqlite3_column_type(result, - column)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } /* sqlite manual says to invoke 'sqlite3_column_blob()' before calling sqlite3_column_bytes() */ - ret = sqlite3_column_blob(result, - column); - have = sqlite3_column_bytes(result, - column); + ret = sqlite3_column_blob (result, + column); + have = sqlite3_column_bytes (result, + column); if (have < 0) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } *dst_size = have; if (0 == have) - { - *rdst = NULL; - return GNUNET_OK; - } - *rdst = GNUNET_malloc(have); - GNUNET_memcpy(*rdst, - ret, - have); + { + *rdst = NULL; + return GNUNET_OK; + } + *rdst = GNUNET_malloc (have); + GNUNET_memcpy (*rdst, + ret, + have); return GNUNET_OK; } @@ -97,15 +96,15 @@ extract_var_blob(void *cls, * @param cls pointer to pointer of allocation */ static void -clean_var_blob(void *cls) +clean_var_blob (void *cls) { - void **dptr = (void **)cls; + void **dptr = (void **) cls; if (NULL != *dptr) - { - GNUNET_free(*dptr); - *dptr = NULL; - } + { + GNUNET_free (*dptr); + *dptr = NULL; + } } @@ -117,8 +116,8 @@ clean_var_blob(void *cls) * @return array entry for the result specification to use */ struct GNUNET_SQ_ResultSpec -GNUNET_SQ_result_spec_variable_size(void **dst, - size_t *sptr) +GNUNET_SQ_result_spec_variable_size (void **dst, + size_t *sptr) { struct GNUNET_SQ_ResultSpec rs = { .conv = &extract_var_blob, @@ -146,44 +145,44 @@ GNUNET_SQ_result_spec_variable_size(void **dst, * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) */ static int -extract_fixed_blob(void *cls, - sqlite3_stmt *result, - unsigned int column, - size_t *dst_size, - void *dst) +extract_fixed_blob (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) { int have; const void *ret; if ((0 == *dst_size) && (SQLITE_NULL == - sqlite3_column_type(result, - column))) - { - return GNUNET_YES; - } + sqlite3_column_type (result, + column))) + { + return GNUNET_YES; + } if (SQLITE_BLOB != - sqlite3_column_type(result, - column)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } /* sqlite manual says to invoke 'sqlite3_column_blob()' before calling sqlite3_column_bytes() */ - ret = sqlite3_column_blob(result, - column); - have = sqlite3_column_bytes(result, - column); + ret = sqlite3_column_blob (result, + column); + have = sqlite3_column_bytes (result, + column); if (*dst_size != have) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - GNUNET_memcpy(dst, - ret, - have); + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + GNUNET_memcpy (dst, + ret, + have); return GNUNET_OK; } @@ -196,8 +195,8 @@ extract_fixed_blob(void *cls, * @return array entry for the result specification to use */ struct GNUNET_SQ_ResultSpec -GNUNET_SQ_result_spec_fixed_size(void *dst, - size_t dst_size) +GNUNET_SQ_result_spec_fixed_size (void *dst, + size_t dst_size) { struct GNUNET_SQ_ResultSpec rs = { .conv = &extract_fixed_blob, @@ -223,40 +222,40 @@ GNUNET_SQ_result_spec_fixed_size(void *dst, * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) */ static int -extract_utf8_string(void *cls, - sqlite3_stmt *result, - unsigned int column, - size_t *dst_size, - void *dst) +extract_utf8_string (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) { const char *text; char **rdst = dst; if (SQLITE_NULL == - sqlite3_column_type(result, - column)) - { - *rdst = NULL; - return GNUNET_OK; - } + sqlite3_column_type (result, + column)) + { + *rdst = NULL; + return GNUNET_OK; + } if (SQLITE_TEXT != - sqlite3_column_type(result, - column)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } /* sqlite manual guarantees that 'sqlite3_column_text()' is 0-terminated */ - text = (const char *)sqlite3_column_text(result, - column); + text = (const char *) sqlite3_column_text (result, + column); if (NULL == text) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - *dst_size = strlen(text) + 1; - *rdst = GNUNET_strdup(text); + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + *dst_size = strlen (text) + 1; + *rdst = GNUNET_strdup (text); return GNUNET_OK; } @@ -267,15 +266,15 @@ extract_utf8_string(void *cls, * @param cls pointer to pointer of allocation */ static void -clean_utf8_string(void *cls) +clean_utf8_string (void *cls) { - char **dptr = (char **)cls; + char **dptr = (char **) cls; if (NULL != *dptr) - { - GNUNET_free(*dptr); - *dptr = NULL; - } + { + GNUNET_free (*dptr); + *dptr = NULL; + } } @@ -286,7 +285,7 @@ clean_utf8_string(void *cls) * @return array entry for the result specification to use */ struct GNUNET_SQ_ResultSpec -GNUNET_SQ_result_spec_string(char **dst) +GNUNET_SQ_result_spec_string (char **dst) { struct GNUNET_SQ_ResultSpec rs = { .conv = &extract_utf8_string, @@ -313,42 +312,42 @@ GNUNET_SQ_result_spec_string(char **dst) * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) */ static int -extract_rsa_pub(void *cls, - sqlite3_stmt *result, - unsigned int column, - size_t *dst_size, - void *dst) +extract_rsa_pub (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) { struct GNUNET_CRYPTO_RsaPublicKey **pk = dst; int have; const void *ret; if (SQLITE_BLOB != - sqlite3_column_type(result, - column)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } /* sqlite manual says to invoke 'sqlite3_column_blob()' before calling sqlite3_column_bytes() */ - ret = sqlite3_column_blob(result, - column); - have = sqlite3_column_bytes(result, - column); + ret = sqlite3_column_blob (result, + column); + have = sqlite3_column_bytes (result, + column); if (have < 0) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } - *pk = GNUNET_CRYPTO_rsa_public_key_decode(ret, - have); + *pk = GNUNET_CRYPTO_rsa_public_key_decode (ret, + have); if (NULL == *pk) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -360,15 +359,15 @@ extract_rsa_pub(void *cls, * @param cls closure */ static void -clean_rsa_pub(void *cls) +clean_rsa_pub (void *cls) { struct GNUNET_CRYPTO_RsaPublicKey **pk = cls; if (NULL != *pk) - { - GNUNET_CRYPTO_rsa_public_key_free(*pk); - *pk = NULL; - } + { + GNUNET_CRYPTO_rsa_public_key_free (*pk); + *pk = NULL; + } } @@ -379,7 +378,7 @@ clean_rsa_pub(void *cls) * @return array entry for the result specification to use */ struct GNUNET_SQ_ResultSpec -GNUNET_SQ_result_spec_rsa_public_key(struct GNUNET_CRYPTO_RsaPublicKey **rsa) +GNUNET_SQ_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa) { struct GNUNET_SQ_ResultSpec rs = { .conv = &extract_rsa_pub, @@ -406,42 +405,42 @@ GNUNET_SQ_result_spec_rsa_public_key(struct GNUNET_CRYPTO_RsaPublicKey **rsa) * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) */ static int -extract_rsa_sig(void *cls, - sqlite3_stmt *result, - unsigned int column, - size_t *dst_size, - void *dst) +extract_rsa_sig (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) { struct GNUNET_CRYPTO_RsaSignature **sig = dst; int have; const void *ret; if (SQLITE_BLOB != - sqlite3_column_type(result, - column)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } /* sqlite manual says to invoke 'sqlite3_column_blob()' before calling sqlite3_column_bytes() */ - ret = sqlite3_column_blob(result, - column); - have = sqlite3_column_bytes(result, - column); + ret = sqlite3_column_blob (result, + column); + have = sqlite3_column_bytes (result, + column); if (have < 0) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } - *sig = GNUNET_CRYPTO_rsa_signature_decode(ret, - have); + *sig = GNUNET_CRYPTO_rsa_signature_decode (ret, + have); if (NULL == *sig) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -453,15 +452,15 @@ extract_rsa_sig(void *cls, * @param cls result data to clean up */ static void -clean_rsa_sig(void *cls) +clean_rsa_sig (void *cls) { struct GNUNET_CRYPTO_RsaSignature **sig = cls; if (NULL != *sig) - { - GNUNET_CRYPTO_rsa_signature_free(*sig); - *sig = NULL; - } + { + GNUNET_CRYPTO_rsa_signature_free (*sig); + *sig = NULL; + } } @@ -472,7 +471,7 @@ clean_rsa_sig(void *cls) * @return array entry for the result specification to use */ struct GNUNET_SQ_ResultSpec -GNUNET_SQ_result_spec_rsa_signature(struct GNUNET_CRYPTO_RsaSignature **sig) +GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig) { struct GNUNET_SQ_ResultSpec rs = { .conv = &extract_rsa_sig, @@ -499,25 +498,25 @@ GNUNET_SQ_result_spec_rsa_signature(struct GNUNET_CRYPTO_RsaSignature **sig) * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) */ static int -extract_abs_time(void *cls, - sqlite3_stmt *result, - unsigned int column, - size_t *dst_size, - void *dst) +extract_abs_time (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) { struct GNUNET_TIME_Absolute *u = dst; struct GNUNET_TIME_Absolute t; - GNUNET_assert(sizeof(uint64_t) == *dst_size); + GNUNET_assert (sizeof(uint64_t) == *dst_size); if (SQLITE_INTEGER != - sqlite3_column_type(result, - column)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - t.abs_value_us = (uint64_t)sqlite3_column_int64(result, - column); + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + t.abs_value_us = (uint64_t) sqlite3_column_int64 (result, + column); if (INT64_MAX == t.abs_value_us) t = GNUNET_TIME_UNIT_FOREVER_ABS; *u = t; @@ -532,7 +531,7 @@ extract_abs_time(void *cls, * @return array entry for the result specification to use */ struct GNUNET_SQ_ResultSpec -GNUNET_SQ_result_spec_absolute_time(struct GNUNET_TIME_Absolute *at) +GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at) { struct GNUNET_SQ_ResultSpec rs = { .conv = &extract_abs_time, @@ -558,28 +557,28 @@ GNUNET_SQ_result_spec_absolute_time(struct GNUNET_TIME_Absolute *at) * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) */ static int -extract_abs_time_nbo(void *cls, - sqlite3_stmt *result, - unsigned int column, - size_t *dst_size, - void *dst) +extract_abs_time_nbo (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) { struct GNUNET_TIME_AbsoluteNBO *u = dst; struct GNUNET_TIME_Absolute t; - GNUNET_assert(sizeof(uint64_t) == *dst_size); + GNUNET_assert (sizeof(uint64_t) == *dst_size); if (SQLITE_INTEGER != - sqlite3_column_type(result, - column)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - t.abs_value_us = (uint64_t)sqlite3_column_int64(result, - column); + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + t.abs_value_us = (uint64_t) sqlite3_column_int64 (result, + column); if (INT64_MAX == t.abs_value_us) t = GNUNET_TIME_UNIT_FOREVER_ABS; - *u = GNUNET_TIME_absolute_hton(t); + *u = GNUNET_TIME_absolute_hton (t); return GNUNET_OK; } @@ -591,7 +590,7 @@ extract_abs_time_nbo(void *cls, * @return array entry for the result specification to use */ struct GNUNET_SQ_ResultSpec -GNUNET_SQ_result_spec_absolute_time_nbo(struct GNUNET_TIME_AbsoluteNBO *at) +GNUNET_SQ_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at) { struct GNUNET_SQ_ResultSpec rs = { .conv = &extract_abs_time_nbo, @@ -617,31 +616,31 @@ GNUNET_SQ_result_spec_absolute_time_nbo(struct GNUNET_TIME_AbsoluteNBO *at) * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) */ static int -extract_uint16(void *cls, - sqlite3_stmt *result, - unsigned int column, - size_t *dst_size, - void *dst) +extract_uint16 (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) { uint64_t v; uint16_t *u = dst; - GNUNET_assert(sizeof(uint16_t) == *dst_size); + GNUNET_assert (sizeof(uint16_t) == *dst_size); if (SQLITE_INTEGER != - sqlite3_column_type(result, - column)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - v = (uint64_t)sqlite3_column_int64(result, - column); + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + v = (uint64_t) sqlite3_column_int64 (result, + column); if (v > UINT16_MAX) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - *u = (uint16_t)v; + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + *u = (uint16_t) v; return GNUNET_OK; } @@ -653,7 +652,7 @@ extract_uint16(void *cls, * @return array entry for the result specification to use */ struct GNUNET_SQ_ResultSpec -GNUNET_SQ_result_spec_uint16(uint16_t *u16) +GNUNET_SQ_result_spec_uint16 (uint16_t *u16) { struct GNUNET_SQ_ResultSpec rs = { .conv = &extract_uint16, @@ -679,31 +678,31 @@ GNUNET_SQ_result_spec_uint16(uint16_t *u16) * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) */ static int -extract_uint32(void *cls, - sqlite3_stmt *result, - unsigned int column, - size_t *dst_size, - void *dst) +extract_uint32 (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) { uint64_t v; uint32_t *u = dst; - GNUNET_assert(sizeof(uint32_t) == *dst_size); + GNUNET_assert (sizeof(uint32_t) == *dst_size); if (SQLITE_INTEGER != - sqlite3_column_type(result, - column)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - v = (uint64_t)sqlite3_column_int64(result, - column); + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + v = (uint64_t) sqlite3_column_int64 (result, + column); if (v > UINT32_MAX) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - *u = (uint32_t)v; + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + *u = (uint32_t) v; return GNUNET_OK; } @@ -715,7 +714,7 @@ extract_uint32(void *cls, * @return array entry for the result specification to use */ struct GNUNET_SQ_ResultSpec -GNUNET_SQ_result_spec_uint32(uint32_t *u32) +GNUNET_SQ_result_spec_uint32 (uint32_t *u32) { struct GNUNET_SQ_ResultSpec rs = { .conv = &extract_uint32, @@ -741,24 +740,24 @@ GNUNET_SQ_result_spec_uint32(uint32_t *u32) * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) */ static int -extract_uint64(void *cls, - sqlite3_stmt *result, - unsigned int column, - size_t *dst_size, - void *dst) +extract_uint64 (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) { uint64_t *u = dst; - GNUNET_assert(sizeof(uint64_t) == *dst_size); + GNUNET_assert (sizeof(uint64_t) == *dst_size); if (SQLITE_INTEGER != - sqlite3_column_type(result, - column)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - *u = (uint64_t)sqlite3_column_int64(result, - column); + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + *u = (uint64_t) sqlite3_column_int64 (result, + column); return GNUNET_OK; } @@ -770,7 +769,7 @@ extract_uint64(void *cls, * @return array entry for the result specification to use */ struct GNUNET_SQ_ResultSpec -GNUNET_SQ_result_spec_uint64(uint64_t *u64) +GNUNET_SQ_result_spec_uint64 (uint64_t *u64) { struct GNUNET_SQ_ResultSpec rs = { .conv = &extract_uint64, diff --git a/src/sq/test_sq.c b/src/sq/test_sq.c index 4c81bd5c3..e5187b55a 100644 --- a/src/sq/test_sq.c +++ b/src/sq/test_sq.c @@ -36,23 +36,23 @@ * @return 0 on success */ static int -sq_prepare(sqlite3 *dbh, - const char *zSql, - sqlite3_stmt **ppStmt) +sq_prepare (sqlite3 *dbh, + const char *zSql, + sqlite3_stmt **ppStmt) { char *dummy; int result; - result = sqlite3_prepare_v2(dbh, - zSql, - strlen(zSql), - ppStmt, - (const char **)&dummy); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Prepared `%s' / %p: %d\n", - zSql, - *ppStmt, - result); + result = sqlite3_prepare_v2 (dbh, + zSql, + strlen (zSql), + ppStmt, + (const char **) &dummy); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Prepared `%s' / %p: %d\n", + zSql, + *ppStmt, + result); return result; } @@ -63,13 +63,13 @@ sq_prepare(sqlite3 *dbh, * @return 0 on success */ static int -run_queries(sqlite3 *dbh) +run_queries (sqlite3 *dbh) { 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; @@ -88,199 +88,199 @@ run_queries(sqlite3 *dbh) 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_SQ_result_spec_variable_size */ - sq_prepare(dbh, - "INSERT INTO test_sq (" - " pub" - ",sig" - ",abs_time" - ",forever" - ",hash" - ",vsize" - ",u16" - ",u32" - ",u64" - ") VALUES " - "($1, $2, $3, $4, $5, $6," - "$7, $8, $9);", - &stmt); + sq_prepare (dbh, + "INSERT INTO test_sq (" + " pub" + ",sig" + ",abs_time" + ",forever" + ",hash" + ",vsize" + ",u16" + ",u32" + ",u64" + ") VALUES " + "($1, $2, $3, $4, $5, $6," + "$7, $8, $9);", + &stmt); { struct GNUNET_SQ_QueryParam params_insert[] = { - GNUNET_SQ_query_param_rsa_public_key(pub), - GNUNET_SQ_query_param_rsa_signature(sig), - GNUNET_SQ_query_param_absolute_time(&abs_time), - GNUNET_SQ_query_param_absolute_time(&forever), - GNUNET_SQ_query_param_auto_from_type(&hc), - GNUNET_SQ_query_param_fixed_size(msg, strlen(msg)), - GNUNET_SQ_query_param_uint16(&u16), - GNUNET_SQ_query_param_uint32(&u32), - GNUNET_SQ_query_param_uint64(&u64), + GNUNET_SQ_query_param_rsa_public_key (pub), + GNUNET_SQ_query_param_rsa_signature (sig), + GNUNET_SQ_query_param_absolute_time (&abs_time), + GNUNET_SQ_query_param_absolute_time (&forever), + GNUNET_SQ_query_param_auto_from_type (&hc), + GNUNET_SQ_query_param_fixed_size (msg, strlen (msg)), + GNUNET_SQ_query_param_uint16 (&u16), + GNUNET_SQ_query_param_uint32 (&u32), + GNUNET_SQ_query_param_uint64 (&u64), GNUNET_SQ_query_param_end }; - GNUNET_assert(GNUNET_OK == - GNUNET_SQ_bind(stmt, - params_insert)); + GNUNET_assert (GNUNET_OK == + GNUNET_SQ_bind (stmt, + params_insert)); if (SQLITE_DONE != - sqlite3_step(stmt)) - { - GNUNET_CRYPTO_rsa_signature_free(sig); - GNUNET_CRYPTO_rsa_private_key_free(priv); - GNUNET_CRYPTO_rsa_public_key_free(pub); - return 1; - } + sqlite3_step (stmt)) + { + GNUNET_CRYPTO_rsa_signature_free (sig); + GNUNET_CRYPTO_rsa_private_key_free (priv); + GNUNET_CRYPTO_rsa_public_key_free (pub); + return 1; + } } - sqlite3_finalize(stmt); + sqlite3_finalize (stmt); - sq_prepare(dbh, - "SELECT" - " pub" - ",sig" - ",abs_time" - ",forever" - ",hash" - ",vsize" - ",u16" - ",u32" - ",u64" - " FROM test_sq" - " ORDER BY abs_time DESC " - " LIMIT 1;", - &stmt); + sq_prepare (dbh, + "SELECT" + " pub" + ",sig" + ",abs_time" + ",forever" + ",hash" + ",vsize" + ",u16" + ",u32" + ",u64" + " FROM test_sq" + " ORDER BY abs_time DESC " + " LIMIT 1;", + &stmt); { struct GNUNET_SQ_QueryParam params_select[] = { GNUNET_SQ_query_param_end }; struct GNUNET_SQ_ResultSpec results_select[] = { - GNUNET_SQ_result_spec_rsa_public_key(&pub2), - GNUNET_SQ_result_spec_rsa_signature(&sig2), - GNUNET_SQ_result_spec_absolute_time(&abs_time2), - GNUNET_SQ_result_spec_absolute_time(&forever2), - GNUNET_SQ_result_spec_auto_from_type(&hc2), - GNUNET_SQ_result_spec_variable_size(&msg2, &msg2_len), - GNUNET_SQ_result_spec_uint16(&u162), - GNUNET_SQ_result_spec_uint32(&u322), - GNUNET_SQ_result_spec_uint64(&u642), + GNUNET_SQ_result_spec_rsa_public_key (&pub2), + GNUNET_SQ_result_spec_rsa_signature (&sig2), + GNUNET_SQ_result_spec_absolute_time (&abs_time2), + GNUNET_SQ_result_spec_absolute_time (&forever2), + GNUNET_SQ_result_spec_auto_from_type (&hc2), + GNUNET_SQ_result_spec_variable_size (&msg2, &msg2_len), + GNUNET_SQ_result_spec_uint16 (&u162), + GNUNET_SQ_result_spec_uint32 (&u322), + GNUNET_SQ_result_spec_uint64 (&u642), GNUNET_SQ_result_spec_end }; - GNUNET_assert(GNUNET_OK == - GNUNET_SQ_bind(stmt, - params_select)); + GNUNET_assert (GNUNET_OK == + GNUNET_SQ_bind (stmt, + params_select)); if (SQLITE_ROW != - sqlite3_step(stmt)) - { - GNUNET_break(0); - sqlite3_finalize(stmt); - GNUNET_CRYPTO_rsa_signature_free(sig); - GNUNET_CRYPTO_rsa_private_key_free(priv); - GNUNET_CRYPTO_rsa_public_key_free(pub); - return 1; - } - GNUNET_assert(GNUNET_OK == - GNUNET_SQ_extract_result(stmt, - results_select)); - 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_SQ_cleanup_result(results_select); + sqlite3_step (stmt)) + { + GNUNET_break (0); + sqlite3_finalize (stmt); + GNUNET_CRYPTO_rsa_signature_free (sig); + GNUNET_CRYPTO_rsa_private_key_free (priv); + GNUNET_CRYPTO_rsa_public_key_free (pub); + return 1; + } + GNUNET_assert (GNUNET_OK == + GNUNET_SQ_extract_result (stmt, + results_select)); + 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_SQ_cleanup_result (results_select); } - sqlite3_finalize(stmt); + sqlite3_finalize (stmt); - 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); return 0; } int -main(int argc, - const char *const argv[]) +main (int argc, + const char *const argv[]) { sqlite3 *dbh; int ret; - GNUNET_log_setup("test-sq", - "WARNING", - NULL); + GNUNET_log_setup ("test-sq", + "WARNING", + NULL); if (SQLITE_OK != - sqlite3_open("test.db", - &dbh)) - { - fprintf(stderr, - "Cannot run test, sqlite3 initialization failed\n"); - GNUNET_break(0); - return 77; /* Signal test was skipped... */ - } + sqlite3_open ("test.db", + &dbh)) + { + fprintf (stderr, + "Cannot run test, sqlite3 initialization failed\n"); + GNUNET_break (0); + return 77; /* Signal test was skipped... */ + } if (SQLITE_OK != - sqlite3_exec(dbh, - "CREATE TEMPORARY TABLE IF NOT EXISTS test_sq (" - " pub BYTEA NOT NULL" - ",sig BYTEA NOT NULL" - ",abs_time INT8 NOT NULL" - ",forever INT8 NOT NULL" - ",hash BYTEA NOT NULL" - ",vsize VARCHAR NOT NULL" - ",u16 INT2 NOT NULL" - ",u32 INT4 NOT NULL" - ",u64 INT8 NOT NULL" - ")", - NULL, NULL, NULL)) - { - fprintf(stderr, - "Failed to create table\n"); - GNUNET_break(SQLITE_OK == - sqlite3_close(dbh)); - if (0 != unlink("test.db")) - GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, - "unlink", - "test.db"); - return 1; - } + sqlite3_exec (dbh, + "CREATE TEMPORARY TABLE IF NOT EXISTS test_sq (" + " pub BYTEA NOT NULL" + ",sig BYTEA NOT NULL" + ",abs_time INT8 NOT NULL" + ",forever INT8 NOT NULL" + ",hash BYTEA NOT NULL" + ",vsize VARCHAR NOT NULL" + ",u16 INT2 NOT NULL" + ",u32 INT4 NOT NULL" + ",u64 INT8 NOT NULL" + ")", + NULL, NULL, NULL)) + { + fprintf (stderr, + "Failed to create table\n"); + GNUNET_break (SQLITE_OK == + sqlite3_close (dbh)); + if (0 != unlink ("test.db")) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, + "unlink", + "test.db"); + return 1; + } - ret = run_queries(dbh); + ret = run_queries (dbh); if (SQLITE_OK != - sqlite3_exec(dbh, - "DROP TABLE test_sq", - NULL, NULL, NULL)) - { - fprintf(stderr, - "Failed to drop table\n"); - ret = 1; - } - GNUNET_break(SQLITE_OK == - sqlite3_close(dbh)); - if (0 != unlink("test.db")) - GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, - "unlink", - "test.db"); + sqlite3_exec (dbh, + "DROP TABLE test_sq", + NULL, NULL, NULL)) + { + fprintf (stderr, + "Failed to drop table\n"); + ret = 1; + } + GNUNET_break (SQLITE_OK == + sqlite3_close (dbh)); + if (0 != unlink ("test.db")) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, + "unlink", + "test.db"); return ret; } -- cgit v1.2.3