aboutsummaryrefslogtreecommitdiff
path: root/src/sq
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/sq
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/sq')
-rw-r--r--src/sq/sq.c134
-rw-r--r--src/sq/sq_exec.c94
-rw-r--r--src/sq/sq_prepare.c72
-rw-r--r--src/sq/sq_query_helper.c305
-rw-r--r--src/sq/sq_result_helper.c550
-rw-r--r--src/sq/test_sq.c364
6 files changed, 764 insertions, 755 deletions
diff --git a/src/sq/sq.c b/src/sq/sq.c
index e74071b81..6fce01322 100644
--- a/src/sq/sq.c
+++ b/src/sq/sq.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2017 GNUnet e.V. 3 Copyright (C) 2017 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file sq/sq.c 21 * @file sq/sq.c
22 * @brief helper functions for Sqlite3 DB interactions 22 * @brief helper functions for Sqlite3 DB interactions
@@ -34,37 +34,37 @@
34 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 34 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
35 */ 35 */
36int 36int
37GNUNET_SQ_bind (sqlite3_stmt *stmt, 37GNUNET_SQ_bind(sqlite3_stmt *stmt,
38 const struct GNUNET_SQ_QueryParam *params) 38 const struct GNUNET_SQ_QueryParam *params)
39{ 39{
40 unsigned int j; 40 unsigned int j;
41 41
42 j = 1; 42 j = 1;
43 for (unsigned int i=0;NULL != params[i].conv; i++) 43 for (unsigned int i = 0; NULL != params[i].conv; i++)
44 {
45 if (GNUNET_OK !=
46 params[i].conv (params[i].conv_cls,
47 params[i].data,
48 params[i].size,
49 stmt,
50 j))
51 { 44 {
52 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 45 if (GNUNET_OK !=
53 "sq", 46 params[i].conv(params[i].conv_cls,
54 _("Failure to bind %u-th SQL parameter\n"), 47 params[i].data,
55 i); 48 params[i].size,
56 if (SQLITE_OK != 49 stmt,
57 sqlite3_reset (stmt)) 50 j))
58 { 51 {
59 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 52 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING,
60 "sq", 53 "sq",
61 _("Failure in sqlite3_reset (!)\n")); 54 _("Failure to bind %u-th SQL parameter\n"),
62 return GNUNET_SYSERR; 55 i);
63 } 56 if (SQLITE_OK !=
57 sqlite3_reset(stmt))
58 {
59 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING,
60 "sq",
61 _("Failure in sqlite3_reset (!)\n"));
62 return GNUNET_SYSERR;
63 }
64 }
65 GNUNET_assert(0 != params[i].num_params);
66 j += params[i].num_params;
64 } 67 }
65 GNUNET_assert (0 != params[i].num_params);
66 j += params[i].num_params;
67 }
68 return GNUNET_OK; 68 return GNUNET_OK;
69} 69}
70 70
@@ -79,30 +79,30 @@ GNUNET_SQ_bind (sqlite3_stmt *stmt,
79 * #GNUNET_SYSERR if a result was invalid (non-existing field) 79 * #GNUNET_SYSERR if a result was invalid (non-existing field)
80 */ 80 */
81int 81int
82GNUNET_SQ_extract_result (sqlite3_stmt *result, 82GNUNET_SQ_extract_result(sqlite3_stmt *result,
83 struct GNUNET_SQ_ResultSpec *rs) 83 struct GNUNET_SQ_ResultSpec *rs)
84{ 84{
85 unsigned int j = 0; 85 unsigned int j = 0;
86 86
87 for (unsigned int i=0;NULL != rs[i].conv; i++) 87 for (unsigned int i = 0; NULL != rs[i].conv; i++)
88 {
89 if (NULL == rs[i].result_size)
90 rs[i].result_size = &rs[i].dst_size;
91 if (GNUNET_OK !=
92 rs[i].conv (rs[i].cls,
93 result,
94 j,
95 rs[i].result_size,
96 rs[i].dst))
97 { 88 {
98 for (unsigned int k=0;k<i;k++) 89 if (NULL == rs[i].result_size)
99 if (NULL != rs[k].cleaner) 90 rs[i].result_size = &rs[i].dst_size;
100 rs[k].cleaner (rs[k].cls); 91 if (GNUNET_OK !=
101 return GNUNET_SYSERR; 92 rs[i].conv(rs[i].cls,
93 result,
94 j,
95 rs[i].result_size,
96 rs[i].dst))
97 {
98 for (unsigned int k = 0; k < i; k++)
99 if (NULL != rs[k].cleaner)
100 rs[k].cleaner(rs[k].cls);
101 return GNUNET_SYSERR;
102 }
103 GNUNET_assert(0 != rs[i].num_params);
104 j += rs[i].num_params;
102 } 105 }
103 GNUNET_assert (0 != rs[i].num_params);
104 j += rs[i].num_params;
105 }
106 return GNUNET_OK; 106 return GNUNET_OK;
107} 107}
108 108
@@ -114,11 +114,11 @@ GNUNET_SQ_extract_result (sqlite3_stmt *result,
114 * @param rs reult specification to clean up 114 * @param rs reult specification to clean up
115 */ 115 */
116void 116void
117GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs) 117GNUNET_SQ_cleanup_result(struct GNUNET_SQ_ResultSpec *rs)
118{ 118{
119 for (unsigned int i=0;NULL != rs[i].conv; i++) 119 for (unsigned int i = 0; NULL != rs[i].conv; i++)
120 if (NULL != rs[i].cleaner) 120 if (NULL != rs[i].cleaner)
121 rs[i].cleaner (rs[i].cls); 121 rs[i].cleaner(rs[i].cls);
122} 122}
123 123
124 124
@@ -129,15 +129,15 @@ GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs)
129 * @param stmt statement to reset 129 * @param stmt statement to reset
130 */ 130 */
131void 131void
132GNUNET_SQ_reset (sqlite3 *dbh, 132GNUNET_SQ_reset(sqlite3 *dbh,
133 sqlite3_stmt *stmt) 133 sqlite3_stmt *stmt)
134{ 134{
135 if (SQLITE_OK != 135 if (SQLITE_OK !=
136 sqlite3_reset (stmt)) 136 sqlite3_reset(stmt))
137 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 137 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
138 "sqlite", 138 "sqlite",
139 _("Failed to reset sqlite statement with error: %s\n"), 139 _("Failed to reset sqlite statement with error: %s\n"),
140 sqlite3_errmsg (dbh)); 140 sqlite3_errmsg(dbh));
141} 141}
142 142
143 143
diff --git a/src/sq/sq_exec.c b/src/sq/sq_exec.c
index 325dfa014..ebc159421 100644
--- a/src/sq/sq_exec.c
+++ b/src/sq/sq_exec.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2018 GNUnet e.V. 3 Copyright (C) 2018 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file sq/sq_exec.c 21 * @file sq/sq_exec.c
22 * @brief helper functions for executing SQL statements 22 * @brief helper functions for executing SQL statements
@@ -33,8 +33,8 @@
33 * @return initialized struct 33 * @return initialized struct
34 */ 34 */
35struct GNUNET_SQ_ExecuteStatement 35struct GNUNET_SQ_ExecuteStatement
36GNUNET_SQ_make_execute (const char *sql) 36GNUNET_SQ_make_execute(const char *sql)
37 { 37{
38 struct GNUNET_SQ_ExecuteStatement es = { 38 struct GNUNET_SQ_ExecuteStatement es = {
39 .sql = sql, 39 .sql = sql,
40 .ignore_errors = GNUNET_NO 40 .ignore_errors = GNUNET_NO
@@ -53,7 +53,7 @@ GNUNET_SQ_make_execute (const char *sql)
53 * @return initialized struct 53 * @return initialized struct
54 */ 54 */
55struct GNUNET_SQ_ExecuteStatement 55struct GNUNET_SQ_ExecuteStatement
56GNUNET_SQ_make_try_execute (const char *sql) 56GNUNET_SQ_make_try_execute(const char *sql)
57{ 57{
58 struct GNUNET_SQ_ExecuteStatement es = { 58 struct GNUNET_SQ_ExecuteStatement es = {
59 .sql = sql, 59 .sql = sql,
@@ -74,39 +74,39 @@ GNUNET_SQ_make_try_execute (const char *sql)
74 * #GNUNET_SYSERR on error 74 * #GNUNET_SYSERR on error
75 */ 75 */
76int 76int
77GNUNET_SQ_exec_statements (sqlite3 *dbh, 77GNUNET_SQ_exec_statements(sqlite3 *dbh,
78 const struct GNUNET_SQ_ExecuteStatement *es) 78 const struct GNUNET_SQ_ExecuteStatement *es)
79{ 79{
80 for (unsigned int i=0;NULL != es[i].sql;i++) 80 for (unsigned int i = 0; NULL != es[i].sql; i++)
81 {
82 char *emsg = NULL;
83
84 if (SQLITE_OK !=
85 sqlite3_exec (dbh,
86 es[i].sql,
87 NULL,
88 NULL,
89 &emsg))
90 { 81 {
91 if (es[i].ignore_errors) 82 char *emsg = NULL;
92 { 83
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 84 if (SQLITE_OK !=
94 "Failed to run SQL `%s': %s\n", 85 sqlite3_exec(dbh,
95 es[i].sql, 86 es[i].sql,
96 emsg); 87 NULL,
97 } 88 NULL,
98 else 89 &emsg))
99 { 90 {
100 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 91 if (es[i].ignore_errors)
101 "Failed to run SQL `%s': %s\n", 92 {
102 es[i].sql, 93 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
103 emsg); 94 "Failed to run SQL `%s': %s\n",
104 sqlite3_free (emsg); 95 es[i].sql,
105 return GNUNET_SYSERR; 96 emsg);
106 } 97 }
107 sqlite3_free (emsg); 98 else
99 {
100 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
101 "Failed to run SQL `%s': %s\n",
102 es[i].sql,
103 emsg);
104 sqlite3_free(emsg);
105 return GNUNET_SYSERR;
106 }
107 sqlite3_free(emsg);
108 }
108 } 109 }
109 }
110 return GNUNET_OK; 110 return GNUNET_OK;
111} 111}
112 112
diff --git a/src/sq/sq_prepare.c b/src/sq/sq_prepare.c
index ab5ee09f5..3df4b80bc 100644
--- a/src/sq/sq_prepare.c
+++ b/src/sq/sq_prepare.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2018 GNUnet e.V. 3 Copyright (C) 2018 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file sq/sq_prepare.c 21 * @file sq/sq_prepare.c
22 * @brief helper functions for executing SQL statements 22 * @brief helper functions for executing SQL statements
@@ -34,8 +34,8 @@
34 * @return initialized struct 34 * @return initialized struct
35 */ 35 */
36struct GNUNET_SQ_PrepareStatement 36struct GNUNET_SQ_PrepareStatement
37GNUNET_SQ_make_prepare (const char *sql, 37GNUNET_SQ_make_prepare(const char *sql,
38 sqlite3_stmt **pstmt) 38 sqlite3_stmt **pstmt)
39{ 39{
40 struct GNUNET_SQ_PrepareStatement ps = { 40 struct GNUNET_SQ_PrepareStatement ps = {
41 .sql = sql, 41 .sql = sql,
@@ -56,29 +56,29 @@ GNUNET_SQ_make_prepare (const char *sql,
56 * @return #GNUNET_OK on success 56 * @return #GNUNET_OK on success
57 */ 57 */
58int 58int
59GNUNET_SQ_prepare (sqlite3 *dbh, 59GNUNET_SQ_prepare(sqlite3 *dbh,
60 const struct GNUNET_SQ_PrepareStatement *ps) 60 const struct GNUNET_SQ_PrepareStatement *ps)
61{ 61{
62 for (unsigned int i=0;NULL != ps[i].sql;i++) 62 for (unsigned int i = 0; NULL != ps[i].sql; i++)
63 {
64 const char *epos = NULL;
65 int ret;
66
67 if (SQLITE_OK !=
68 (ret = sqlite3_prepare_v2 (dbh,
69 ps[i].sql,
70 strlen (ps[i].sql),
71 ps[i].pstmt,
72 &epos)))
73 { 63 {
74 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 64 const char *epos = NULL;
75 "Failed to prepare SQL `%s': error %d at %s\n", 65 int ret;
76 ps[i].sql, 66
77 ret, 67 if (SQLITE_OK !=
78 epos); 68 (ret = sqlite3_prepare_v2(dbh,
79 return GNUNET_SYSERR; 69 ps[i].sql,
70 strlen(ps[i].sql),
71 ps[i].pstmt,
72 &epos)))
73 {
74 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
75 "Failed to prepare SQL `%s': error %d at %s\n",
76 ps[i].sql,
77 ret,
78 epos);
79 return GNUNET_SYSERR;
80 }
80 } 81 }
81 }
82 return GNUNET_OK; 82 return GNUNET_OK;
83} 83}
84 84
diff --git a/src/sq/sq_query_helper.c b/src/sq/sq_query_helper.c
index 2c7a9028a..1addef499 100644
--- a/src/sq/sq_query_helper.c
+++ b/src/sq/sq_query_helper.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2017 GNUnet e.V. 3 Copyright (C) 2017 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file sq/sq_query_helper.c 21 * @file sq/sq_query_helper.c
22 * @brief helper functions for queries 22 * @brief helper functions for queries
@@ -38,18 +38,18 @@
38 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 38 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
39 */ 39 */
40static int 40static int
41bind_fixed_blob (void *cls, 41bind_fixed_blob(void *cls,
42 const void *data, 42 const void *data,
43 size_t data_len, 43 size_t data_len,
44 sqlite3_stmt *stmt, 44 sqlite3_stmt *stmt,
45 unsigned int off) 45 unsigned int off)
46{ 46{
47 if (SQLITE_OK != 47 if (SQLITE_OK !=
48 sqlite3_bind_blob64 (stmt, 48 sqlite3_bind_blob64(stmt,
49 (int) off, 49 (int)off,
50 data, 50 data,
51 (sqlite3_uint64) data_len, 51 (sqlite3_uint64)data_len,
52 SQLITE_TRANSIENT)) 52 SQLITE_TRANSIENT))
53 return GNUNET_SYSERR; 53 return GNUNET_SYSERR;
54 return GNUNET_OK; 54 return GNUNET_OK;
55} 55}
@@ -63,8 +63,8 @@ bind_fixed_blob (void *cls,
63 * @oaran ptr_size number of bytes in @a ptr 63 * @oaran ptr_size number of bytes in @a ptr
64 */ 64 */
65struct GNUNET_SQ_QueryParam 65struct GNUNET_SQ_QueryParam
66GNUNET_SQ_query_param_fixed_size (const void *ptr, 66GNUNET_SQ_query_param_fixed_size(const void *ptr,
67 size_t ptr_size) 67 size_t ptr_size)
68{ 68{
69 struct GNUNET_SQ_QueryParam qp = { 69 struct GNUNET_SQ_QueryParam qp = {
70 .conv = &bind_fixed_blob, 70 .conv = &bind_fixed_blob,
@@ -72,6 +72,7 @@ GNUNET_SQ_query_param_fixed_size (const void *ptr,
72 .size = ptr_size, 72 .size = ptr_size,
73 .num_params = 1 73 .num_params = 1
74 }; 74 };
75
75 return qp; 76 return qp;
76} 77}
77 78
@@ -88,26 +89,26 @@ GNUNET_SQ_query_param_fixed_size (const void *ptr,
88 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 89 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
89 */ 90 */
90static int 91static int
91bind_string (void *cls, 92bind_string(void *cls,
92 const void *data, 93 const void *data,
93 size_t data_len, 94 size_t data_len,
94 sqlite3_stmt *stmt, 95 sqlite3_stmt *stmt,
95 unsigned int off) 96 unsigned int off)
96{ 97{
97 if (NULL == data) 98 if (NULL == data)
98 { 99 {
99 if (SQLITE_OK != 100 if (SQLITE_OK !=
100 sqlite3_bind_null (stmt, 101 sqlite3_bind_null(stmt,
101 (int) off)) 102 (int)off))
102 return GNUNET_SYSERR; 103 return GNUNET_SYSERR;
103 return GNUNET_OK; 104 return GNUNET_OK;
104 } 105 }
105 if (SQLITE_OK != 106 if (SQLITE_OK !=
106 sqlite3_bind_text (stmt, 107 sqlite3_bind_text(stmt,
107 (int) off, 108 (int)off,
108 (const char *) data, 109 (const char *)data,
109 -1, 110 -1,
110 SQLITE_TRANSIENT)) 111 SQLITE_TRANSIENT))
111 return GNUNET_SYSERR; 112 return GNUNET_SYSERR;
112 return GNUNET_OK; 113 return GNUNET_OK;
113} 114}
@@ -119,13 +120,14 @@ bind_string (void *cls,
119 * @param ptr pointer to the string query parameter to pass 120 * @param ptr pointer to the string query parameter to pass
120 */ 121 */
121struct GNUNET_SQ_QueryParam 122struct GNUNET_SQ_QueryParam
122GNUNET_SQ_query_param_string (const char *ptr) 123GNUNET_SQ_query_param_string(const char *ptr)
123{ 124{
124 struct GNUNET_SQ_QueryParam qp = { 125 struct GNUNET_SQ_QueryParam qp = {
125 .conv = &bind_string, 126 .conv = &bind_string,
126 .data = ptr, 127 .data = ptr,
127 .num_params = 1 128 .num_params = 1
128 }; 129 };
130
129 return qp; 131 return qp;
130} 132}
131 133
@@ -142,30 +144,30 @@ GNUNET_SQ_query_param_string (const char *ptr)
142 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 144 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
143 */ 145 */
144static int 146static int
145bind_rsa_pub (void *cls, 147bind_rsa_pub(void *cls,
146 const void *data, 148 const void *data,
147 size_t data_len, 149 size_t data_len,
148 sqlite3_stmt *stmt, 150 sqlite3_stmt *stmt,
149 unsigned int off) 151 unsigned int off)
150{ 152{
151 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data; 153 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data;
152 char *buf; 154 char *buf;
153 size_t buf_size; 155 size_t buf_size;
154 156
155 GNUNET_break (NULL == cls); 157 GNUNET_break(NULL == cls);
156 buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, 158 buf_size = GNUNET_CRYPTO_rsa_public_key_encode(rsa,
157 &buf); 159 &buf);
158 if (SQLITE_OK != 160 if (SQLITE_OK !=
159 sqlite3_bind_blob64 (stmt, 161 sqlite3_bind_blob64(stmt,
160 (int) off, 162 (int)off,
161 buf, 163 buf,
162 (sqlite3_uint64) buf_size, 164 (sqlite3_uint64)buf_size,
163 SQLITE_TRANSIENT)) 165 SQLITE_TRANSIENT))
164 { 166 {
165 GNUNET_free (buf); 167 GNUNET_free(buf);
166 return GNUNET_SYSERR; 168 return GNUNET_SYSERR;
167 } 169 }
168 GNUNET_free (buf); 170 GNUNET_free(buf);
169 return GNUNET_OK; 171 return GNUNET_OK;
170} 172}
171 173
@@ -177,14 +179,15 @@ bind_rsa_pub (void *cls,
177 * @param x the query parameter to pass. 179 * @param x the query parameter to pass.
178 */ 180 */
179struct GNUNET_SQ_QueryParam 181struct GNUNET_SQ_QueryParam
180GNUNET_SQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x) 182GNUNET_SQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x)
181{ 183{
182 struct GNUNET_SQ_QueryParam qp = { 184 struct GNUNET_SQ_QueryParam qp = {
183 .conv = &bind_rsa_pub, 185 .conv = &bind_rsa_pub,
184 .data = x, 186 .data = x,
185 .num_params = 1 187 .num_params = 1
186 }; 188 };
187 return qp; 189
190 return qp;
188} 191}
189 192
190 193
@@ -200,30 +203,30 @@ GNUNET_SQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x
200 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 203 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
201 */ 204 */
202static int 205static int
203bind_rsa_sig (void *cls, 206bind_rsa_sig(void *cls,
204 const void *data, 207 const void *data,
205 size_t data_len, 208 size_t data_len,
206 sqlite3_stmt *stmt, 209 sqlite3_stmt *stmt,
207 unsigned int off) 210 unsigned int off)
208{ 211{
209 const struct GNUNET_CRYPTO_RsaSignature *sig = data; 212 const struct GNUNET_CRYPTO_RsaSignature *sig = data;
210 char *buf; 213 char *buf;
211 size_t buf_size; 214 size_t buf_size;
212 215
213 GNUNET_break (NULL == cls); 216 GNUNET_break(NULL == cls);
214 buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig, 217 buf_size = GNUNET_CRYPTO_rsa_signature_encode(sig,
215 &buf); 218 &buf);
216 if (SQLITE_OK != 219 if (SQLITE_OK !=
217 sqlite3_bind_blob64 (stmt, 220 sqlite3_bind_blob64(stmt,
218 (int) off, 221 (int)off,
219 buf, 222 buf,
220 (sqlite3_uint64) buf_size, 223 (sqlite3_uint64)buf_size,
221 SQLITE_TRANSIENT)) 224 SQLITE_TRANSIENT))
222 { 225 {
223 GNUNET_free (buf); 226 GNUNET_free(buf);
224 return GNUNET_SYSERR; 227 return GNUNET_SYSERR;
225 } 228 }
226 GNUNET_free (buf); 229 GNUNET_free(buf);
227 return GNUNET_OK; 230 return GNUNET_OK;
228} 231}
229 232
@@ -235,14 +238,15 @@ bind_rsa_sig (void *cls,
235 * @param x the query parameter to pass 238 * @param x the query parameter to pass
236 */ 239 */
237struct GNUNET_SQ_QueryParam 240struct GNUNET_SQ_QueryParam
238GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) 241GNUNET_SQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x)
239{ 242{
240 struct GNUNET_SQ_QueryParam qp = { 243 struct GNUNET_SQ_QueryParam qp = {
241 .conv = &bind_rsa_sig, 244 .conv = &bind_rsa_sig,
242 .data = x, 245 .data = x,
243 .num_params = 1 246 .num_params = 1
244 }; 247 };
245 return qp; 248
249 return qp;
246} 250}
247 251
248 252
@@ -258,11 +262,11 @@ GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
258 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 262 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
259 */ 263 */
260static int 264static int
261bind_abstime (void *cls, 265bind_abstime(void *cls,
262 const void *data, 266 const void *data,
263 size_t data_len, 267 size_t data_len,
264 sqlite3_stmt *stmt, 268 sqlite3_stmt *stmt,
265 unsigned int off) 269 unsigned int off)
266{ 270{
267 const struct GNUNET_TIME_Absolute *u = data; 271 const struct GNUNET_TIME_Absolute *u = data;
268 struct GNUNET_TIME_Absolute abs; 272 struct GNUNET_TIME_Absolute abs;
@@ -270,11 +274,11 @@ bind_abstime (void *cls,
270 abs = *u; 274 abs = *u;
271 if (abs.abs_value_us > INT64_MAX) 275 if (abs.abs_value_us > INT64_MAX)
272 abs.abs_value_us = INT64_MAX; 276 abs.abs_value_us = INT64_MAX;
273 GNUNET_assert (sizeof (uint64_t) == data_len); 277 GNUNET_assert(sizeof(uint64_t) == data_len);
274 if (SQLITE_OK != 278 if (SQLITE_OK !=
275 sqlite3_bind_int64 (stmt, 279 sqlite3_bind_int64(stmt,
276 (int) off, 280 (int)off,
277 (sqlite3_int64) abs.abs_value_us)) 281 (sqlite3_int64)abs.abs_value_us))
278 return GNUNET_SYSERR; 282 return GNUNET_SYSERR;
279 return GNUNET_OK; 283 return GNUNET_OK;
280} 284}
@@ -287,14 +291,15 @@ bind_abstime (void *cls,
287 * @param x pointer to the query parameter to pass 291 * @param x pointer to the query parameter to pass
288 */ 292 */
289struct GNUNET_SQ_QueryParam 293struct GNUNET_SQ_QueryParam
290GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) 294GNUNET_SQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
291{ 295{
292 struct GNUNET_SQ_QueryParam qp = { 296 struct GNUNET_SQ_QueryParam qp = {
293 .conv = &bind_abstime, 297 .conv = &bind_abstime,
294 .data = x, 298 .data = x,
295 .size = sizeof (struct GNUNET_TIME_Absolute), 299 .size = sizeof(struct GNUNET_TIME_Absolute),
296 .num_params = 1 300 .num_params = 1
297 }; 301 };
302
298 return qp; 303 return qp;
299} 304}
300 305
@@ -311,23 +316,23 @@ GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
311 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 316 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
312 */ 317 */
313static int 318static int
314bind_nbotime (void *cls, 319bind_nbotime(void *cls,
315 const void *data, 320 const void *data,
316 size_t data_len, 321 size_t data_len,
317 sqlite3_stmt *stmt, 322 sqlite3_stmt *stmt,
318 unsigned int off) 323 unsigned int off)
319{ 324{
320 const struct GNUNET_TIME_AbsoluteNBO *u = data; 325 const struct GNUNET_TIME_AbsoluteNBO *u = data;
321 struct GNUNET_TIME_Absolute abs; 326 struct GNUNET_TIME_Absolute abs;
322 327
323 abs = GNUNET_TIME_absolute_ntoh (*u); 328 abs = GNUNET_TIME_absolute_ntoh(*u);
324 if (abs.abs_value_us > INT64_MAX) 329 if (abs.abs_value_us > INT64_MAX)
325 abs.abs_value_us = INT64_MAX; 330 abs.abs_value_us = INT64_MAX;
326 GNUNET_assert (sizeof (uint64_t) == data_len); 331 GNUNET_assert(sizeof(uint64_t) == data_len);
327 if (SQLITE_OK != 332 if (SQLITE_OK !=
328 sqlite3_bind_int64 (stmt, 333 sqlite3_bind_int64(stmt,
329 (int) off, 334 (int)off,
330 (sqlite3_int64) abs.abs_value_us)) 335 (sqlite3_int64)abs.abs_value_us))
331 return GNUNET_SYSERR; 336 return GNUNET_SYSERR;
332 return GNUNET_OK; 337 return GNUNET_OK;
333} 338}
@@ -340,14 +345,15 @@ bind_nbotime (void *cls,
340 * @param x pointer to the query parameter to pass 345 * @param x pointer to the query parameter to pass
341 */ 346 */
342struct GNUNET_SQ_QueryParam 347struct GNUNET_SQ_QueryParam
343GNUNET_SQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x) 348GNUNET_SQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x)
344{ 349{
345 struct GNUNET_SQ_QueryParam qp = { 350 struct GNUNET_SQ_QueryParam qp = {
346 .conv = &bind_nbotime, 351 .conv = &bind_nbotime,
347 .data = x, 352 .data = x,
348 .size = sizeof (struct GNUNET_TIME_AbsoluteNBO), 353 .size = sizeof(struct GNUNET_TIME_AbsoluteNBO),
349 .num_params = 1 354 .num_params = 1
350 }; 355 };
356
351 return qp; 357 return qp;
352} 358}
353 359
@@ -364,19 +370,19 @@ GNUNET_SQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x
364 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 370 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
365 */ 371 */
366static int 372static int
367bind_u16 (void *cls, 373bind_u16(void *cls,
368 const void *data, 374 const void *data,
369 size_t data_len, 375 size_t data_len,
370 sqlite3_stmt *stmt, 376 sqlite3_stmt *stmt,
371 unsigned int off) 377 unsigned int off)
372{ 378{
373 const uint16_t *u = data; 379 const uint16_t *u = data;
374 380
375 GNUNET_assert (sizeof (uint16_t) == data_len); 381 GNUNET_assert(sizeof(uint16_t) == data_len);
376 if (SQLITE_OK != 382 if (SQLITE_OK !=
377 sqlite3_bind_int (stmt, 383 sqlite3_bind_int(stmt,
378 (int) off, 384 (int)off,
379 (int) *u)) 385 (int)*u))
380 return GNUNET_SYSERR; 386 return GNUNET_SYSERR;
381 return GNUNET_OK; 387 return GNUNET_OK;
382} 388}
@@ -388,14 +394,15 @@ bind_u16 (void *cls,
388 * @param x pointer to the query parameter to pass 394 * @param x pointer to the query parameter to pass
389 */ 395 */
390struct GNUNET_SQ_QueryParam 396struct GNUNET_SQ_QueryParam
391GNUNET_SQ_query_param_uint16 (const uint16_t *x) 397GNUNET_SQ_query_param_uint16(const uint16_t *x)
392{ 398{
393 struct GNUNET_SQ_QueryParam qp = { 399 struct GNUNET_SQ_QueryParam qp = {
394 .conv = &bind_u16, 400 .conv = &bind_u16,
395 .data = x, 401 .data = x,
396 .size = sizeof (uint16_t), 402 .size = sizeof(uint16_t),
397 .num_params = 1 403 .num_params = 1
398 }; 404 };
405
399 return qp; 406 return qp;
400} 407}
401 408
@@ -412,19 +419,19 @@ GNUNET_SQ_query_param_uint16 (const uint16_t *x)
412 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 419 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
413 */ 420 */
414static int 421static int
415bind_u32 (void *cls, 422bind_u32(void *cls,
416 const void *data, 423 const void *data,
417 size_t data_len, 424 size_t data_len,
418 sqlite3_stmt *stmt, 425 sqlite3_stmt *stmt,
419 unsigned int off) 426 unsigned int off)
420{ 427{
421 const uint32_t *u = data; 428 const uint32_t *u = data;
422 429
423 GNUNET_assert (sizeof (uint32_t) == data_len); 430 GNUNET_assert(sizeof(uint32_t) == data_len);
424 if (SQLITE_OK != 431 if (SQLITE_OK !=
425 sqlite3_bind_int64 (stmt, 432 sqlite3_bind_int64(stmt,
426 (int) off, 433 (int)off,
427 (sqlite3_int64) *u)) 434 (sqlite3_int64) * u))
428 return GNUNET_SYSERR; 435 return GNUNET_SYSERR;
429 return GNUNET_OK; 436 return GNUNET_OK;
430} 437}
@@ -435,14 +442,15 @@ bind_u32 (void *cls,
435 * @param x pointer to the query parameter to pass 442 * @param x pointer to the query parameter to pass
436 */ 443 */
437struct GNUNET_SQ_QueryParam 444struct GNUNET_SQ_QueryParam
438GNUNET_SQ_query_param_uint32 (const uint32_t *x) 445GNUNET_SQ_query_param_uint32(const uint32_t *x)
439{ 446{
440 struct GNUNET_SQ_QueryParam qp = { 447 struct GNUNET_SQ_QueryParam qp = {
441 .conv = &bind_u32, 448 .conv = &bind_u32,
442 .data = x, 449 .data = x,
443 .size = sizeof (uint32_t), 450 .size = sizeof(uint32_t),
444 .num_params = 1 451 .num_params = 1
445 }; 452 };
453
446 return qp; 454 return qp;
447} 455}
448 456
@@ -459,19 +467,19 @@ GNUNET_SQ_query_param_uint32 (const uint32_t *x)
459 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 467 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
460 */ 468 */
461static int 469static int
462bind_u64 (void *cls, 470bind_u64(void *cls,
463 const void *data, 471 const void *data,
464 size_t data_len, 472 size_t data_len,
465 sqlite3_stmt *stmt, 473 sqlite3_stmt *stmt,
466 unsigned int off) 474 unsigned int off)
467{ 475{
468 const uint64_t *u = data; 476 const uint64_t *u = data;
469 477
470 GNUNET_assert (sizeof (uint64_t) == data_len); 478 GNUNET_assert(sizeof(uint64_t) == data_len);
471 if (SQLITE_OK != 479 if (SQLITE_OK !=
472 sqlite3_bind_int64 (stmt, 480 sqlite3_bind_int64(stmt,
473 (int) off, 481 (int)off,
474 (sqlite3_int64) *u)) 482 (sqlite3_int64) * u))
475 return GNUNET_SYSERR; 483 return GNUNET_SYSERR;
476 return GNUNET_OK; 484 return GNUNET_OK;
477} 485}
@@ -483,14 +491,15 @@ bind_u64 (void *cls,
483 * @param x pointer to the query parameter to pass 491 * @param x pointer to the query parameter to pass
484 */ 492 */
485struct GNUNET_SQ_QueryParam 493struct GNUNET_SQ_QueryParam
486GNUNET_SQ_query_param_uint64 (const uint64_t *x) 494GNUNET_SQ_query_param_uint64(const uint64_t *x)
487{ 495{
488 struct GNUNET_SQ_QueryParam qp = { 496 struct GNUNET_SQ_QueryParam qp = {
489 .conv = &bind_u64, 497 .conv = &bind_u64,
490 .data = x, 498 .data = x,
491 .size = sizeof (uint64_t), 499 .size = sizeof(uint64_t),
492 .num_params = 1 500 .num_params = 1
493 }; 501 };
502
494 return qp; 503 return qp;
495} 504}
496 505
diff --git a/src/sq/sq_result_helper.c b/src/sq/sq_result_helper.c
index aba1eaea5..6cef94326 100644
--- a/src/sq/sq_result_helper.c
+++ b/src/sq/sq_result_helper.c
@@ -1,23 +1,23 @@
1 1
2/* 2/*
3 This file is part of GNUnet 3 This file is part of GNUnet
4 Copyright (C) 2017 GNUnet e.V. 4 Copyright (C) 2017 GNUnet e.V.
5 5
6 GNUnet is free software: you can redistribute it and/or modify it 6 GNUnet is free software: you can redistribute it and/or modify it
7 under the terms of the GNU Affero General Public License as published 7 under the terms of the GNU Affero General Public License as published
8 by the Free Software Foundation, either version 3 of the License, 8 by the Free Software Foundation, either version 3 of the License,
9 or (at your option) any later version. 9 or (at your option) any later version.
10 10
11 GNUnet is distributed in the hope that it will be useful, but 11 GNUnet is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of 12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Affero General Public License for more details. 14 Affero General Public License for more details.
15 15
16 You should have received a copy of the GNU Affero General Public License 16 You should have received a copy of the GNU Affero General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 SPDX-License-Identifier: AGPL3.0-or-later 19 SPDX-License-Identifier: AGPL3.0-or-later
20*/ 20 */
21/** 21/**
22 * @file sq/sq_result_helper.c 22 * @file sq/sq_result_helper.c
23 * @brief helper functions for queries 23 * @brief helper functions for queries
@@ -40,53 +40,53 @@
40 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 40 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
41 */ 41 */
42static int 42static int
43extract_var_blob (void *cls, 43extract_var_blob(void *cls,
44 sqlite3_stmt *result, 44 sqlite3_stmt *result,
45 unsigned int column, 45 unsigned int column,
46 size_t *dst_size, 46 size_t *dst_size,
47 void *dst) 47 void *dst)
48{ 48{
49 int have; 49 int have;
50 const void *ret; 50 const void *ret;
51 void **rdst = (void **) dst; 51 void **rdst = (void **)dst;
52 52
53 if (SQLITE_NULL == 53 if (SQLITE_NULL ==
54 sqlite3_column_type (result, 54 sqlite3_column_type(result,
55 column)) 55 column))
56 { 56 {
57 *rdst = NULL; 57 *rdst = NULL;
58 *dst_size = 0; 58 *dst_size = 0;
59 return GNUNET_YES; 59 return GNUNET_YES;
60 } 60 }
61 61
62 if (SQLITE_BLOB != 62 if (SQLITE_BLOB !=
63 sqlite3_column_type (result, 63 sqlite3_column_type(result,
64 column)) 64 column))
65 { 65 {
66 GNUNET_break (0); 66 GNUNET_break(0);
67 return GNUNET_SYSERR; 67 return GNUNET_SYSERR;
68 } 68 }
69 /* sqlite manual says to invoke 'sqlite3_column_blob()' 69 /* sqlite manual says to invoke 'sqlite3_column_blob()'
70 before calling sqlite3_column_bytes() */ 70 before calling sqlite3_column_bytes() */
71 ret = sqlite3_column_blob (result, 71 ret = sqlite3_column_blob(result,
72 column); 72 column);
73 have = sqlite3_column_bytes (result, 73 have = sqlite3_column_bytes(result,
74 column); 74 column);
75 if (have < 0) 75 if (have < 0)
76 { 76 {
77 GNUNET_break (0); 77 GNUNET_break(0);
78 return GNUNET_SYSERR; 78 return GNUNET_SYSERR;
79 } 79 }
80 *dst_size = have; 80 *dst_size = have;
81 if (0 == have) 81 if (0 == have)
82 { 82 {
83 *rdst = NULL; 83 *rdst = NULL;
84 return GNUNET_OK; 84 return GNUNET_OK;
85 } 85 }
86 *rdst = GNUNET_malloc (have); 86 *rdst = GNUNET_malloc(have);
87 GNUNET_memcpy (*rdst, 87 GNUNET_memcpy(*rdst,
88 ret, 88 ret,
89 have); 89 have);
90 return GNUNET_OK; 90 return GNUNET_OK;
91} 91}
92 92
@@ -97,15 +97,15 @@ extract_var_blob (void *cls,
97 * @param cls pointer to pointer of allocation 97 * @param cls pointer to pointer of allocation
98 */ 98 */
99static void 99static void
100clean_var_blob (void *cls) 100clean_var_blob(void *cls)
101{ 101{
102 void **dptr = (void **) cls; 102 void **dptr = (void **)cls;
103 103
104 if (NULL != *dptr) 104 if (NULL != *dptr)
105 { 105 {
106 GNUNET_free (*dptr); 106 GNUNET_free(*dptr);
107 *dptr = NULL; 107 *dptr = NULL;
108 } 108 }
109} 109}
110 110
111 111
@@ -117,8 +117,8 @@ clean_var_blob (void *cls)
117 * @return array entry for the result specification to use 117 * @return array entry for the result specification to use
118 */ 118 */
119struct GNUNET_SQ_ResultSpec 119struct GNUNET_SQ_ResultSpec
120GNUNET_SQ_result_spec_variable_size (void **dst, 120GNUNET_SQ_result_spec_variable_size(void **dst,
121 size_t *sptr) 121 size_t *sptr)
122{ 122{
123 struct GNUNET_SQ_ResultSpec rs = { 123 struct GNUNET_SQ_ResultSpec rs = {
124 .conv = &extract_var_blob, 124 .conv = &extract_var_blob,
@@ -146,44 +146,44 @@ GNUNET_SQ_result_spec_variable_size (void **dst,
146 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 146 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
147 */ 147 */
148static int 148static int
149extract_fixed_blob (void *cls, 149extract_fixed_blob(void *cls,
150 sqlite3_stmt *result, 150 sqlite3_stmt *result,
151 unsigned int column, 151 unsigned int column,
152 size_t *dst_size, 152 size_t *dst_size,
153 void *dst) 153 void *dst)
154{ 154{
155 int have; 155 int have;
156 const void *ret; 156 const void *ret;
157 157
158 if ( (0 == *dst_size) && 158 if ((0 == *dst_size) &&
159 (SQLITE_NULL == 159 (SQLITE_NULL ==
160 sqlite3_column_type (result, 160 sqlite3_column_type(result,
161 column)) ) 161 column)))
162 { 162 {
163 return GNUNET_YES; 163 return GNUNET_YES;
164 } 164 }
165 165
166 if (SQLITE_BLOB != 166 if (SQLITE_BLOB !=
167 sqlite3_column_type (result, 167 sqlite3_column_type(result,
168 column)) 168 column))
169 { 169 {
170 GNUNET_break (0); 170 GNUNET_break(0);
171 return GNUNET_SYSERR; 171 return GNUNET_SYSERR;
172 } 172 }
173 /* sqlite manual says to invoke 'sqlite3_column_blob()' 173 /* sqlite manual says to invoke 'sqlite3_column_blob()'
174 before calling sqlite3_column_bytes() */ 174 before calling sqlite3_column_bytes() */
175 ret = sqlite3_column_blob (result, 175 ret = sqlite3_column_blob(result,
176 column); 176 column);
177 have = sqlite3_column_bytes (result, 177 have = sqlite3_column_bytes(result,
178 column); 178 column);
179 if (*dst_size != have) 179 if (*dst_size != have)
180 { 180 {
181 GNUNET_break (0); 181 GNUNET_break(0);
182 return GNUNET_SYSERR; 182 return GNUNET_SYSERR;
183 } 183 }
184 GNUNET_memcpy (dst, 184 GNUNET_memcpy(dst,
185 ret, 185 ret,
186 have); 186 have);
187 return GNUNET_OK; 187 return GNUNET_OK;
188} 188}
189 189
@@ -196,8 +196,8 @@ extract_fixed_blob (void *cls,
196 * @return array entry for the result specification to use 196 * @return array entry for the result specification to use
197 */ 197 */
198struct GNUNET_SQ_ResultSpec 198struct GNUNET_SQ_ResultSpec
199GNUNET_SQ_result_spec_fixed_size (void *dst, 199GNUNET_SQ_result_spec_fixed_size(void *dst,
200 size_t dst_size) 200 size_t dst_size)
201{ 201{
202 struct GNUNET_SQ_ResultSpec rs = { 202 struct GNUNET_SQ_ResultSpec rs = {
203 .conv = &extract_fixed_blob, 203 .conv = &extract_fixed_blob,
@@ -223,40 +223,40 @@ GNUNET_SQ_result_spec_fixed_size (void *dst,
223 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 223 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
224 */ 224 */
225static int 225static int
226extract_utf8_string (void *cls, 226extract_utf8_string(void *cls,
227 sqlite3_stmt *result, 227 sqlite3_stmt *result,
228 unsigned int column, 228 unsigned int column,
229 size_t *dst_size, 229 size_t *dst_size,
230 void *dst) 230 void *dst)
231{ 231{
232 const char *text; 232 const char *text;
233 char **rdst = dst; 233 char **rdst = dst;
234 234
235 if (SQLITE_NULL == 235 if (SQLITE_NULL ==
236 sqlite3_column_type (result, 236 sqlite3_column_type(result,
237 column)) 237 column))
238 { 238 {
239 *rdst = NULL; 239 *rdst = NULL;
240 return GNUNET_OK; 240 return GNUNET_OK;
241 } 241 }
242 if (SQLITE_TEXT != 242 if (SQLITE_TEXT !=
243 sqlite3_column_type (result, 243 sqlite3_column_type(result,
244 column)) 244 column))
245 { 245 {
246 GNUNET_break (0); 246 GNUNET_break(0);
247 return GNUNET_SYSERR; 247 return GNUNET_SYSERR;
248 } 248 }
249 /* sqlite manual guarantees that 'sqlite3_column_text()' 249 /* sqlite manual guarantees that 'sqlite3_column_text()'
250 is 0-terminated */ 250 is 0-terminated */
251 text = (const char *) sqlite3_column_text (result, 251 text = (const char *)sqlite3_column_text(result,
252 column); 252 column);
253 if (NULL == text) 253 if (NULL == text)
254 { 254 {
255 GNUNET_break (0); 255 GNUNET_break(0);
256 return GNUNET_SYSERR; 256 return GNUNET_SYSERR;
257 } 257 }
258 *dst_size = strlen (text) + 1; 258 *dst_size = strlen(text) + 1;
259 *rdst = GNUNET_strdup (text); 259 *rdst = GNUNET_strdup(text);
260 return GNUNET_OK; 260 return GNUNET_OK;
261} 261}
262 262
@@ -267,15 +267,15 @@ extract_utf8_string (void *cls,
267 * @param cls pointer to pointer of allocation 267 * @param cls pointer to pointer of allocation
268 */ 268 */
269static void 269static void
270clean_utf8_string (void *cls) 270clean_utf8_string(void *cls)
271{ 271{
272 char **dptr = (char **) cls; 272 char **dptr = (char **)cls;
273 273
274 if (NULL != *dptr) 274 if (NULL != *dptr)
275 { 275 {
276 GNUNET_free (*dptr); 276 GNUNET_free(*dptr);
277 *dptr = NULL; 277 *dptr = NULL;
278 } 278 }
279} 279}
280 280
281 281
@@ -286,7 +286,7 @@ clean_utf8_string (void *cls)
286 * @return array entry for the result specification to use 286 * @return array entry for the result specification to use
287 */ 287 */
288struct GNUNET_SQ_ResultSpec 288struct GNUNET_SQ_ResultSpec
289GNUNET_SQ_result_spec_string (char **dst) 289GNUNET_SQ_result_spec_string(char **dst)
290{ 290{
291 struct GNUNET_SQ_ResultSpec rs = { 291 struct GNUNET_SQ_ResultSpec rs = {
292 .conv = &extract_utf8_string, 292 .conv = &extract_utf8_string,
@@ -313,42 +313,42 @@ GNUNET_SQ_result_spec_string (char **dst)
313 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 313 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
314 */ 314 */
315static int 315static int
316extract_rsa_pub (void *cls, 316extract_rsa_pub(void *cls,
317 sqlite3_stmt *result, 317 sqlite3_stmt *result,
318 unsigned int column, 318 unsigned int column,
319 size_t *dst_size, 319 size_t *dst_size,
320 void *dst) 320 void *dst)
321{ 321{
322 struct GNUNET_CRYPTO_RsaPublicKey **pk = dst; 322 struct GNUNET_CRYPTO_RsaPublicKey **pk = dst;
323 int have; 323 int have;
324 const void *ret; 324 const void *ret;
325 325
326 if (SQLITE_BLOB != 326 if (SQLITE_BLOB !=
327 sqlite3_column_type (result, 327 sqlite3_column_type(result,
328 column)) 328 column))
329 { 329 {
330 GNUNET_break (0); 330 GNUNET_break(0);
331 return GNUNET_SYSERR; 331 return GNUNET_SYSERR;
332 } 332 }
333 /* sqlite manual says to invoke 'sqlite3_column_blob()' 333 /* sqlite manual says to invoke 'sqlite3_column_blob()'
334 before calling sqlite3_column_bytes() */ 334 before calling sqlite3_column_bytes() */
335 ret = sqlite3_column_blob (result, 335 ret = sqlite3_column_blob(result,
336 column); 336 column);
337 have = sqlite3_column_bytes (result, 337 have = sqlite3_column_bytes(result,
338 column); 338 column);
339 if (have < 0) 339 if (have < 0)
340 { 340 {
341 GNUNET_break (0); 341 GNUNET_break(0);
342 return GNUNET_SYSERR; 342 return GNUNET_SYSERR;
343 } 343 }
344 344
345 *pk = GNUNET_CRYPTO_rsa_public_key_decode (ret, 345 *pk = GNUNET_CRYPTO_rsa_public_key_decode(ret,
346 have); 346 have);
347 if (NULL == *pk) 347 if (NULL == *pk)
348 { 348 {
349 GNUNET_break (0); 349 GNUNET_break(0);
350 return GNUNET_SYSERR; 350 return GNUNET_SYSERR;
351 } 351 }
352 return GNUNET_OK; 352 return GNUNET_OK;
353} 353}
354 354
@@ -360,15 +360,15 @@ extract_rsa_pub (void *cls,
360 * @param cls closure 360 * @param cls closure
361 */ 361 */
362static void 362static void
363clean_rsa_pub (void *cls) 363clean_rsa_pub(void *cls)
364{ 364{
365 struct GNUNET_CRYPTO_RsaPublicKey **pk = cls; 365 struct GNUNET_CRYPTO_RsaPublicKey **pk = cls;
366 366
367 if (NULL != *pk) 367 if (NULL != *pk)
368 { 368 {
369 GNUNET_CRYPTO_rsa_public_key_free (*pk); 369 GNUNET_CRYPTO_rsa_public_key_free(*pk);
370 *pk = NULL; 370 *pk = NULL;
371 } 371 }
372} 372}
373 373
374 374
@@ -379,7 +379,7 @@ clean_rsa_pub (void *cls)
379 * @return array entry for the result specification to use 379 * @return array entry for the result specification to use
380 */ 380 */
381struct GNUNET_SQ_ResultSpec 381struct GNUNET_SQ_ResultSpec
382GNUNET_SQ_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa) 382GNUNET_SQ_result_spec_rsa_public_key(struct GNUNET_CRYPTO_RsaPublicKey **rsa)
383{ 383{
384 struct GNUNET_SQ_ResultSpec rs = { 384 struct GNUNET_SQ_ResultSpec rs = {
385 .conv = &extract_rsa_pub, 385 .conv = &extract_rsa_pub,
@@ -406,42 +406,42 @@ GNUNET_SQ_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa)
406 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 406 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
407 */ 407 */
408static int 408static int
409extract_rsa_sig (void *cls, 409extract_rsa_sig(void *cls,
410 sqlite3_stmt *result, 410 sqlite3_stmt *result,
411 unsigned int column, 411 unsigned int column,
412 size_t *dst_size, 412 size_t *dst_size,
413 void *dst) 413 void *dst)
414{ 414{
415 struct GNUNET_CRYPTO_RsaSignature **sig = dst; 415 struct GNUNET_CRYPTO_RsaSignature **sig = dst;
416 int have; 416 int have;
417 const void *ret; 417 const void *ret;
418 418
419 if (SQLITE_BLOB != 419 if (SQLITE_BLOB !=
420 sqlite3_column_type (result, 420 sqlite3_column_type(result,
421 column)) 421 column))
422 { 422 {
423 GNUNET_break (0); 423 GNUNET_break(0);
424 return GNUNET_SYSERR; 424 return GNUNET_SYSERR;
425 } 425 }
426 /* sqlite manual says to invoke 'sqlite3_column_blob()' 426 /* sqlite manual says to invoke 'sqlite3_column_blob()'
427 before calling sqlite3_column_bytes() */ 427 before calling sqlite3_column_bytes() */
428 ret = sqlite3_column_blob (result, 428 ret = sqlite3_column_blob(result,
429 column); 429 column);
430 have = sqlite3_column_bytes (result, 430 have = sqlite3_column_bytes(result,
431 column); 431 column);
432 if (have < 0) 432 if (have < 0)
433 { 433 {
434 GNUNET_break (0); 434 GNUNET_break(0);
435 return GNUNET_SYSERR; 435 return GNUNET_SYSERR;
436 } 436 }
437 437
438 *sig = GNUNET_CRYPTO_rsa_signature_decode (ret, 438 *sig = GNUNET_CRYPTO_rsa_signature_decode(ret,
439 have); 439 have);
440 if (NULL == *sig) 440 if (NULL == *sig)
441 { 441 {
442 GNUNET_break (0); 442 GNUNET_break(0);
443 return GNUNET_SYSERR; 443 return GNUNET_SYSERR;
444 } 444 }
445 return GNUNET_OK; 445 return GNUNET_OK;
446} 446}
447 447
@@ -453,15 +453,15 @@ extract_rsa_sig (void *cls,
453 * @param cls result data to clean up 453 * @param cls result data to clean up
454 */ 454 */
455static void 455static void
456clean_rsa_sig (void *cls) 456clean_rsa_sig(void *cls)
457{ 457{
458 struct GNUNET_CRYPTO_RsaSignature **sig = cls; 458 struct GNUNET_CRYPTO_RsaSignature **sig = cls;
459 459
460 if (NULL != *sig) 460 if (NULL != *sig)
461 { 461 {
462 GNUNET_CRYPTO_rsa_signature_free (*sig); 462 GNUNET_CRYPTO_rsa_signature_free(*sig);
463 *sig = NULL; 463 *sig = NULL;
464 } 464 }
465} 465}
466 466
467 467
@@ -472,7 +472,7 @@ clean_rsa_sig (void *cls)
472 * @return array entry for the result specification to use 472 * @return array entry for the result specification to use
473 */ 473 */
474struct GNUNET_SQ_ResultSpec 474struct GNUNET_SQ_ResultSpec
475GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig) 475GNUNET_SQ_result_spec_rsa_signature(struct GNUNET_CRYPTO_RsaSignature **sig)
476{ 476{
477 struct GNUNET_SQ_ResultSpec rs = { 477 struct GNUNET_SQ_ResultSpec rs = {
478 .conv = &extract_rsa_sig, 478 .conv = &extract_rsa_sig,
@@ -499,25 +499,25 @@ GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig)
499 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 499 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
500 */ 500 */
501static int 501static int
502extract_abs_time (void *cls, 502extract_abs_time(void *cls,
503 sqlite3_stmt *result, 503 sqlite3_stmt *result,
504 unsigned int column, 504 unsigned int column,
505 size_t *dst_size, 505 size_t *dst_size,
506 void *dst) 506 void *dst)
507{ 507{
508 struct GNUNET_TIME_Absolute *u = dst; 508 struct GNUNET_TIME_Absolute *u = dst;
509 struct GNUNET_TIME_Absolute t; 509 struct GNUNET_TIME_Absolute t;
510 510
511 GNUNET_assert (sizeof (uint64_t) == *dst_size); 511 GNUNET_assert(sizeof(uint64_t) == *dst_size);
512 if (SQLITE_INTEGER != 512 if (SQLITE_INTEGER !=
513 sqlite3_column_type (result, 513 sqlite3_column_type(result,
514 column)) 514 column))
515 { 515 {
516 GNUNET_break (0); 516 GNUNET_break(0);
517 return GNUNET_SYSERR; 517 return GNUNET_SYSERR;
518 } 518 }
519 t.abs_value_us = (uint64_t) sqlite3_column_int64 (result, 519 t.abs_value_us = (uint64_t)sqlite3_column_int64(result,
520 column); 520 column);
521 if (INT64_MAX == t.abs_value_us) 521 if (INT64_MAX == t.abs_value_us)
522 t = GNUNET_TIME_UNIT_FOREVER_ABS; 522 t = GNUNET_TIME_UNIT_FOREVER_ABS;
523 *u = t; 523 *u = t;
@@ -532,12 +532,12 @@ extract_abs_time (void *cls,
532 * @return array entry for the result specification to use 532 * @return array entry for the result specification to use
533 */ 533 */
534struct GNUNET_SQ_ResultSpec 534struct GNUNET_SQ_ResultSpec
535GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at) 535GNUNET_SQ_result_spec_absolute_time(struct GNUNET_TIME_Absolute *at)
536{ 536{
537 struct GNUNET_SQ_ResultSpec rs = { 537 struct GNUNET_SQ_ResultSpec rs = {
538 .conv = &extract_abs_time, 538 .conv = &extract_abs_time,
539 .dst = at, 539 .dst = at,
540 .dst_size = sizeof (struct GNUNET_TIME_Absolute), 540 .dst_size = sizeof(struct GNUNET_TIME_Absolute),
541 .num_params = 1 541 .num_params = 1
542 }; 542 };
543 543
@@ -558,28 +558,28 @@ GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at)
558 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 558 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
559 */ 559 */
560static int 560static int
561extract_abs_time_nbo (void *cls, 561extract_abs_time_nbo(void *cls,
562 sqlite3_stmt *result, 562 sqlite3_stmt *result,
563 unsigned int column, 563 unsigned int column,
564 size_t *dst_size, 564 size_t *dst_size,
565 void *dst) 565 void *dst)
566{ 566{
567 struct GNUNET_TIME_AbsoluteNBO *u = dst; 567 struct GNUNET_TIME_AbsoluteNBO *u = dst;
568 struct GNUNET_TIME_Absolute t; 568 struct GNUNET_TIME_Absolute t;
569 569
570 GNUNET_assert (sizeof (uint64_t) == *dst_size); 570 GNUNET_assert(sizeof(uint64_t) == *dst_size);
571 if (SQLITE_INTEGER != 571 if (SQLITE_INTEGER !=
572 sqlite3_column_type (result, 572 sqlite3_column_type(result,
573 column)) 573 column))
574 { 574 {
575 GNUNET_break (0); 575 GNUNET_break(0);
576 return GNUNET_SYSERR; 576 return GNUNET_SYSERR;
577 } 577 }
578 t.abs_value_us = (uint64_t) sqlite3_column_int64 (result, 578 t.abs_value_us = (uint64_t)sqlite3_column_int64(result,
579 column); 579 column);
580 if (INT64_MAX == t.abs_value_us) 580 if (INT64_MAX == t.abs_value_us)
581 t = GNUNET_TIME_UNIT_FOREVER_ABS; 581 t = GNUNET_TIME_UNIT_FOREVER_ABS;
582 *u = GNUNET_TIME_absolute_hton (t); 582 *u = GNUNET_TIME_absolute_hton(t);
583 return GNUNET_OK; 583 return GNUNET_OK;
584} 584}
585 585
@@ -591,12 +591,12 @@ extract_abs_time_nbo (void *cls,
591 * @return array entry for the result specification to use 591 * @return array entry for the result specification to use
592 */ 592 */
593struct GNUNET_SQ_ResultSpec 593struct GNUNET_SQ_ResultSpec
594GNUNET_SQ_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at) 594GNUNET_SQ_result_spec_absolute_time_nbo(struct GNUNET_TIME_AbsoluteNBO *at)
595{ 595{
596 struct GNUNET_SQ_ResultSpec rs = { 596 struct GNUNET_SQ_ResultSpec rs = {
597 .conv = &extract_abs_time_nbo, 597 .conv = &extract_abs_time_nbo,
598 .dst = at, 598 .dst = at,
599 .dst_size = sizeof (struct GNUNET_TIME_AbsoluteNBO), 599 .dst_size = sizeof(struct GNUNET_TIME_AbsoluteNBO),
600 .num_params = 1 600 .num_params = 1
601 }; 601 };
602 602
@@ -617,31 +617,31 @@ GNUNET_SQ_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at)
617 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 617 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
618 */ 618 */
619static int 619static int
620extract_uint16 (void *cls, 620extract_uint16(void *cls,
621 sqlite3_stmt *result, 621 sqlite3_stmt *result,
622 unsigned int column, 622 unsigned int column,
623 size_t *dst_size, 623 size_t *dst_size,
624 void *dst) 624 void *dst)
625{ 625{
626 uint64_t v; 626 uint64_t v;
627 uint16_t *u = dst; 627 uint16_t *u = dst;
628 628
629 GNUNET_assert (sizeof (uint16_t) == *dst_size); 629 GNUNET_assert(sizeof(uint16_t) == *dst_size);
630 if (SQLITE_INTEGER != 630 if (SQLITE_INTEGER !=
631 sqlite3_column_type (result, 631 sqlite3_column_type(result,
632 column)) 632 column))
633 { 633 {
634 GNUNET_break (0); 634 GNUNET_break(0);
635 return GNUNET_SYSERR; 635 return GNUNET_SYSERR;
636 } 636 }
637 v = (uint64_t) sqlite3_column_int64 (result, 637 v = (uint64_t)sqlite3_column_int64(result,
638 column); 638 column);
639 if (v > UINT16_MAX) 639 if (v > UINT16_MAX)
640 { 640 {
641 GNUNET_break (0); 641 GNUNET_break(0);
642 return GNUNET_SYSERR; 642 return GNUNET_SYSERR;
643 } 643 }
644 *u = (uint16_t) v; 644 *u = (uint16_t)v;
645 return GNUNET_OK; 645 return GNUNET_OK;
646} 646}
647 647
@@ -653,12 +653,12 @@ extract_uint16 (void *cls,
653 * @return array entry for the result specification to use 653 * @return array entry for the result specification to use
654 */ 654 */
655struct GNUNET_SQ_ResultSpec 655struct GNUNET_SQ_ResultSpec
656GNUNET_SQ_result_spec_uint16 (uint16_t *u16) 656GNUNET_SQ_result_spec_uint16(uint16_t *u16)
657{ 657{
658 struct GNUNET_SQ_ResultSpec rs = { 658 struct GNUNET_SQ_ResultSpec rs = {
659 .conv = &extract_uint16, 659 .conv = &extract_uint16,
660 .dst = u16, 660 .dst = u16,
661 .dst_size = sizeof (uint16_t), 661 .dst_size = sizeof(uint16_t),
662 .num_params = 1 662 .num_params = 1
663 }; 663 };
664 664
@@ -679,31 +679,31 @@ GNUNET_SQ_result_spec_uint16 (uint16_t *u16)
679 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 679 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
680 */ 680 */
681static int 681static int
682extract_uint32 (void *cls, 682extract_uint32(void *cls,
683 sqlite3_stmt *result, 683 sqlite3_stmt *result,
684 unsigned int column, 684 unsigned int column,
685 size_t *dst_size, 685 size_t *dst_size,
686 void *dst) 686 void *dst)
687{ 687{
688 uint64_t v; 688 uint64_t v;
689 uint32_t *u = dst; 689 uint32_t *u = dst;
690 690
691 GNUNET_assert (sizeof (uint32_t) == *dst_size); 691 GNUNET_assert(sizeof(uint32_t) == *dst_size);
692 if (SQLITE_INTEGER != 692 if (SQLITE_INTEGER !=
693 sqlite3_column_type (result, 693 sqlite3_column_type(result,
694 column)) 694 column))
695 { 695 {
696 GNUNET_break (0); 696 GNUNET_break(0);
697 return GNUNET_SYSERR; 697 return GNUNET_SYSERR;
698 } 698 }
699 v = (uint64_t) sqlite3_column_int64 (result, 699 v = (uint64_t)sqlite3_column_int64(result,
700 column); 700 column);
701 if (v > UINT32_MAX) 701 if (v > UINT32_MAX)
702 { 702 {
703 GNUNET_break (0); 703 GNUNET_break(0);
704 return GNUNET_SYSERR; 704 return GNUNET_SYSERR;
705 } 705 }
706 *u = (uint32_t) v; 706 *u = (uint32_t)v;
707 return GNUNET_OK; 707 return GNUNET_OK;
708} 708}
709 709
@@ -715,12 +715,12 @@ extract_uint32 (void *cls,
715 * @return array entry for the result specification to use 715 * @return array entry for the result specification to use
716 */ 716 */
717struct GNUNET_SQ_ResultSpec 717struct GNUNET_SQ_ResultSpec
718GNUNET_SQ_result_spec_uint32 (uint32_t *u32) 718GNUNET_SQ_result_spec_uint32(uint32_t *u32)
719{ 719{
720 struct GNUNET_SQ_ResultSpec rs = { 720 struct GNUNET_SQ_ResultSpec rs = {
721 .conv = &extract_uint32, 721 .conv = &extract_uint32,
722 .dst = u32, 722 .dst = u32,
723 .dst_size = sizeof (uint32_t), 723 .dst_size = sizeof(uint32_t),
724 .num_params = 1 724 .num_params = 1
725 }; 725 };
726 726
@@ -741,24 +741,24 @@ GNUNET_SQ_result_spec_uint32 (uint32_t *u32)
741 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 741 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
742 */ 742 */
743static int 743static int
744extract_uint64 (void *cls, 744extract_uint64(void *cls,
745 sqlite3_stmt *result, 745 sqlite3_stmt *result,
746 unsigned int column, 746 unsigned int column,
747 size_t *dst_size, 747 size_t *dst_size,
748 void *dst) 748 void *dst)
749{ 749{
750 uint64_t *u = dst; 750 uint64_t *u = dst;
751 751
752 GNUNET_assert (sizeof (uint64_t) == *dst_size); 752 GNUNET_assert(sizeof(uint64_t) == *dst_size);
753 if (SQLITE_INTEGER != 753 if (SQLITE_INTEGER !=
754 sqlite3_column_type (result, 754 sqlite3_column_type(result,
755 column)) 755 column))
756 { 756 {
757 GNUNET_break (0); 757 GNUNET_break(0);
758 return GNUNET_SYSERR; 758 return GNUNET_SYSERR;
759 } 759 }
760 *u = (uint64_t) sqlite3_column_int64 (result, 760 *u = (uint64_t)sqlite3_column_int64(result,
761 column); 761 column);
762 return GNUNET_OK; 762 return GNUNET_OK;
763} 763}
764 764
@@ -770,12 +770,12 @@ extract_uint64 (void *cls,
770 * @return array entry for the result specification to use 770 * @return array entry for the result specification to use
771 */ 771 */
772struct GNUNET_SQ_ResultSpec 772struct GNUNET_SQ_ResultSpec
773GNUNET_SQ_result_spec_uint64 (uint64_t *u64) 773GNUNET_SQ_result_spec_uint64(uint64_t *u64)
774{ 774{
775 struct GNUNET_SQ_ResultSpec rs = { 775 struct GNUNET_SQ_ResultSpec rs = {
776 .conv = &extract_uint64, 776 .conv = &extract_uint64,
777 .dst = u64, 777 .dst = u64,
778 .dst_size = sizeof (uint64_t), 778 .dst_size = sizeof(uint64_t),
779 .num_params = 1 779 .num_params = 1
780 }; 780 };
781 781
diff --git a/src/sq/test_sq.c b/src/sq/test_sq.c
index 69216443f..4c81bd5c3 100644
--- a/src/sq/test_sq.c
+++ b/src/sq/test_sq.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2015, 2016, 2017 GNUnet e.V. 3 (C) 2015, 2016, 2017 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file sq/test_sq.c 21 * @file sq/test_sq.c
22 * @brief Tests for sqlite3 convenience API 22 * @brief Tests for sqlite3 convenience API
@@ -36,23 +36,23 @@
36 * @return 0 on success 36 * @return 0 on success
37 */ 37 */
38static int 38static int
39sq_prepare (sqlite3 *dbh, 39sq_prepare(sqlite3 *dbh,
40 const char *zSql, 40 const char *zSql,
41 sqlite3_stmt **ppStmt) 41 sqlite3_stmt **ppStmt)
42{ 42{
43 char *dummy; 43 char *dummy;
44 int result; 44 int result;
45 45
46 result = sqlite3_prepare_v2 (dbh, 46 result = sqlite3_prepare_v2(dbh,
47 zSql, 47 zSql,
48 strlen (zSql), 48 strlen(zSql),
49 ppStmt, 49 ppStmt,
50 (const char **) &dummy); 50 (const char **)&dummy);
51 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 51 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
52 "Prepared `%s' / %p: %d\n", 52 "Prepared `%s' / %p: %d\n",
53 zSql, 53 zSql,
54 *ppStmt, 54 *ppStmt,
55 result); 55 result);
56 return result; 56 return result;
57} 57}
58 58
@@ -63,13 +63,13 @@ sq_prepare (sqlite3 *dbh,
63 * @return 0 on success 63 * @return 0 on success
64 */ 64 */
65static int 65static int
66run_queries (sqlite3 *dbh) 66run_queries(sqlite3 *dbh)
67{ 67{
68 struct GNUNET_CRYPTO_RsaPublicKey *pub; 68 struct GNUNET_CRYPTO_RsaPublicKey *pub;
69 struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; 69 struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL;
70 struct GNUNET_CRYPTO_RsaSignature *sig; 70 struct GNUNET_CRYPTO_RsaSignature *sig;
71 struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; 71 struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL;
72 struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get (); 72 struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get();
73 struct GNUNET_TIME_Absolute abs_time2; 73 struct GNUNET_TIME_Absolute abs_time2;
74 struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS; 74 struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS;
75 struct GNUNET_TIME_Absolute forever2; 75 struct GNUNET_TIME_Absolute forever2;
@@ -88,133 +88,133 @@ run_queries (sqlite3 *dbh)
88 uint64_t u64; 88 uint64_t u64;
89 uint64_t u642; 89 uint64_t u642;
90 90
91 priv = GNUNET_CRYPTO_rsa_private_key_create (1024); 91 priv = GNUNET_CRYPTO_rsa_private_key_create(1024);
92 pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); 92 pub = GNUNET_CRYPTO_rsa_private_key_get_public(priv);
93 memset (&hmsg, 42, sizeof (hmsg)); 93 memset(&hmsg, 42, sizeof(hmsg));
94 sig = GNUNET_CRYPTO_rsa_sign_fdh (priv, 94 sig = GNUNET_CRYPTO_rsa_sign_fdh(priv,
95 &hmsg); 95 &hmsg);
96 u16 = 16; 96 u16 = 16;
97 u32 = 32; 97 u32 = 32;
98 u64 = 64; 98 u64 = 64;
99 /* FIXME: test GNUNET_SQ_result_spec_variable_size */ 99 /* FIXME: test GNUNET_SQ_result_spec_variable_size */
100 100
101 sq_prepare (dbh, 101 sq_prepare(dbh,
102 "INSERT INTO test_sq (" 102 "INSERT INTO test_sq ("
103 " pub" 103 " pub"
104 ",sig" 104 ",sig"
105 ",abs_time" 105 ",abs_time"
106 ",forever" 106 ",forever"
107 ",hash" 107 ",hash"
108 ",vsize" 108 ",vsize"
109 ",u16" 109 ",u16"
110 ",u32" 110 ",u32"
111 ",u64" 111 ",u64"
112 ") VALUES " 112 ") VALUES "
113 "($1, $2, $3, $4, $5, $6," 113 "($1, $2, $3, $4, $5, $6,"
114 "$7, $8, $9);", 114 "$7, $8, $9);",
115 &stmt); 115 &stmt);
116 { 116 {
117 struct GNUNET_SQ_QueryParam params_insert[] = { 117 struct GNUNET_SQ_QueryParam params_insert[] = {
118 GNUNET_SQ_query_param_rsa_public_key (pub), 118 GNUNET_SQ_query_param_rsa_public_key(pub),
119 GNUNET_SQ_query_param_rsa_signature (sig), 119 GNUNET_SQ_query_param_rsa_signature(sig),
120 GNUNET_SQ_query_param_absolute_time (&abs_time), 120 GNUNET_SQ_query_param_absolute_time(&abs_time),
121 GNUNET_SQ_query_param_absolute_time (&forever), 121 GNUNET_SQ_query_param_absolute_time(&forever),
122 GNUNET_SQ_query_param_auto_from_type (&hc), 122 GNUNET_SQ_query_param_auto_from_type(&hc),
123 GNUNET_SQ_query_param_fixed_size (msg, strlen (msg)), 123 GNUNET_SQ_query_param_fixed_size(msg, strlen(msg)),
124 GNUNET_SQ_query_param_uint16 (&u16), 124 GNUNET_SQ_query_param_uint16(&u16),
125 GNUNET_SQ_query_param_uint32 (&u32), 125 GNUNET_SQ_query_param_uint32(&u32),
126 GNUNET_SQ_query_param_uint64 (&u64), 126 GNUNET_SQ_query_param_uint64(&u64),
127 GNUNET_SQ_query_param_end 127 GNUNET_SQ_query_param_end
128 }; 128 };
129 129
130 GNUNET_assert (GNUNET_OK == 130 GNUNET_assert(GNUNET_OK ==
131 GNUNET_SQ_bind (stmt, 131 GNUNET_SQ_bind(stmt,
132 params_insert)); 132 params_insert));
133 if (SQLITE_DONE != 133 if (SQLITE_DONE !=
134 sqlite3_step (stmt)) 134 sqlite3_step(stmt))
135 { 135 {
136 GNUNET_CRYPTO_rsa_signature_free (sig); 136 GNUNET_CRYPTO_rsa_signature_free(sig);
137 GNUNET_CRYPTO_rsa_private_key_free (priv); 137 GNUNET_CRYPTO_rsa_private_key_free(priv);
138 GNUNET_CRYPTO_rsa_public_key_free (pub); 138 GNUNET_CRYPTO_rsa_public_key_free(pub);
139 return 1; 139 return 1;
140 } 140 }
141 } 141 }
142 sqlite3_finalize (stmt); 142 sqlite3_finalize(stmt);
143 143
144 sq_prepare (dbh, 144 sq_prepare(dbh,
145 "SELECT" 145 "SELECT"
146 " pub" 146 " pub"
147 ",sig" 147 ",sig"
148 ",abs_time" 148 ",abs_time"
149 ",forever" 149 ",forever"
150 ",hash" 150 ",hash"
151 ",vsize" 151 ",vsize"
152 ",u16" 152 ",u16"
153 ",u32" 153 ",u32"
154 ",u64" 154 ",u64"
155 " FROM test_sq" 155 " FROM test_sq"
156 " ORDER BY abs_time DESC " 156 " ORDER BY abs_time DESC "
157 " LIMIT 1;", 157 " LIMIT 1;",
158 &stmt); 158 &stmt);
159 { 159 {
160 struct GNUNET_SQ_QueryParam params_select[] = { 160 struct GNUNET_SQ_QueryParam params_select[] = {
161 GNUNET_SQ_query_param_end 161 GNUNET_SQ_query_param_end
162 }; 162 };
163 struct GNUNET_SQ_ResultSpec results_select[] = { 163 struct GNUNET_SQ_ResultSpec results_select[] = {
164 GNUNET_SQ_result_spec_rsa_public_key (&pub2), 164 GNUNET_SQ_result_spec_rsa_public_key(&pub2),
165 GNUNET_SQ_result_spec_rsa_signature (&sig2), 165 GNUNET_SQ_result_spec_rsa_signature(&sig2),
166 GNUNET_SQ_result_spec_absolute_time (&abs_time2), 166 GNUNET_SQ_result_spec_absolute_time(&abs_time2),
167 GNUNET_SQ_result_spec_absolute_time (&forever2), 167 GNUNET_SQ_result_spec_absolute_time(&forever2),
168 GNUNET_SQ_result_spec_auto_from_type (&hc2), 168 GNUNET_SQ_result_spec_auto_from_type(&hc2),
169 GNUNET_SQ_result_spec_variable_size (&msg2, &msg2_len), 169 GNUNET_SQ_result_spec_variable_size(&msg2, &msg2_len),
170 GNUNET_SQ_result_spec_uint16 (&u162), 170 GNUNET_SQ_result_spec_uint16(&u162),
171 GNUNET_SQ_result_spec_uint32 (&u322), 171 GNUNET_SQ_result_spec_uint32(&u322),
172 GNUNET_SQ_result_spec_uint64 (&u642), 172 GNUNET_SQ_result_spec_uint64(&u642),
173 GNUNET_SQ_result_spec_end 173 GNUNET_SQ_result_spec_end
174 }; 174 };
175 175
176 GNUNET_assert (GNUNET_OK == 176 GNUNET_assert(GNUNET_OK ==
177 GNUNET_SQ_bind (stmt, 177 GNUNET_SQ_bind(stmt,
178 params_select)); 178 params_select));
179 if (SQLITE_ROW != 179 if (SQLITE_ROW !=
180 sqlite3_step (stmt)) 180 sqlite3_step(stmt))
181 { 181 {
182 GNUNET_break (0); 182 GNUNET_break(0);
183 sqlite3_finalize (stmt); 183 sqlite3_finalize(stmt);
184 GNUNET_CRYPTO_rsa_signature_free (sig); 184 GNUNET_CRYPTO_rsa_signature_free(sig);
185 GNUNET_CRYPTO_rsa_private_key_free (priv); 185 GNUNET_CRYPTO_rsa_private_key_free(priv);
186 GNUNET_CRYPTO_rsa_public_key_free (pub); 186 GNUNET_CRYPTO_rsa_public_key_free(pub);
187 return 1; 187 return 1;
188 } 188 }
189 GNUNET_assert (GNUNET_OK == 189 GNUNET_assert(GNUNET_OK ==
190 GNUNET_SQ_extract_result (stmt, 190 GNUNET_SQ_extract_result(stmt,
191 results_select)); 191 results_select));
192 GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us); 192 GNUNET_break(abs_time.abs_value_us == abs_time2.abs_value_us);
193 GNUNET_break (forever.abs_value_us == forever2.abs_value_us); 193 GNUNET_break(forever.abs_value_us == forever2.abs_value_us);
194 GNUNET_break (0 == 194 GNUNET_break(0 ==
195 GNUNET_memcmp (&hc, 195 GNUNET_memcmp(&hc,
196 &hc2)); 196 &hc2));
197 GNUNET_break (0 == 197 GNUNET_break(0 ==
198 GNUNET_CRYPTO_rsa_signature_cmp (sig, 198 GNUNET_CRYPTO_rsa_signature_cmp(sig,
199 sig2)); 199 sig2));
200 GNUNET_break (0 == 200 GNUNET_break(0 ==
201 GNUNET_CRYPTO_rsa_public_key_cmp (pub, 201 GNUNET_CRYPTO_rsa_public_key_cmp(pub,
202 pub2)); 202 pub2));
203 GNUNET_break (strlen (msg) == msg2_len); 203 GNUNET_break(strlen(msg) == msg2_len);
204 GNUNET_break (0 == 204 GNUNET_break(0 ==
205 strncmp (msg, 205 strncmp(msg,
206 msg2, 206 msg2,
207 msg2_len)); 207 msg2_len));
208 GNUNET_break (16 == u162); 208 GNUNET_break(16 == u162);
209 GNUNET_break (32 == u322); 209 GNUNET_break(32 == u322);
210 GNUNET_break (64 == u642); 210 GNUNET_break(64 == u642);
211 GNUNET_SQ_cleanup_result (results_select); 211 GNUNET_SQ_cleanup_result(results_select);
212 } 212 }
213 sqlite3_finalize (stmt); 213 sqlite3_finalize(stmt);
214 214
215 GNUNET_CRYPTO_rsa_signature_free (sig); 215 GNUNET_CRYPTO_rsa_signature_free(sig);
216 GNUNET_CRYPTO_rsa_private_key_free (priv); 216 GNUNET_CRYPTO_rsa_private_key_free(priv);
217 GNUNET_CRYPTO_rsa_public_key_free (pub); 217 GNUNET_CRYPTO_rsa_public_key_free(pub);
218 return 0; 218 return 0;
219} 219}
220 220
@@ -226,61 +226,61 @@ main(int argc,
226 sqlite3 *dbh; 226 sqlite3 *dbh;
227 int ret; 227 int ret;
228 228
229 GNUNET_log_setup ("test-sq", 229 GNUNET_log_setup("test-sq",
230 "WARNING", 230 "WARNING",
231 NULL); 231 NULL);
232 if (SQLITE_OK != 232 if (SQLITE_OK !=
233 sqlite3_open ("test.db", 233 sqlite3_open("test.db",
234 &dbh)) 234 &dbh))
235 { 235 {
236 fprintf (stderr, 236 fprintf(stderr,
237 "Cannot run test, sqlite3 initialization failed\n"); 237 "Cannot run test, sqlite3 initialization failed\n");
238 GNUNET_break (0); 238 GNUNET_break(0);
239 return 77; /* Signal test was skipped... */ 239 return 77; /* Signal test was skipped... */
240 } 240 }
241 241
242 if (SQLITE_OK != 242 if (SQLITE_OK !=
243 sqlite3_exec (dbh, 243 sqlite3_exec(dbh,
244 "CREATE TEMPORARY TABLE IF NOT EXISTS test_sq (" 244 "CREATE TEMPORARY TABLE IF NOT EXISTS test_sq ("
245 " pub BYTEA NOT NULL" 245 " pub BYTEA NOT NULL"
246 ",sig BYTEA NOT NULL" 246 ",sig BYTEA NOT NULL"
247 ",abs_time INT8 NOT NULL" 247 ",abs_time INT8 NOT NULL"
248 ",forever INT8 NOT NULL" 248 ",forever INT8 NOT NULL"
249 ",hash BYTEA NOT NULL" 249 ",hash BYTEA NOT NULL"
250 ",vsize VARCHAR NOT NULL" 250 ",vsize VARCHAR NOT NULL"
251 ",u16 INT2 NOT NULL" 251 ",u16 INT2 NOT NULL"
252 ",u32 INT4 NOT NULL" 252 ",u32 INT4 NOT NULL"
253 ",u64 INT8 NOT NULL" 253 ",u64 INT8 NOT NULL"
254 ")", 254 ")",
255 NULL, NULL, NULL)) 255 NULL, NULL, NULL))
256 { 256 {
257 fprintf (stderr, 257 fprintf(stderr,
258 "Failed to create table\n"); 258 "Failed to create table\n");
259 GNUNET_break (SQLITE_OK == 259 GNUNET_break(SQLITE_OK ==
260 sqlite3_close (dbh)); 260 sqlite3_close(dbh));
261 if (0 != unlink ("test.db")) 261 if (0 != unlink("test.db"))
262 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 262 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR,
263 "unlink", 263 "unlink",
264 "test.db"); 264 "test.db");
265 return 1; 265 return 1;
266 } 266 }
267 267
268 ret = run_queries (dbh); 268 ret = run_queries(dbh);
269 if (SQLITE_OK != 269 if (SQLITE_OK !=
270 sqlite3_exec (dbh, 270 sqlite3_exec(dbh,
271 "DROP TABLE test_sq", 271 "DROP TABLE test_sq",
272 NULL, NULL, NULL)) 272 NULL, NULL, NULL))
273 { 273 {
274 fprintf (stderr, 274 fprintf(stderr,
275 "Failed to drop table\n"); 275 "Failed to drop table\n");
276 ret = 1; 276 ret = 1;
277 } 277 }
278 GNUNET_break (SQLITE_OK == 278 GNUNET_break(SQLITE_OK ==
279 sqlite3_close (dbh)); 279 sqlite3_close(dbh));
280 if (0 != unlink ("test.db")) 280 if (0 != unlink("test.db"))
281 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 281 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR,
282 "unlink", 282 "unlink",
283 "test.db"); 283 "test.db");
284 return ret; 284 return ret;
285} 285}
286 286